new game request struct
This commit is contained in:
parent
0538932ec8
commit
8843e4af3b
2 changed files with 33 additions and 20 deletions
|
@ -63,7 +63,7 @@ pub struct CAHPlayer {
|
|||
}
|
||||
|
||||
/// The game master
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Default)]
|
||||
pub struct CAHGame {
|
||||
/// The name of the game
|
||||
game_name: String,
|
||||
|
@ -85,6 +85,16 @@ pub struct CAHGame {
|
|||
pub current_black: Option<CAHCardBlack>,
|
||||
}
|
||||
|
||||
/// New game request structure
|
||||
pub struct NewGameRequest {
|
||||
/// Game name
|
||||
pub name: String,
|
||||
/// Game host
|
||||
pub host: CAHPlayer,
|
||||
/// Chosen packs
|
||||
pub packs: Vec<CAHCardSet>,
|
||||
}
|
||||
|
||||
impl CAHGame {
|
||||
/// Build game decks from input data for game start.
|
||||
/// This should only run once and at startup.
|
||||
|
@ -100,15 +110,15 @@ impl CAHGame {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
pub fn new(name: String, host: CAHPlayer, decks: Vec<CAHCardSet>) -> Result<CAHGame> {
|
||||
pub fn new(request: NewGameRequest) -> Result<CAHGame> {
|
||||
let mut game = CAHGame {
|
||||
..Default::default()
|
||||
};
|
||||
println!("Creating game {}", &name);
|
||||
game.game_name = name;
|
||||
println!("Creating game {}", &request.name);
|
||||
game.game_name = request.name;
|
||||
|
||||
game.build_decks(decks)?;
|
||||
game.create_player(host)?;
|
||||
game.build_decks(request.packs)?;
|
||||
game.create_player(request.host)?;
|
||||
game.deal_black()?;
|
||||
|
||||
Ok(game)
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -41,11 +41,14 @@ fn main() -> Result<()> {
|
|||
let mut games: Vec<CAHGame> = vec![];
|
||||
|
||||
// create game with/for player 0
|
||||
// TODO: make this a new game request struct
|
||||
let test_game0 = NewGameRequest {
|
||||
name: "Test0".to_string(),
|
||||
host: test_player0,
|
||||
packs: chosen_packs,
|
||||
};
|
||||
|
||||
games.push(CAHGame::new(
|
||||
"Test0".to_string(),
|
||||
test_player0,
|
||||
chosen_packs,
|
||||
test_game0
|
||||
)?);
|
||||
|
||||
// a new game request struct but this player is a player
|
||||
|
|
Loading…
Add table
Reference in a new issue