From 8843e4af3b10f98b1f07bfd6fea538b71a3ab27b Mon Sep 17 00:00:00 2001 From: Adam <24621027+adoyle0@users.noreply.github.com> Date: Fri, 12 Apr 2024 18:35:13 -0400 Subject: [PATCH] new game request struct --- src/CAHd_game.rs | 22 ++++++++++++++++------ src/main.rs | 31 +++++++++++++++++-------------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/CAHd_game.rs b/src/CAHd_game.rs index 427abc6..86b496c 100644 --- a/src/CAHd_game.rs +++ b/src/CAHd_game.rs @@ -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, } +/// New game request structure +pub struct NewGameRequest { + /// Game name + pub name: String, + /// Game host + pub host: CAHPlayer, + /// Chosen packs + pub packs: Vec, +} + 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) -> Result { + pub fn new(request: NewGameRequest) -> Result { 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) diff --git a/src/main.rs b/src/main.rs index 5c258cd..371cd82 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,29 +23,32 @@ fn main() -> Result<()> { println!("{}", &chosen_packs.len()); let test_player0 = CAHPlayer { - player_name: "Adam".to_string(), - role: PlayerRole::Host, - white: vec![], - black: vec![], - }; + player_name: "Adam".to_string(), + role: PlayerRole::Host, + white: vec![], + black: vec![], + }; let test_player1 = CAHPlayer { - player_name: "Ferris".to_string(), - role: PlayerRole::Player, - white: vec![], - black: vec![], - }; + player_name: "Ferris".to_string(), + role: PlayerRole::Player, + white: vec![], + black: vec![], + }; // make some games // use hashmap? let mut games: Vec = 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