From 916d81e04647abae20200dc6b113bde18d50e7ac Mon Sep 17 00:00:00 2001 From: Jules LASCRET Date: Wed, 22 May 2024 19:16:27 +0200 Subject: [PATCH] revert 232c3b2feef0b07aa21c2bbdff95167017b17592 revert Added a ClearGame() method + moved the tile bag creation to StartGame() --- Qwirkle/QwirkleClassLibrary/Games/Game.cs | 35 ++++++----------------- Qwirkle/TestBase/TestGame.cs | 23 +++------------ 2 files changed, 12 insertions(+), 46 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index ab0da75..a3e2711 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -21,7 +21,7 @@ namespace QwirkleClassLibrary.Games public ReadOnlyDictionary ScoreBoard => scoreBoard.AsReadOnly(); private readonly Dictionary scoreBoard = new(); - private TileBag? bag = null; + private TileBag bag; public bool GameRunning { get; private set; } private Board board; @@ -56,6 +56,7 @@ namespace QwirkleClassLibrary.Games /// public Game() { + bag = CreateTileBag(3); board = CreateBoard(); } @@ -119,12 +120,6 @@ namespace QwirkleClassLibrary.Games /// /// Board public Board GetBoard() { return board; } - - /// - /// Returns the tile bag of the game - /// - /// - public TileBag GetTileBag() { return bag; } /// /// Creates a board with a number of columns and rows @@ -153,7 +148,6 @@ namespace QwirkleClassLibrary.Games public void StartGame() { if (players.Count < 2 || players.Count >= 5) return; - bag = CreateTileBag(3); GameRunning = true; } @@ -183,7 +177,7 @@ namespace QwirkleClassLibrary.Games { if (GetPlayingPlayerPosition() == -1) { - throw new ArgumentException("No player currently playing !"); + throw new ArgumentException("No player play."); } return players[GetPlayingPlayerPosition()]; } @@ -223,13 +217,10 @@ namespace QwirkleClassLibrary.Games { for (int j = 0; j < 6; j++) { - if (bag != null) - { - int val = RandomNumberGenerator.GetInt32(0, bag.TilesBag.Count); + int val = RandomNumberGenerator.GetInt32(0, bag.TilesBag.Count); - p.AddTileToPlayer(bag.TilesBag[val]); - bag.RemoveTileInBag(bag.TilesBag[val]); - } + p.AddTileToPlayer(bag.TilesBag[val]); + bag.RemoveTileInBag(bag.TilesBag[val]); } } } @@ -659,7 +650,7 @@ namespace QwirkleClassLibrary.Games /// /// /// - public bool CheckPlacementPossibilities(List playerTilesBagPos) + public bool CheckBoardTile(List playerTilesBagPos) { for (int i = 0; i < playerTilesBagPos.Count; i++) { @@ -691,7 +682,7 @@ namespace QwirkleClassLibrary.Games { List playerTilesBagPos = CheckTilesBag(); - if (playerTilesBagPos.Count != 0 && !CheckPlacementPossibilities(playerTilesBagPos)) + if (playerTilesBagPos.Count != 0 && !CheckBoardTile(playerTilesBagPos)) { OnEndOfGame(new EndOfGameNotifiedEventArgs(player)); GameRunning = false; @@ -701,15 +692,5 @@ namespace QwirkleClassLibrary.Games return false; } - - public void ClearGame() - { - players.Clear(); - scoreBoard.Clear(); - cellUsed.Clear(); - bag = null; - board = CreateBoard(); - GameRunning = false; - } } } \ No newline at end of file diff --git a/Qwirkle/TestBase/TestGame.cs b/Qwirkle/TestBase/TestGame.cs index 12b2a2d..d205135 100644 --- a/Qwirkle/TestBase/TestGame.cs +++ b/Qwirkle/TestBase/TestGame.cs @@ -214,19 +214,21 @@ public class TestGame game.AddPlayerInGame("Test1"); game.AddPlayerInGame("Test2"); + game.GiveTilesToPlayers(); + if (except) { game.StartGame(); - game.GiveTilesToPlayers(); game.SetNextPlayer(); Assert.True(game.PlaceTile(game.GetPlayingPlayer(), game.PlayerList[game.GetPlayingPlayerPosition()].Tiles[0], 1, 1)); return; } game.StartGame(); - game.GiveTilesToPlayers(); game.SetNextPlayer(); Assert.False(game.PlaceTile(game.GetPlayingPlayer(), game.PlayerList[game.GetPlayingPlayerPosition()].Tiles[0], -5, 1)); + return; + } [Fact] @@ -388,23 +390,6 @@ public class TestGame game.CheckGameOver(game.GetPlayingPlayer()); } - - [Fact] - public void Test_ClearGame() - { - Game game = new Game(); - game.AddPlayerInGame("Test1"); - game.AddPlayerInGame("Test2"); - - game.StartGame(); - game.SetFirstPlayer(); - - game.ClearGame(); - - Assert.Empty(game.PlayerList); - Assert.Null(game.GetTileBag()); - Assert.Equal(-1, game.GetPlayingPlayerPosition()); - } }