Skip to content

Commit 0e68057

Browse files
Merge pull request #170 from StecuPM/feature/slots-postgame-stats
Add postgame stats for Slots
2 parents 16a07d6 + ca125d2 commit 0e68057

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

casino/games/slots/slots.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Literal
44

55
from casino.accounts import Account
6+
from casino.stats import GameStats, display_stats
67
from casino.types import GameContext
78
from casino.utils import clear_screen, cprint, cinput, display_topbar
89

@@ -239,6 +240,7 @@ def play_slots(ctx: GameContext) -> None:
239240
"""Play slots game."""
240241
account = ctx.account
241242
min_bet = ctx.config.slots_min_line_bet
243+
stats = GameStats("Slots", account.balance)
242244
take_new_bet = True
243245
bet_amount = 0
244246
while True:
@@ -248,6 +250,8 @@ def play_slots(ctx: GameContext) -> None:
248250
if account.balance < min_bet:
249251
cprint("You don't have enough money to make a bet.\n\n")
250252
cinput("Press Enter to continue...")
253+
stats.ending_balance = account.balance
254+
display_stats(stats)
251255
return
252256
bet_amount = get_bet_amount(ctx)
253257
take_new_bet = False
@@ -273,6 +277,8 @@ def play_slots(ctx: GameContext) -> None:
273277
display_topbar(account, **HEADER_OPTIONS)
274278
print_spin(items, 0)
275279
cprint(f"MATCH: +{money_gain} chips")
280+
stats.rounds_played += 1
281+
stats.wins += 1
276282
else:
277283
items = (get_rand_item(), get_rand_item(), get_rand_item())
278284
while len(set(items)) == 1:
@@ -282,11 +288,15 @@ def play_slots(ctx: GameContext) -> None:
282288
display_topbar(account, **HEADER_OPTIONS)
283289
print_spin(items, 0)
284290
cprint(f"NO MATCH: -{bet_amount} chips")
291+
stats.rounds_played += 1
292+
stats.losses += 1
285293

286294
# Choose what to do after spin
287295
choice = get_player_choice(ctx, items, bet_amount)
288296
match choice:
289297
case "quit":
298+
stats.ending_balance = account.balance
299+
display_stats(stats)
290300
return
291301
case "change_bet":
292302
take_new_bet = True

0 commit comments

Comments
 (0)