using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions; using MiniJeuxFinal.Games.PierrePapierCiseaux.Factories; using MiniJeuxFinal.Games.PierrePapierCiseaux.Players; using MiniJeuxFinal.Wrappers; namespace MiniJeuxFinal.Games.PierrePapierCiseaux { internal class PierrePapierCiseauxGame : IGame { public string Name => "Jeu du Pierre, Papier, Ciseaux 🧱 📄 ✂️"; private readonly int _totalRounds; private readonly string _playerName; 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, string playerName) { _totalRounds = totalRound; _playerName = playerName; } public void Start() { IAction[] lstActions = [new StoneAction(), new PaperAction(), new ScissorsAction()]; var player = new PlayerPpc(_playerName, new InputActionFactory(new ConsoleService())); player.AddAction(lstActions); var computer = new PlayerPpc("Ordi", new RandomActionFactory()); computer.AddAction(lstActions); while (player.Score < _totalRounds && computer.Score < _totalRounds) { var actionPLayer = (IActionPpc)player.Play(); var actionComputer = (IActionPpc)computer.Play(); TurnStarted?.Invoke(this, (actionPLayer.Name, actionComputer.Name)); if (actionPLayer.ToWin(actionComputer)) player.IncrementScore(); else if (actionComputer.ToWin(actionPLayer)) computer.IncrementScore(); else { TurnEnded?.Invoke(this, (null, [player, computer])); continue; } TurnEnded?.Invoke(this, (actionPLayer.ToWin(actionComputer) ? player : computer, [player, computer])); } GameEnded?.Invoke(this, (player.Score > computer.Score ? player : computer, [player, computer])); } } }