diff options
| author | salmonik <salmonik@tuta.io> | 2026-08-24 14:48:12 +0200 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-08-24 14:48:12 +0200 |
| commit | 5d6b5049c2a34a3f8abe725d4a871ba84a0dd714 (patch) | |
| tree | 57cb03bf59b3358a96742f455d38c21f4f645396 /src/bin/client/games/slots.rs | |
| parent | stable and working, both platforms (diff) | |
| download | zagan-bet-5d6b5049c2a34a3f8abe725d4a871ba84a0dd714.tar.gz zagan-bet-5d6b5049c2a34a3f8abe725d4a871ba84a0dd714.zip | |
TLS transport and games framework on client and server
Diffstat (limited to 'src/bin/client/games/slots.rs')
| -rw-r--r-- | src/bin/client/games/slots.rs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/bin/client/games/slots.rs b/src/bin/client/games/slots.rs new file mode 100644 index 0000000..2f9d63e --- /dev/null +++ b/src/bin/client/games/slots.rs | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | use crate::games::traits::{Game, GameState}; | ||
| 2 | |||
| 3 | pub struct SlotsGame; | ||
| 4 | |||
| 5 | impl SlotsGame { | ||
| 6 | pub fn new() -> Self { | ||
| 7 | Self | ||
| 8 | } | ||
| 9 | |||
| 10 | fn render_reels(&self, reels: &str) -> String { | ||
| 11 | if reels.is_empty() { | ||
| 12 | "[ ? ] [ ? ] [ ? ]".to_string() | ||
| 13 | } else { | ||
| 14 | let chars: Vec<char> = reels.chars().collect(); | ||
| 15 | format!( | ||
| 16 | "[ {} ] [ {} ] [ {} ]\r", | ||
| 17 | chars.get(0).unwrap_or(&'?'), | ||
| 18 | chars.get(1).unwrap_or(&'?'), | ||
| 19 | chars.get(2).unwrap_or(&'?') | ||
| 20 | ) | ||
| 21 | } | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | impl Game for SlotsGame { | ||
| 26 | fn get_name(&self) -> &'static str { | ||
| 27 | "Slots" | ||
| 28 | } | ||
| 29 | |||
| 30 | fn render(&self, state: &GameState) -> String { | ||
| 31 | let reels = state.data.get("reels").cloned().unwrap_or_default(); | ||
| 32 | |||
| 33 | let mut output = format!("\n=== SLOTS ===\r\n"); | ||
| 34 | output += &format!("Bet: {} PLN\r\n", state.bet_amount); | ||
| 35 | output += &format!("{}\r\n", self.render_reels(&reels)); | ||
| 36 | output += "\nPress [SPACE] to spin!\r\n"; | ||
| 37 | output += "\nControls: [+/-] Adjust Bet [Q] Quit\r\n"; | ||
| 38 | output | ||
| 39 | } | ||
| 40 | |||
| 41 | fn render_lines(&self, state: &GameState) -> usize { | ||
| 42 | self.render(state).lines().count() | ||
| 43 | } | ||
| 44 | |||
| 45 | fn get_help(&self) -> String { | ||
| 46 | "SLOTS GAME\n\ | ||
| 47 | =========\n\ | ||
| 48 | Match symbols to win!\n\ | ||
| 49 | \n\ | ||
| 50 | Payouts:\n\ | ||
| 51 | Three of a kind: 5x-100x bet\n\ | ||
| 52 | Two of a kind: 2x-20x bet\n\ | ||
| 53 | \n\ | ||
| 54 | Symbols: C=Cherry, L=Lemon, O=Orange, G=Grapes, D=Diamond, S=Seven\n\ | ||
| 55 | \n\ | ||
| 56 | Controls:\n\ | ||
| 57 | SPACE - Spin the reels\n\ | ||
| 58 | +/- - Adjust bet amount\n\ | ||
| 59 | Q - Exit the game" | ||
| 60 | .to_string() | ||
| 61 | } | ||
| 62 | } | ||
