From e393e1ad99bdb34dc94d7806bf9f2969df3fa14c Mon Sep 17 00:00:00 2001 From: Adam <24621027+adoyle0@users.noreply.github.com> Date: Fri, 12 Apr 2024 02:04:58 -0400 Subject: [PATCH] fake it til you make it --- src/CAHd_game.rs | 32 +++++++++++++++++++------------- src/main.rs | 33 ++++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/CAHd_game.rs b/src/CAHd_game.rs index cbe12f5..866c98c 100644 --- a/src/CAHd_game.rs +++ b/src/CAHd_game.rs @@ -65,6 +65,8 @@ pub struct CAHCardSet { /// The game master #[derive(Debug, Default)] pub struct CAHGame { + /// The name of the game + game_name: String, /// White draw pile white: Vec, /// Black draw pile @@ -96,23 +98,17 @@ impl CAHGame { } } } - pub fn new(host: CAHPlayer, decks: Vec) -> Result { + pub fn new(name: String, host: CAHPlayer, decks: Vec) -> Result { let mut game = CAHGame { ..Default::default() }; + println!("Creating game {}", &name); + game.game_name = name; + game.build_decks(decks); - game.create_player(host); + let _ = 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) } @@ -166,8 +162,18 @@ impl CAHGame { } /// Create a new player and add them to the game. - fn create_player(&mut self, player: CAHPlayer) { + pub fn create_player(&mut self, mut player: CAHPlayer) -> Result<()> { + println!("Creating player {} as {:?}", &player.player_name, &player.role); + + let mut hand_buf = vec![]; + for _ in 0..10 { + hand_buf.push(self.draw_one_white()?); + } + println!("Dealing hand for {}", &player.player_name); + let _ = &player.white.extend(hand_buf); + self.players.push(player); - println!("Player Created!"); + + Ok(()) } } diff --git a/src/main.rs b/src/main.rs index c830b1a..13686d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use serde_json::Result; -use std::{alloc::Layout, fs}; +use std::fs; #[allow(non_snake_case)] pub mod CAHd_game; @@ -16,20 +16,35 @@ fn load_json(path: &str) -> Result> { fn main() -> Result<()> { // choose decks let cards_input_path: &str = "data/cah-cards-full.json"; - let cards_json: Vec = load_json(cards_input_path)?; + let chosen_packs: Vec = load_json(cards_input_path)?; - // create game with/for player 0 - let game = CAHGame::new( - CAHPlayer { + let test_player0 = CAHPlayer { player_name: "Adam".to_string(), role: PlayerRole::Host, white: vec![], black: vec![], - }, - cards_json, - ); + }; + + let test_player1 = CAHPlayer { + player_name: "Ferris".to_string(), + role: PlayerRole::Player, + white: vec![], + black: vec![], + }; + + // make some games + let mut games: Vec = vec![]; + + // create game with/for player 0 + games.push(CAHGame::new( + "Test0".to_string(), + test_player0, + chosen_packs, + )?); + + // ready player 1 + let _ = games[0].create_player(test_player1); - println!("{:#?}", game?.players[0]); Ok(()) }