From cf79298b04e04793f89971a8ea9e8184980a20fc Mon Sep 17 00:00:00 2001 From: Phan Huy Tran Date: Wed, 7 May 2025 14:17:41 +0200 Subject: [PATCH 001/276] feat: add blank status --- .../de/szut/casino/slots/SlotService.java | 56 +++++++++++++------ .../java/de/szut/casino/slots/Status.java | 7 +++ 2 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 backend/src/main/java/de/szut/casino/slots/Status.java diff --git a/backend/src/main/java/de/szut/casino/slots/SlotService.java b/backend/src/main/java/de/szut/casino/slots/SlotService.java index 8557480..43f2e52 100644 --- a/backend/src/main/java/de/szut/casino/slots/SlotService.java +++ b/backend/src/main/java/de/szut/casino/slots/SlotService.java @@ -33,6 +33,7 @@ public class SlotService { this.thirdReel = shuffleReel(reelStrip); } + public SpinResult spin(BigDecimal betAmount, UserEntity user) { int index1 = this.random.nextInt(REEL_LENGTH); int index2 = this.random.nextInt(REEL_LENGTH); @@ -42,31 +43,36 @@ public class SlotService { Symbol symbol2 = getSymbolAt(this.secondReel, index2); Symbol symbol3 = getSymbolAt(this.thirdReel, index3); - boolean isWin = symbol1.equals(symbol2) && symbol1.equals(symbol3); + Status status = determineStatus(symbol1, symbol2, symbol3); - SpinResult spinResult = processResult(betAmount, user, isWin, symbol1); + SpinResult spinResult = processResult(betAmount, user, status, symbol1); buildResultMatrix(spinResult, index1, index2, index3); return spinResult; } - private SpinResult processResult(BigDecimal betAmount, UserEntity user, boolean isWin, Symbol winSymbol) { - BigDecimal resultAmount; - String status; - - if (isWin) { - resultAmount = betAmount.multiply(winSymbol.getPayoutMultiplier()); - status = "win"; - this.balanceService.addFunds(user, resultAmount); - } else { - resultAmount = betAmount; - status = "lose"; - this.balanceService.subtractFunds(user, betAmount); - } - + private SpinResult processResult(BigDecimal betAmount, UserEntity user, Status status, Symbol winSymbol) { SpinResult spinResult = new SpinResult(); - spinResult.setStatus(status); - spinResult.setAmount(resultAmount); + + switch (status) { + case WIN: + BigDecimal winAmount = betAmount.multiply(winSymbol.getPayoutMultiplier()); + this.balanceService.addFunds(user, winAmount); + spinResult.setAmount(winAmount); + spinResult.setStatus(Status.WIN.name().toLowerCase()); + break; + + case BLANK: + spinResult.setAmount(BigDecimal.ZERO); + spinResult.setStatus(Status.BLANK.name().toLowerCase()); + break; + + case LOSE: + this.balanceService.subtractFunds(user, betAmount); + spinResult.setAmount(betAmount); + spinResult.setStatus(Status.LOSE.name().toLowerCase()); + break; + } return spinResult; } @@ -124,4 +130,18 @@ public class SlotService { return reel.get(effectiveIndex); } + + private Status determineStatus(Symbol symbol1, Symbol symbol2, Symbol symbol3) { + boolean allSymbolsMatch = symbol1.equals(symbol2) && symbol1.equals(symbol3); + + if (allSymbolsMatch) { + if (symbol1 == Symbol.BLANK) { + return Status.BLANK; + } else { + return Status.WIN; + } + } + + return Status.LOSE; + } } diff --git a/backend/src/main/java/de/szut/casino/slots/Status.java b/backend/src/main/java/de/szut/casino/slots/Status.java new file mode 100644 index 0000000..c53611f --- /dev/null +++ b/backend/src/main/java/de/szut/casino/slots/Status.java @@ -0,0 +1,7 @@ +package de.szut.casino.slots; + +public enum Status { + WIN, + LOSE, + BLANK +} From f81351243629f2ffb6f75a0087d1056c298a82a1 Mon Sep 17 00:00:00 2001 From: Phan Huy Tran Date: Wed, 7 May 2025 14:17:57 +0200 Subject: [PATCH 002/276] feat: add blank status --- backend/src/main/java/de/szut/casino/slots/SlotService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/main/java/de/szut/casino/slots/SlotService.java b/backend/src/main/java/de/szut/casino/slots/SlotService.java index 43f2e52..c327742 100644 --- a/backend/src/main/java/de/szut/casino/slots/SlotService.java +++ b/backend/src/main/java/de/szut/casino/slots/SlotService.java @@ -33,7 +33,6 @@ public class SlotService { this.thirdReel = shuffleReel(reelStrip); } - public SpinResult spin(BigDecimal betAmount, UserEntity user) { int index1 = this.random.nextInt(REEL_LENGTH); int index2 = this.random.nextInt(REEL_LENGTH); From bc56b498ee5d6d73467a12bcf6b61c0f68f60a2b Mon Sep 17 00:00:00 2001 From: Phan Huy Tran Date: Wed, 7 May 2025 13:56:25 +0200 Subject: [PATCH 003/276] feat: add bare slots frontend, remove bun start warnings --- frontend/src/app/app.routes.ts | 5 ++ .../game/blackjack/blackjack.component.ts | 34 ++++++------ .../animated-number.component.ts | 6 +- .../game-result/game-result.component.ts | 2 +- .../feature/game/slots/slots.component.html | 52 ++++++++++++++++++ .../app/feature/game/slots/slots.component.ts | 55 +++++++++++++++++++ .../transaction-history.component.ts | 20 ++----- .../components/navbar/navbar.component.ts | 2 +- 8 files changed, 139 insertions(+), 37 deletions(-) create mode 100644 frontend/src/app/feature/game/slots/slots.component.html create mode 100644 frontend/src/app/feature/game/slots/slots.component.ts diff --git a/frontend/src/app/app.routes.ts b/frontend/src/app/app.routes.ts index c536f8f..ce4451c 100644 --- a/frontend/src/app/app.routes.ts +++ b/frontend/src/app/app.routes.ts @@ -21,4 +21,9 @@ export const routes: Routes = [ loadComponent: () => import('./feature/game/blackjack/blackjack.component'), canActivate: [authGuard], }, + { + path: 'game/slots', + loadComponent: () => import('./feature/game/slots/slots.component'), + canActivate: [authGuard], + }, ]; diff --git a/frontend/src/app/feature/game/blackjack/blackjack.component.ts b/frontend/src/app/feature/game/blackjack/blackjack.component.ts index 3e58e25..64ef4ef 100644 --- a/frontend/src/app/feature/game/blackjack/blackjack.component.ts +++ b/frontend/src/app/feature/game/blackjack/blackjack.component.ts @@ -1,20 +1,19 @@ -import { ChangeDetectionStrategy, Component, inject, OnInit, signal } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { Router } from '@angular/router'; -import { PlayingCardComponent } from './components/playing-card/playing-card.component'; -import { DealerHandComponent } from './components/dealer-hand/dealer-hand.component'; -import { PlayerHandComponent } from './components/player-hand/player-hand.component'; -import { GameControlsComponent } from './components/game-controls/game-controls.component'; -import { GameInfoComponent } from './components/game-info/game-info.component'; -import { BlackjackGame, Card } from '@blackjack/models/blackjack.model'; -import { BlackjackService } from '@blackjack/services/blackjack.service'; -import { HttpErrorResponse } from '@angular/common/http'; -import { GameResultComponent } from '@blackjack/components/game-result/game-result.component'; -import { GameState } from '@blackjack/enum/gameState'; -import { NavbarComponent } from '@shared/components/navbar/navbar.component'; -import { UserService } from '@service/user.service'; -import { timer } from 'rxjs'; -import { DebtDialogComponent } from '@shared/components/debt-dialog/debt-dialog.component'; +import {ChangeDetectionStrategy, Component, inject, OnInit, signal} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {Router} from '@angular/router'; +import {DealerHandComponent} from './components/dealer-hand/dealer-hand.component'; +import {PlayerHandComponent} from './components/player-hand/player-hand.component'; +import {GameControlsComponent} from './components/game-controls/game-controls.component'; +import {GameInfoComponent} from './components/game-info/game-info.component'; +import {BlackjackGame, Card} from '@blackjack/models/blackjack.model'; +import {BlackjackService} from '@blackjack/services/blackjack.service'; +import {HttpErrorResponse} from '@angular/common/http'; +import {GameResultComponent} from '@blackjack/components/game-result/game-result.component'; +import {GameState} from '@blackjack/enum/gameState'; +import {NavbarComponent} from '@shared/components/navbar/navbar.component'; +import {UserService} from '@service/user.service'; +import {timer} from 'rxjs'; +import {DebtDialogComponent} from '@shared/components/debt-dialog/debt-dialog.component'; @Component({ selector: 'app-blackjack', @@ -22,7 +21,6 @@ import { DebtDialogComponent } from '@shared/components/debt-dialog/debt-dialog. imports: [ CommonModule, NavbarComponent, - PlayingCardComponent, DealerHandComponent, PlayerHandComponent, GameControlsComponent, diff --git a/frontend/src/app/feature/game/blackjack/components/animated-number/animated-number.component.ts b/frontend/src/app/feature/game/blackjack/components/animated-number/animated-number.component.ts index 7d78871..0b8cd4c 100644 --- a/frontend/src/app/feature/game/blackjack/components/animated-number/animated-number.component.ts +++ b/frontend/src/app/feature/game/blackjack/components/animated-number/animated-number.component.ts @@ -8,13 +8,13 @@ import { SimpleChanges, ViewChild, } from '@angular/core'; -import { CommonModule, CurrencyPipe } from '@angular/common'; -import { CountUp } from 'countup.js'; +import {CommonModule} from '@angular/common'; +import {CountUp} from 'countup.js'; @Component({ selector: 'app-animated-number', standalone: true, - imports: [CommonModule, CurrencyPipe], + imports: [CommonModule], template: ` {{ formattedValue }} `, changeDetection: ChangeDetectionStrategy.OnPush, }) diff --git a/frontend/src/app/feature/game/blackjack/components/game-result/game-result.component.ts b/frontend/src/app/feature/game/blackjack/components/game-result/game-result.component.ts index 74d02e4..06f2d3a 100644 --- a/frontend/src/app/feature/game/blackjack/components/game-result/game-result.component.ts +++ b/frontend/src/app/feature/game/blackjack/components/game-result/game-result.component.ts @@ -7,7 +7,7 @@ import { AnimatedNumberComponent } from '../animated-number/animated-number.comp @Component({ selector: 'app-game-result', standalone: true, - imports: [CommonModule, CurrencyPipe, AnimatedNumberComponent], + imports: [CommonModule, AnimatedNumberComponent], template: `