diff options
| author | salmonik <salmonik@tuta.io> | 2026-10-28 22:28:05 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-10-28 22:28:05 +0100 |
| commit | ea5e7d336719571e51ef14478ab603e71126e3d8 (patch) | |
| tree | 4fb59337501f798e6591701e52b9e785307efd63 /src/bin/server/games/traits.rs | |
| parent | Fix TUI: render_lines 6 for correct MoveUp, drain buffered events before clea... (diff) | |
| download | zagan-bet-ea5e7d336719571e51ef14478ab603e71126e3d8.tar.gz zagan-bet-ea5e7d336719571e51ef14478ab603e71126e3d8.zip | |
v0.2.2: split client/server logic into the library
Diffstat (limited to 'src/bin/server/games/traits.rs')
| -rw-r--r-- | src/bin/server/games/traits.rs | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/src/bin/server/games/traits.rs b/src/bin/server/games/traits.rs deleted file mode 100644 index d56b334..0000000 --- a/src/bin/server/games/traits.rs +++ /dev/null | |||
| @@ -1,67 +0,0 @@ | |||
| 1 | use serde::{Deserialize, Serialize}; | ||
| 2 | use std::collections::HashMap; | ||
| 3 | |||
| 4 | #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| 5 | pub enum GameError { | ||
| 6 | InvalidAction(String), | ||
| 7 | InsufficientBalance, | ||
| 8 | InvalidBet, | ||
| 9 | GameOver, | ||
| 10 | SessionNotFound, | ||
| 11 | InternalError(String), | ||
| 12 | } | ||
| 13 | |||
| 14 | #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | ||
| 15 | pub enum GamePhase { | ||
| 16 | WaitingToStart, | ||
| 17 | Playing, | ||
| 18 | Finished, | ||
| 19 | } | ||
| 20 | |||
| 21 | #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| 22 | pub struct GameState { | ||
| 23 | pub session_id: String, | ||
| 24 | pub game_type: String, | ||
| 25 | pub bet_amount: u64, | ||
| 26 | pub phase: GamePhase, | ||
| 27 | pub data: HashMap<String, String>, | ||
| 28 | } | ||
| 29 | |||
| 30 | #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| 31 | pub struct GameResult { | ||
| 32 | pub session_id: String, | ||
| 33 | pub game_type: String, | ||
| 34 | pub bet_amount: u64, | ||
| 35 | pub winnings: u64, | ||
| 36 | pub final_balance: u64, | ||
| 37 | pub result_data: HashMap<String, String>, | ||
| 38 | } | ||
| 39 | |||
| 40 | pub trait Game: Send + Sync { | ||
| 41 | fn game_type(&self) -> &'static str; | ||
| 42 | |||
| 43 | fn get_name(&self) -> &'static str; | ||
| 44 | |||
| 45 | fn get_description(&self) -> &'static str; | ||
| 46 | |||
| 47 | fn validate_bet(&self, bet_amount: u64, user_balance: u64) -> Result<(), GameError> { | ||
| 48 | if bet_amount == 0 { | ||
| 49 | return Err(GameError::InvalidBet); | ||
| 50 | } | ||
| 51 | if bet_amount > user_balance { | ||
| 52 | return Err(GameError::InsufficientBalance); | ||
| 53 | } | ||
| 54 | Ok(()) | ||
| 55 | } | ||
| 56 | |||
| 57 | fn prepare_state(&self, username: &str, bet_amount: u64) -> GameState; | ||
| 58 | |||
| 59 | fn process_action( | ||
| 60 | &self, | ||
| 61 | state: &GameState, | ||
| 62 | action: &str, | ||
| 63 | params: &[&str], | ||
| 64 | ) -> Result<GameState, GameError>; | ||
| 65 | |||
| 66 | fn calculate_result(&self, state: &GameState) -> Result<GameResult, GameError>; | ||
| 67 | } | ||
