From 0d977e5cca2ec059993556885609205f468250c4 Mon Sep 17 00:00:00 2001 From: Maxiwere45 Date: Tue, 9 Jun 2026 11:20:46 +0200 Subject: [PATCH] feat(domain): add immutable GameState Co-Authored-By: Claude Opus 4.8 --- lib/domain/game/game_state.dart | 68 +++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 lib/domain/game/game_state.dart diff --git a/lib/domain/game/game_state.dart b/lib/domain/game/game_state.dart new file mode 100644 index 0000000..19d65f2 --- /dev/null +++ b/lib/domain/game/game_state.dart @@ -0,0 +1,68 @@ +import '../../core/config/app_constants.dart'; +import '../entities/pokemon.dart'; + +/// Phase courante de la partie. +enum GameStatus { loading, playing, roundWon, gameOver, error } + +/// Résultat d'une soumission de réponse. +enum GuessResult { correct, wrong, gameOver, invalid } + +/// État immuable d'une partie. +class GameState { + final Pokemon? currentPokemon; + final int lives; + final int skips; + final int hints; + final int sessionCorrectCount; + final int currentScore; + final int bestScore; + final bool isShiny; + final bool isHintUsed; + final GameStatus status; + + const GameState({ + this.currentPokemon, + this.lives = AppConstants.startingLives, + this.skips = AppConstants.startingSkips, + this.hints = AppConstants.startingHints, + this.sessionCorrectCount = 0, + this.currentScore = 0, + this.bestScore = 0, + this.isShiny = false, + this.isHintUsed = false, + this.status = GameStatus.loading, + }); + + GameState copyWith({ + Pokemon? currentPokemon, + int? lives, + int? skips, + int? hints, + int? sessionCorrectCount, + int? currentScore, + int? bestScore, + bool? isShiny, + bool? isHintUsed, + GameStatus? status, + }) { + return GameState( + currentPokemon: currentPokemon ?? this.currentPokemon, + lives: lives ?? this.lives, + skips: skips ?? this.skips, + hints: hints ?? this.hints, + sessionCorrectCount: sessionCorrectCount ?? this.sessionCorrectCount, + currentScore: currentScore ?? this.currentScore, + bestScore: bestScore ?? this.bestScore, + isShiny: isShiny ?? this.isShiny, + isHintUsed: isHintUsed ?? this.isHintUsed, + status: status ?? this.status, + ); + } +} + +/// Issue d'un appel à GameEngine.submitGuess : nouvel état + nature du résultat. +class GuessOutcome { + final GameState state; + final GuessResult result; + const GuessOutcome(this.state, this.result); +}