1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
use crate::games::traits::{Game, GameState};
pub struct SlotsGame;
impl SlotsGame {
pub fn new() -> Self {
Self
}
fn render_reels(&self, reels: &str) -> String {
if reels.is_empty() {
"[ ? ] [ ? ] [ ? ]".to_string()
} else {
let chars: Vec<char> = reels.chars().collect();
format!(
"[ {} ] [ {} ] [ {} ]\r",
chars.get(0).unwrap_or(&'?'),
chars.get(1).unwrap_or(&'?'),
chars.get(2).unwrap_or(&'?')
)
}
}
}
impl Game for SlotsGame {
fn get_name(&self) -> &'static str {
"Slots"
}
fn render(&self, state: &GameState) -> String {
let reels = state.data.get("reels").cloned().unwrap_or_default();
let mut output = format!("\n=== SLOTS ===\r\n");
output += &format!("Bet: {} PLN\r\n", state.bet_amount);
output += &format!("{}\r\n", self.render_reels(&reels));
output += "\nPress [SPACE] to spin!\r\n";
output += "\nControls: [+/-] Adjust Bet [Q] Quit\r\n";
output
}
fn render_lines(&self, _state: &GameState) -> usize {
// Fixed count matching the render() layout:
// blank, header, bet, reels, blank, prompt, blank, controls
8
}
fn get_help(&self) -> String {
"SLOTS GAME\n\
=========\n\
Match symbols to win!\n\
\n\
Payouts:\n\
Three of a kind: 2x-28x bet\n\
Two of a kind: 1x-3x bet\n\
\n\
Symbols: C=Cherry, L=Lemon, O=Orange, G=Grapes, D=Diamond, S=Seven\n\
\n\
Controls:\n\
SPACE - Spin the reels\n\
+/- - Adjust bet amount\n\
Q - Exit the game"
.to_string()
}
}
|