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