cleanER
This commit is contained in:
parent
d15c9d08f8
commit
083b4f236c
3 changed files with 67 additions and 67 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -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",
|
||||
]
|
||||
|
|
|
@ -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<CAHCardWhite>,
|
||||
/// The player's wins
|
||||
pub black: Vec<CAHCardBlack>,
|
||||
}
|
||||
|
||||
/// 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<Vec<CAHCardWhite>>,
|
||||
/// Black card data
|
||||
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
|
||||
#[derive(Default)]
|
||||
struct CAHGame {
|
||||
#[derive(Debug, Default)]
|
||||
pub struct CAHGame {
|
||||
/// White draw pile
|
||||
white: Vec<CAHCardWhite>,
|
||||
/// Black draw pile
|
||||
|
@ -63,11 +76,11 @@ struct CAHGame {
|
|||
/// Indicates game active/game over
|
||||
game_active: bool,
|
||||
/// List of current players
|
||||
players: Vec<CAHPlayer>,
|
||||
pub players: Vec<CAHPlayer>,
|
||||
// /// Reference to current card czar
|
||||
// czar: &CAHPlayer,
|
||||
/// Black card for the current round
|
||||
current_black: Option<CAHCardBlack>,
|
||||
pub current_black: Option<CAHCardBlack>,
|
||||
}
|
||||
|
||||
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
|
||||
/// For testing
|
||||
fn deck_counts(&self) {
|
||||
pub fn deck_counts(&self) {
|
||||
println!(
|
||||
"Deck Counts:\n {} White cards\n {} Black cards",
|
||||
self.white.len(),
|
||||
|
|
54
src/main.rs
54
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<CAHCardSet> = 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(())
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue