revert 232c3b2fee
continuous-integration/drone/push Build is failing Details

revert Added a ClearGame() method + moved the tile bag creation to StartGame()
test_old_branch
Jules LASCRET 11 months ago
parent d60308b275
commit 916d81e046

@ -21,7 +21,7 @@ namespace QwirkleClassLibrary.Games
public ReadOnlyDictionary<Player, int> ScoreBoard => scoreBoard.AsReadOnly();
private readonly Dictionary<Player, int> 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
/// </summary>
public Game()
{
bag = CreateTileBag(3);
board = CreateBoard();
}
@ -120,12 +121,6 @@ namespace QwirkleClassLibrary.Games
/// <returns>Board</returns>
public Board GetBoard() { return board; }
/// <summary>
/// Returns the tile bag of the game
/// </summary>
/// <returns></returns>
public TileBag GetTileBag() { return bag; }
/// <summary>
/// Creates a board with a number of columns and rows
/// </summary>
@ -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()];
}
@ -222,8 +216,6 @@ namespace QwirkleClassLibrary.Games
foreach (var p in players)
{
for (int j = 0; j < 6; j++)
{
if (bag != null)
{
int val = RandomNumberGenerator.GetInt32(0, bag.TilesBag.Count);
@ -232,7 +224,6 @@ namespace QwirkleClassLibrary.Games
}
}
}
}
/// <summary>
/// Sets the first player of the game at the beginning of the game
@ -659,7 +650,7 @@ namespace QwirkleClassLibrary.Games
/// </summary>
/// <param name="playerTilesBagPos"></param>
/// <returns></returns>
public bool CheckPlacementPossibilities(List<int> playerTilesBagPos)
public bool CheckBoardTile(List<int> playerTilesBagPos)
{
for (int i = 0; i < playerTilesBagPos.Count; i++)
{
@ -691,7 +682,7 @@ namespace QwirkleClassLibrary.Games
{
List<int> 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;
}
}
}

@ -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]
@ -389,22 +391,5 @@ public class TestGame
}
[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());
}
}

Loading…
Cancel
Save