This commit is contained in:
Adam 2024-04-10 04:18:31 -04:00
parent d15c9d08f8
commit 083b4f236c
3 changed files with 67 additions and 67 deletions

4
Cargo.lock generated
View file

@ -57,9 +57,9 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.35" version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]

View file

@ -3,20 +3,44 @@ use rand::thread_rng;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Result; 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<CAHCardWhite>,
/// The player's wins
pub black: Vec<CAHCardBlack>,
}
/// A CAH white card /// A CAH white card
#[derive(Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
struct CAHCardWhite { pub struct CAHCardWhite {
/// Card text /// Card text
text: String, pub text: String,
/// ID of the pack it came from /// ID of the pack it came from
pack: u8, pack: u8,
} }
/// A CAH black card /// A CAH black card
#[derive(Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
struct CAHCardBlack { pub struct CAHCardBlack {
/// Card text /// Card text
text: String, pub text: String,
/// Amount of cards to submit for judging /// Amount of cards to submit for judging
pick: u8, pick: u8,
/// ID of the pack it came from /// ID of the pack it came from
@ -36,22 +60,11 @@ pub struct CAHCardSet {
white: Option<Vec<CAHCardWhite>>, white: Option<Vec<CAHCardWhite>>,
/// Black card data /// Black card data
black: Option<Vec<CAHCardBlack>>, black: Option<Vec<CAHCardBlack>>,
}
/// 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<CAHCardWhite>,
/// The player's wins
pub black: Vec<CAHCardBlack>,
} }
/// The game master /// The game master
#[derive(Default)] #[derive(Debug, Default)]
struct CAHGame { pub struct CAHGame {
/// White draw pile /// White draw pile
white: Vec<CAHCardWhite>, white: Vec<CAHCardWhite>,
/// Black draw pile /// Black draw pile
@ -63,11 +76,11 @@ struct CAHGame {
/// Indicates game active/game over /// Indicates game active/game over
game_active: bool, game_active: bool,
/// List of current players /// List of current players
players: Vec<CAHPlayer>, pub players: Vec<CAHPlayer>,
// /// Reference to current card czar // /// Reference to current card czar
// czar: &CAHPlayer, // czar: &CAHPlayer,
/// Black card for the current round /// Black card for the current round
current_black: Option<CAHCardBlack>, pub current_black: Option<CAHCardBlack>,
} }
impl CAHGame { impl CAHGame {
@ -83,10 +96,29 @@ impl CAHGame {
} }
} }
} }
pub fn new(host: CAHPlayer, decks: Vec<CAHCardSet>) -> Result<CAHGame> {
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 /// Log counts of current drawable cards
/// For testing /// For testing
fn deck_counts(&self) { pub fn deck_counts(&self) {
println!( println!(
"Deck Counts:\n {} White cards\n {} Black cards", "Deck Counts:\n {} White cards\n {} Black cards",
self.white.len(), self.white.len(),

View file

@ -1,5 +1,5 @@
use serde_json::Result; use serde_json::Result;
use std::fs; use std::{alloc::Layout, fs};
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub mod CAHd_game; pub mod CAHd_game;
@ -18,50 +18,18 @@ fn main() -> Result<()> {
let cards_input_path: &str = "data/cah-cards-full.json"; let cards_input_path: &str = "data/cah-cards-full.json";
let cards_json: Vec<CAHCardSet> = load_json(cards_input_path)?; let cards_json: Vec<CAHCardSet> = load_json(cards_input_path)?;
// player 0 (host)
let adam: CAHPlayer = CAHPlayer {
host: true,
..Default::default()
};
// create game with/for player 0 // 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(()) Ok(())
} }