From 4a3ab90bdcab5b984f2afb9f25df20f7009c84b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20LAVERGNE?= Date: Sun, 2 Jun 2024 16:48:43 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Suppression=20d'un=20constructeu?= =?UTF-8?q?r=20et=20d=C3=A9veloppement=20de=20la=20m=C3=A9thode=20d'initia?= =?UTF-8?q?lisation=20=C3=A0=20la=20place?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Trek-12/Models/Game/Game.cs | 61 +++++++++++++++++------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/source/Trek-12/Models/Game/Game.cs b/source/Trek-12/Models/Game/Game.cs index 982b2af..c4f4460 100644 --- a/source/Trek-12/Models/Game/Game.cs +++ b/source/Trek-12/Models/Game/Game.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; @@ -27,14 +28,20 @@ namespace Models.Game public List BestScores { get; set; } private bool _isRunning; + public bool IsRunning + { + get => _isRunning; + private set => _isRunning = value; + } + public Player CurrentPlayer { get; private set; } public Map UsedMap { get; private set; } - private Dice Dice1 { get; } - private Dice Dice2 { get; } + public Dice Dice1 { get; private set; } + public Dice Dice2 { get; private set; } - private int Turn { get; set; } + public int Turn { get; private set; } public Rules.Rules GameRules { get; } @@ -98,25 +105,10 @@ namespace Models.Game Games = new List(); Maps = new List(); BestScores = new List(); - - _isRunning = false; - } - - - /// - /// Initializes a new instance of the class. - /// - /// The player who play the game. - /// The map to be used in the game. - public Game(Player player, Map map) - { - _isRunning = false; - UsedMap = map; - CurrentPlayer = player; - Dice1 = new Dice(); - Dice2 = new Dice(1); - Turn = 1; + GameRules = new Rules.Rules(); + + IsRunning = false; } /// @@ -240,13 +232,30 @@ namespace Models.Game } } } - + /// /// Initializes the game. /// - public void InitializeGame() + public void InitializeGame(Map map, Player player, bool startImmediately = true) + { + UsedMap = map; + CurrentPlayer = player; + Turn = 1; + Dice1 = new Dice(); + Dice2 = new Dice(1); + + if (startImmediately) + { + StartGame(); + } + } + + /// + /// Starts the game. + /// + private void StartGame() { - _isRunning = true; + IsRunning = true; GameStarted?.Invoke(this, new GameStartedEventArgs(CurrentPlayer)); GameLoop(); } @@ -256,7 +265,7 @@ namespace Models.Game /// private void EndGame(int? pts) { - _isRunning = false; + IsRunning = false; GameEnded?.Invoke(this, new GameEndedEventArgs(CurrentPlayer, pts)); } @@ -265,7 +274,7 @@ namespace Models.Game /// private void GameLoop() { - while (_isRunning) + while (IsRunning) { if (Turn == 20) {