diff options
| author | salmonik <salmonik@tuta.io> | 2026-10-28 23:31:54 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-10-28 23:31:54 +0100 |
| commit | 7d18a268547734daf19a740b6533e9c1697baf1a (patch) | |
| tree | 789f519a19b053b8ad0ff41d2828fe22c06fb21a /src/client | |
| parent | v1.2.0: show the symbol paytable on the slots board (diff) | |
| download | zagan-bet-7d18a268547734daf19a740b6533e9c1697baf1a.tar.gz zagan-bet-7d18a268547734daf19a740b6533e9c1697baf1a.zip | |
v1.2.1: track wrapped board lines and split the paytable
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/games/slots.rs | 10 | ||||
| -rw-r--r-- | src/client/ui.rs | 17 |
2 files changed, 23 insertions, 4 deletions
diff --git a/src/client/games/slots.rs b/src/client/games/slots.rs index 7e59919..a417e7d 100644 --- a/src/client/games/slots.rs +++ b/src/client/games/slots.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | use super::traits::{Game, GamePhase, GameState}; | 1 | use super::traits::{Game, GamePhase, GameState}; |
| 2 | use crate::slots::{paytable_line, REELS, ROWS}; | 2 | use crate::slots::{paytable_lines, REELS, ROWS}; |
| 3 | 3 | ||
| 4 | /// Height of the game board. It must never depend on the spin result. | 4 | /// Height of the game board. It must never depend on the spin result. |
| 5 | pub const SLOT_BOARD_LINES: usize = 9; | 5 | pub const SLOT_BOARD_LINES: usize = 10; |
| 6 | 6 | ||
| 7 | pub struct SlotsGame; | 7 | pub struct SlotsGame; |
| 8 | 8 | ||
| @@ -102,15 +102,17 @@ impl Game for SlotsGame { | |||
| 102 | .unwrap_or("?"); | 102 | .unwrap_or("?"); |
| 103 | let winning = Self::highlighted_cells(state); | 103 | let winning = Self::highlighted_cells(state); |
| 104 | let grid = self.render_grid(&reels, &winning); | 104 | let grid = self.render_grid(&reels, &winning); |
| 105 | let paytable = paytable_lines(); | ||
| 105 | 106 | ||
| 106 | format!( | 107 | format!( |
| 107 | "=== SLOTS ===\r\nBet: {} PLN Balance: {} PLN\r\n{}\r\n{}\r\n{}\r\n{}\r\n{}\r\n{}\r\n[+/-] Bet [SPACE] Spin [Q] Quit", | 108 | "=== SLOTS ===\r\nBet: {} PLN Balance: {} PLN\r\n{}\r\n{}\r\n{}\r\n{}\r\n{}\r\n{}\r\n{}\r\n[+/-] Bet [SPACE] Spin [Q] Quit", |
| 108 | state.bet_amount, | 109 | state.bet_amount, |
| 109 | balance, | 110 | balance, |
| 110 | grid[0], | 111 | grid[0], |
| 111 | grid[1], | 112 | grid[1], |
| 112 | grid[2], | 113 | grid[2], |
| 113 | paytable_line(), | 114 | paytable[0], |
| 115 | paytable[1], | ||
| 114 | self.render_status(state), | 116 | self.render_status(state), |
| 115 | self.render_win_lines(state) | 117 | self.render_win_lines(state) |
| 116 | ) | 118 | ) |
diff --git a/src/client/ui.rs b/src/client/ui.rs index 493f660..11cedc7 100644 --- a/src/client/ui.rs +++ b/src/client/ui.rs | |||
| @@ -257,6 +257,23 @@ pub fn input_cursor_column(prompt_len: usize, input_len: usize) -> u16 { | |||
| 257 | .min(u16::MAX as usize) as u16 | 257 | .min(u16::MAX as usize) as u16 |
| 258 | } | 258 | } |
| 259 | 259 | ||
| 260 | /// Number of terminal rows a block of logical lines occupies after wrapping. | ||
| 261 | /// Empty lines still occupy one row. | ||
| 262 | pub fn visual_line_count(lines: &[String], width: usize) -> usize { | ||
| 263 | let width = width.max(1); | ||
| 264 | lines | ||
| 265 | .iter() | ||
| 266 | .map(|line| { | ||
| 267 | let columns = display_width(line); | ||
| 268 | if columns == 0 { | ||
| 269 | 1 | ||
| 270 | } else { | ||
| 271 | columns.div_ceil(width) | ||
| 272 | } | ||
| 273 | }) | ||
| 274 | .sum() | ||
| 275 | } | ||
| 276 | |||
| 260 | /// Format a ping round-trip time with one decimal place. | 277 | /// Format a ping round-trip time with one decimal place. |
| 261 | pub fn format_pong(elapsed: std::time::Duration) -> String { | 278 | pub fn format_pong(elapsed: std::time::Duration) -> String { |
| 262 | format!("Pong ({:.1}ms)", elapsed.as_secs_f64() * 1000.0) | 279 | format!("Pong ({:.1}ms)", elapsed.as_secs_f64() * 1000.0) |
