Refacto
This commit is contained in:
57
Correction/MiniJeuxFinal/Ui/GameRunnerConsole.cs
Normal file
57
Correction/MiniJeuxFinal/Ui/GameRunnerConsole.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using MiniJeuxFinal.Games;
|
||||
|
||||
namespace MiniJeuxFinal.Ui
|
||||
{
|
||||
public class GameRunnerConsole
|
||||
{
|
||||
private readonly IGame _game;
|
||||
|
||||
public GameRunnerConsole(IGame game)
|
||||
{
|
||||
_game = game;
|
||||
SetupEvents();
|
||||
}
|
||||
|
||||
private void SetupEvents()
|
||||
{
|
||||
_game.TurnStarted += OnTurnStarted;
|
||||
_game.TurnEnded += OnTurnEnded;
|
||||
_game.GameEnded += OnGameEnded;
|
||||
}
|
||||
|
||||
private void OnTurnStarted(object? sender, (string playerChoice, string computerChoice) e)
|
||||
{
|
||||
Console.WriteLine($"Tu joues : {e.playerChoice}");
|
||||
Console.WriteLine($"L'ordinateur joue : {e.computerChoice}");
|
||||
}
|
||||
|
||||
private void OnTurnEnded(object? sender, (IPlayer? winner, IPlayer[] players) e)
|
||||
{
|
||||
Thread.Sleep(2000);
|
||||
Console.Clear();
|
||||
|
||||
if (e.winner == null)
|
||||
Console.WriteLine("Égalité !");
|
||||
else
|
||||
Console.WriteLine($"{e.winner.Name} gagne la manche");
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"Score : {e.players[0]} - {e.players[1]}");
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
private void OnGameEnded(object? sender, (IPlayer winner, IPlayer[] players) e)
|
||||
{
|
||||
Console.WriteLine($"{e.winner.Name} A GAGNÉ ! 🎉🎉🎉");
|
||||
var loser = e.players.First(p => p.Name != e.winner.Name);
|
||||
Console.WriteLine($"Score final : {e.winner.Score} - {loser.Score}");
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
Console.WriteLine(_game.Name);
|
||||
Console.WriteLine();
|
||||
_game.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user