From b5a52fc0312afdf5d5fbe53275dc88d6d881c2ff Mon Sep 17 00:00:00 2001 From: salmonik Date: Thu, 29 Oct 2026 18:22:40 +0100 Subject: v2.2.0: add blackjack with reserved bets and hit/stand/double --- src/client/games/manager.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/client/games/manager.rs') diff --git a/src/client/games/manager.rs b/src/client/games/manager.rs index 02e9451..4e0218b 100644 --- a/src/client/games/manager.rs +++ b/src/client/games/manager.rs @@ -1,7 +1,9 @@ +use super::blackjack::BlackjackGame; use super::response::{RouletteResult, SpinResult}; use super::roulette::RouletteGame; use super::slots::SlotsGame; use super::traits::{Game, GameError, GamePhase, GameState}; +use crate::blackjack::BlackjackState; use crate::roulette::Bets; use std::collections::HashMap; @@ -15,6 +17,7 @@ impl GameManager { let mut games: HashMap> = HashMap::new(); games.insert("slots".to_string(), Box::new(SlotsGame::new())); games.insert("roulette".to_string(), Box::new(RouletteGame::new())); + games.insert("blackjack".to_string(), Box::new(BlackjackGame::new())); Self { current_session: None, @@ -51,6 +54,9 @@ impl GameManager { data.insert("status".to_string(), "place".to_string()); data.insert("number_input".to_string(), String::new()); 0 + } else if game_type == "blackjack" { + data.insert("status".to_string(), "ready".to_string()); + 10 } else { 10 }; @@ -260,6 +266,49 @@ impl GameManager { .insert("number_input".to_string(), String::new()); } + pub fn apply_blackjack_state(&mut self, state: BlackjackState) { + let Some(session) = self.current_session.as_mut() else { + return; + }; + session.phase = if state.phase == "player" { + GamePhase::Playing + } else { + GamePhase::Finished + }; + session.bet_amount = state.base_bet; + session.data.remove("error"); + session + .data + .insert("balance".to_string(), state.balance.to_string()); + session.data.insert( + "status".to_string(), + if state.phase == "player" { + "player".to_string() + } else { + "done".to_string() + }, + ); + session.data.insert( + "blackjack".to_string(), + serde_json::to_string(&state).unwrap_or_default(), + ); + } + + pub fn blackjack_state(&self) -> Option { + self.current_session + .as_ref() + .and_then(|session| session.data.get("blackjack")) + .and_then(|raw| serde_json::from_str(raw).ok()) + } + + pub fn set_blackjack_status(&mut self, status: &str) { + if let Some(session) = self.current_session.as_mut() { + session + .data + .insert("status".to_string(), status.to_string()); + } + } + pub fn get_current_game(&self) -> Option<&dyn Game> { self.current_session .as_ref() -- cgit v1.2.3