cards/src/main.rs
2024-04-12 02:04:58 -04:00

50 lines
1.2 KiB
Rust

use serde_json::Result;
use std::fs;
#[allow(non_snake_case)]
pub mod CAHd_game;
use crate::CAHd_game::*;
/// Parse json for card data
fn load_json(path: &str) -> Result<Vec<CAHCardSet>> {
let data: String = fs::read_to_string(path).expect("Error reading file");
let jayson: Vec<CAHCardSet> = serde_json::from_str(&data)?;
Ok(jayson)
}
fn main() -> Result<()> {
// choose decks
let cards_input_path: &str = "data/cah-cards-full.json";
let chosen_packs: Vec<CAHCardSet> = load_json(cards_input_path)?;
let test_player0 = CAHPlayer {
player_name: "Adam".to_string(),
role: PlayerRole::Host,
white: vec![],
black: vec![],
};
let test_player1 = CAHPlayer {
player_name: "Ferris".to_string(),
role: PlayerRole::Player,
white: vec![],
black: vec![],
};
// make some games
let mut games: Vec<CAHGame> = 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);
Ok(())
}