mahjong_core/game/
creation.rs1use super::{
2 definition::{Game, GamePhase, GameStyle},
3 Players,
4};
5use crate::{deck::DEFAULT_DECK, round::Round, Score};
6use uuid::Uuid;
7
8#[derive(Default, Clone)]
9pub struct GameNewOpts {
10 pub players: Option<Players>,
11}
12
13impl Game {
14 pub fn new(opts: Option<GameNewOpts>) -> Self {
15 let parsed_opts = opts.unwrap_or_default();
16 let version = Uuid::new_v4().to_string();
17 let players = parsed_opts.players.clone().unwrap_or_default();
18 let game_style = GameStyle::HongKong;
19
20 let table = DEFAULT_DECK.create_table(&players);
21 let score = Score::new(&players.0);
22
23 Self {
24 id: "game_id".to_string(),
25 name: "game_name".to_string(),
26 phase: GamePhase::Beginning,
27 players,
28 round: Round::new(&game_style),
29 score,
30 style: GameStyle::HongKong,
31 table,
32 version,
33 }
34 }
35}