diff --git a/Cargo.lock b/Cargo.lock index acd9c95..b0c65fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -57,9 +57,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] diff --git a/src/CAHd_game.rs b/src/CAHd_game.rs index dfc3b52..cbe12f5 100644 --- a/src/CAHd_game.rs +++ b/src/CAHd_game.rs @@ -3,20 +3,44 @@ use rand::thread_rng; use serde::{Deserialize, Serialize}; use serde_json::Result; +/// Player roles +#[derive(Debug)] +pub enum PlayerRole { + /// Player is host + Host, + /// Player is a player in a game where another player is host + Player, + /// Player is just spectating + Spectator, +} + +/// A struct that represents a player +#[derive(Debug)] +pub struct CAHPlayer { + /// Player's username + pub player_name: String, + /// This player's role + pub role: PlayerRole, + /// The player's hand + pub white: Vec, + /// The player's wins + pub black: Vec, +} + /// A CAH white card -#[derive(Serialize, Deserialize)] -struct CAHCardWhite { +#[derive(Debug, Serialize, Deserialize)] +pub struct CAHCardWhite { /// Card text - text: String, + pub text: String, /// ID of the pack it came from pack: u8, } /// A CAH black card -#[derive(Serialize, Deserialize)] -struct CAHCardBlack { +#[derive(Debug, Serialize, Deserialize)] +pub struct CAHCardBlack { /// Card text - text: String, + pub text: String, /// Amount of cards to submit for judging pick: u8, /// ID of the pack it came from @@ -36,22 +60,11 @@ pub struct CAHCardSet { white: Option>, /// Black card data black: Option>, - } - -/// A struct that represents a player -#[derive(Default)] -pub struct CAHPlayer { - /// Is this player host? - pub host: bool, - /// The player's hand - pub white: Vec, - /// The player's wins - pub black: Vec, } /// The game master -#[derive(Default)] -struct CAHGame { +#[derive(Debug, Default)] +pub struct CAHGame { /// White draw pile white: Vec, /// Black draw pile @@ -63,11 +76,11 @@ struct CAHGame { /// Indicates game active/game over game_active: bool, /// List of current players - players: Vec, + pub players: Vec, // /// Reference to current card czar // czar: &CAHPlayer, /// Black card for the current round - current_black: Option, + pub current_black: Option, } impl CAHGame { @@ -83,10 +96,29 @@ impl CAHGame { } } } + pub fn new(host: CAHPlayer, decks: Vec) -> Result { + let mut game = CAHGame { + ..Default::default() + }; + game.build_decks(decks); + game.create_player(host); + let _ = game.deal_black()?; + + let mut hand_buf = vec![]; + for _ in 0..10 { + hand_buf.push(game.draw_one_white()?); + } + game.players[0].white.extend(hand_buf); + println!("Player hand dealt"); + + + println!("Game Created!"); + Ok(game) + } /// Log counts of current drawable cards /// For testing - fn deck_counts(&self) { + pub fn deck_counts(&self) { println!( "Deck Counts:\n {} White cards\n {} Black cards", self.white.len(), diff --git a/src/main.rs b/src/main.rs index 987f7f3..c830b1a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use serde_json::Result; -use std::fs; +use std::{alloc::Layout, fs}; #[allow(non_snake_case)] pub mod CAHd_game; @@ -18,50 +18,18 @@ fn main() -> Result<()> { let cards_input_path: &str = "data/cah-cards-full.json"; let cards_json: Vec = load_json(cards_input_path)?; - // player 0 (host) - let adam: CAHPlayer = CAHPlayer { - host: true, - ..Default::default() - }; - // create game with/for player 0 + let game = CAHGame::new( + CAHPlayer { + player_name: "Adam".to_string(), + role: PlayerRole::Host, + white: vec![], + black: vec![], + }, + cards_json, + ); + println!("{:#?}", game?.players[0]); - println!("{:?}", adam.host); - - // setup - // let mut cah_game = CAHGame { - // ..Default::default() - // }; - // cah_game.build_decks(cards_json); - // cah_game.deck_counts(); - // cah_game.create_player(CAHPlayer { - // ..Default::default() - // }); - // - // sloppy ui stuff - // let div = "--------------------------"; - - // deal black - // if let Some(black_card) = cah_game.deal_black()? { - // println!( - // "{}\nPick {}\n {}\n{}", - // div, - // black_card.pick.to_string(), - // black_card.text, - // div, - // ); - // } - - // deal white - // for i in 1..11 { - // let card = cah_game.draw_one_white()?; - // println!("{} {}", i, card.text); - // } - // println!("{}", div); - // - // cah_game.deck_counts(); - - // fin Ok(()) }