new game request struct

This commit is contained in:
Adam 2024-04-12 18:35:13 -04:00
parent 0538932ec8
commit 8843e4af3b
2 changed files with 33 additions and 20 deletions

View file

@ -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)

View file

@ -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<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