diff options
Diffstat (limited to 'src/client/games/crash.rs')
| -rw-r--r-- | src/client/games/crash.rs | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/client/games/crash.rs b/src/client/games/crash.rs new file mode 100644 index 0000000..19733f2 --- /dev/null +++ b/src/client/games/crash.rs | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | use super::traits::{Game, GameState}; | ||
| 2 | |||
| 3 | pub const CRASH_BOARD_LINES: usize = 6; | ||
| 4 | |||
| 5 | pub struct CrashGame; | ||
| 6 | |||
| 7 | impl CrashGame { | ||
| 8 | pub fn new() -> Self { | ||
| 9 | Self | ||
| 10 | } | ||
| 11 | |||
| 12 | fn value<'a>(state: &'a GameState, key: &str) -> Option<&'a str> { | ||
| 13 | state.data.get(key).map(String::as_str) | ||
| 14 | } | ||
| 15 | |||
| 16 | fn status_text(state: &GameState) -> String { | ||
| 17 | let status = Self::value(state, "status").unwrap_or("ready"); | ||
| 18 | match status { | ||
| 19 | "starting" => "Starting...".to_string(), | ||
| 20 | "running" => "Rising... cash out before it crashes.".to_string(), | ||
| 21 | "cashed" => format!( | ||
| 22 | "Cashed out at {}x Won {} PLN", | ||
| 23 | Self::value(state, "multiplier").unwrap_or("1.00"), | ||
| 24 | Self::value(state, "payout").unwrap_or("0") | ||
| 25 | ), | ||
| 26 | "crashed" => format!( | ||
| 27 | "CRASHED at {}x Bet lost", | ||
| 28 | Self::value(state, "crash_point").unwrap_or("?") | ||
| 29 | ), | ||
| 30 | "forfeit" => "Forfeited. Bet lost.".to_string(), | ||
| 31 | _ => "Press [SPACE] to start.".to_string(), | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | fn controls(state: &GameState) -> &'static str { | ||
| 36 | if Self::value(state, "status") == Some("running") { | ||
| 37 | "[C] Cash out [Q] Forfeit" | ||
| 38 | } else { | ||
| 39 | "[SPACE] Play [+/=/-] Bet [Q] Quit" | ||
| 40 | } | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | impl Game for CrashGame { | ||
| 45 | fn get_name(&self) -> &'static str { | ||
| 46 | "Crash" | ||
| 47 | } | ||
| 48 | |||
| 49 | fn render(&self, state: &GameState) -> String { | ||
| 50 | let balance = Self::value(state, "balance").unwrap_or("?"); | ||
| 51 | let multiplier = Self::value(state, "multiplier").unwrap_or("1.00"); | ||
| 52 | let potential = Self::value(state, "potential") | ||
| 53 | .map(str::to_string) | ||
| 54 | .unwrap_or_else(|| state.bet_amount.to_string()); | ||
| 55 | |||
| 56 | if let Some(error) = Self::value(state, "error") { | ||
| 57 | return format!( | ||
| 58 | "=== CRASH ===\r\nBalance: {balance} PLN Bet: {} PLN\r\n\r\nERROR: {error}\r\n\r\n[SPACE] Play [+/=/-] Bet [Q] Quit", | ||
| 59 | state.bet_amount | ||
| 60 | ); | ||
| 61 | } | ||
| 62 | |||
| 63 | format!( | ||
| 64 | "=== CRASH ===\r\nBalance: {} PLN Bet: {} PLN\r\nMultiplier: {}x\r\nPotential: {} PLN\r\n{}\r\n{}", | ||
| 65 | balance, | ||
| 66 | state.bet_amount, | ||
| 67 | multiplier, | ||
| 68 | potential, | ||
| 69 | Self::status_text(state), | ||
| 70 | Self::controls(state) | ||
| 71 | ) | ||
| 72 | } | ||
| 73 | |||
| 74 | fn render_lines(&self, _state: &GameState) -> usize { | ||
| 75 | CRASH_BOARD_LINES | ||
| 76 | } | ||
| 77 | |||
| 78 | fn get_help(&self) -> String { | ||
| 79 | "CRASH\n\ | ||
| 80 | =====\n\ | ||
| 81 | The multiplier rises from 1.00x and crashes at a hidden point.\n\ | ||
| 82 | Cash out before it crashes to win bet x multiplier.\n\ | ||
| 83 | A round can crash at 1.00x, so an instant cashout still risks the bet.\n\ | ||
| 84 | \n\ | ||
| 85 | C - cash out at the server's current multiplier\n\ | ||
| 86 | SPACE - start the next round\n\ | ||
| 87 | +/- - change the next round's bet\n\ | ||
| 88 | Q - forfeit an active round (bet is lost), or leave when idle" | ||
| 89 | .to_string() | ||
| 90 | } | ||
| 91 | } | ||
