using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions; namespace MiniJeuxFinal.Games.PierrePapierCiseaux { public class PierrePapierCiseauxGame : IGame { private readonly int _totalRounds; private readonly IPlayer _player; private readonly IPlayer _computer; public event EventHandler<(IPlayer winner, IPlayer[] players)>? GameEnded; public event EventHandler<(IPlayer? winner, IPlayer[] players)>? TurnEnded; public event EventHandler<(string playerChoice, string computerChoice)>? TurnStarted; public PierrePapierCiseauxGame(int totalRound, IPlayer player, IPlayer computer) { _totalRounds = totalRound; _player = player; _computer = computer; } public string Name => "Jeu du Pierre, Papier, Ciseaux 🧱 📄 ✂️"; public void Start() { while (_player.Score < _totalRounds && _computer.Score < _totalRounds) { var result = Play(); if (result != null) result.IncrementScore(); TurnEnded?.Invoke(this, (result, [_player, _computer])); } var winner = _player.Score > _computer.Score ? _player : _computer; GameEnded?.Invoke(this, (winner, [_player, _computer])); } private IPlayer? Play() { var actionPLayer = (IActionPpc)_player.Play(); var actionComputer = (IActionPpc)_computer.Play(); TurnStarted?.Invoke(this, (actionPLayer.Name, actionComputer.Name)); if (actionPLayer.ToWin(actionComputer) == actionComputer.ToWin(actionPLayer)) return null; if (actionPLayer.ToWin(actionComputer)) return _player; return _computer; } } }