feat: style dice game page

This commit is contained in:
Phan Huy Tran 2025-05-21 10:36:32 +02:00 committed by Phan Huy Tran
commit d58f24ccbf

View file

@ -1,51 +1,74 @@
<div class="dice-container"> <div class="container mx-auto px-4 py-8 space-y-8">
<h2>Dice Game</h2> <h1 class="text-3xl font-bold text-white mb-6">Dice Game</h1>
<form [formGroup]="diceForm" (ngSubmit)="roll()"> <div class="grid grid-cols-1 lg:grid-cols-4 gap-8">
<div class="controls"> <div class="lg:col-span-1 card p-8 space-y-6">
<label for="betAmount">Bet Amount:</label> <form [formGroup]="diceForm" (ngSubmit)="roll()" class="space-y-6">
<input id="betAmount" type="number" formControlName="betAmount" min="0.01" step="0.01"> <div class="controls space-y-4">
<div>
<label for="betAmount" class="block text-text-secondary mb-2">Bet Amount:</label>
<input id="betAmount" type="number" formControlName="betAmount" min="0.01" step="0.01"
class="w-full bg-deep-blue-light text-white rounded-lg p-2 focus:outline-none focus:ring-1 focus:ring-emerald">
@if (hasError('betAmount', 'required')) { @if (hasError('betAmount', 'required')) {
<span class="error">Bet Amount is required</span> <span class="text-accent-red text-sm mt-1 block">Bet Amount is required</span>
} }
@if (hasError('betAmount', 'min')) { @if (hasError('betAmount', 'min')) {
<span class="error">Bet Amount must be at least 0.01</span> <span class="text-accent-red text-sm mt-1 block">Bet Amount must be at least 0.01</span>
} }
<div class="roll-mode">
<button type="button" (click)="toggleRollMode()" [class.active]="diceForm.get('rollOver')?.value">Roll Over</button>
<button type="button" (click)="toggleRollMode()" [class.active]="!diceForm.get('rollOver')?.value">Roll Under</button>
</div> </div>
<label for="targetValue">Target Value:</label> <div>
<input id="targetValue" type="number" formControlName="targetValue" min="1" max="100" step="0.01"> <label class="block text-text-secondary mb-2">Roll Mode:</label>
<div class="roll-mode flex rounded-lg overflow-hidden">
<button type="button" (click)="toggleRollMode()" [ngClass]="{'bg-emerald text-white': diceForm.get('rollOver')?.value, 'bg-deep-blue-light text-text-secondary': !diceForm.get('rollOver')?.value}"
class="flex-1 py-2 text-center font-semibold transition-colors duration-200">Roll Over</button>
<button type="button" (click)="toggleRollMode()" [ngClass]="{'bg-emerald text-white': !diceForm.get('rollOver')?.value, 'bg-deep-blue-light text-text-secondary': diceForm.get('rollOver')?.value}"
class="flex-1 py-2 text-center font-semibold transition-colors duration-200">Roll Under</button>
</div>
</div>
<div>
<label for="targetValue" class="block text-text-secondary mb-2">Target Value: {{ diceForm.get('targetValue')?.value | number:'1.0-2' }}</label>
<input id="targetValue" type="range" formControlName="targetValue" min="1" max="100" step="0.01"
class="w-full h-2 bg-deep-blue-light rounded-lg appearance-none cursor-pointer range-lg accent-emerald">
@if (hasError('targetValue', 'required')) { @if (hasError('targetValue', 'required')) {
<span class="error">Target Value is required</span> <span class="text-accent-red text-sm mt-1 block">Target Value is required</span>
} }
@if (hasError('targetValue', 'min')) { @if (hasError('targetValue', 'min')) {
<span class="error">Target Value must be at least 1</span> <span class="text-accent-red text-sm mt-1 block">Target Value must be at least 1</span>
} }
@if (hasError('targetValue', 'max')) { @if (hasError('targetValue', 'max')) {
<span class="error">Target Value must be at most 100</span> <span class="text-accent-red text-sm mt-1 block">Target Value must be at most 100</span>
} }
</div> </div>
<div class="info">
<p>Win Chance: {{ winChance() | number:'1.0-2' }}%</p>
<p>Potential Win: {{ potentialWin() | currency:'EUR':'symbol':'1.2-2' }}</p>
</div> </div>
<button type="submit">Roll Dice</button> <div class="info space-y-2 text-text-secondary">
<p>Win Chance: <span class="text-white">{{ winChance() | number:'1.0-2' }}%</span></p>
<p>Potential Win: <span class="text-white">{{ potentialWin() | currency:'EUR':'symbol':'1.2-2' }}</span></p>
</div>
<button type="submit" class="button-primary w-full py-2 font-bold">Roll Dice</button>
</form> </form>
</div>
<div class="lg:col-span-3 card p-8 flex items-center justify-center">
<!-- Placeholder for spinning dice animation -->
@if (rolledValue() !== null) {
<div class="text-white text-center text-8xl font-bold">
{{ rolledValue() }}
</div>
}
</div>
</div>
@if (rolledValue() !== null) { @if (rolledValue() !== null) {
<div class="result"> <div class="result max-w-sm mx-auto card p-6 mt-8 text-center">
<h3>Result</h3>
<p>Rolled Value: {{ rolledValue() }}</p>
@if (win()) { @if (win()) {
<p>You Won! Payout: {{ payout() | currency:'EUR':'symbol':'1.2-2' }}</p> <p class="text-emerald text-base font-semibold">You Won! Payout: {{ payout() | currency:'EUR':'symbol':'1.2-2' }}</p>
} @else { } @else {
<p>You Lost.</p> <p class="text-accent-red text-base font-semibold">You Lost.</p>
} }
</div> </div>
} }