|
|
@ -21,7 +21,7 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
public ReadOnlyDictionary<Player, int> ScoreBoard => scoreBoard.AsReadOnly();
|
|
|
|
public ReadOnlyDictionary<Player, int> ScoreBoard => scoreBoard.AsReadOnly();
|
|
|
|
private readonly Dictionary<Player, int> scoreBoard = new();
|
|
|
|
private readonly Dictionary<Player, int> scoreBoard = new();
|
|
|
|
|
|
|
|
|
|
|
|
private TileBag bag;
|
|
|
|
private TileBag? bag = null;
|
|
|
|
public bool GameRunning { get; private set; }
|
|
|
|
public bool GameRunning { get; private set; }
|
|
|
|
private Board board;
|
|
|
|
private Board board;
|
|
|
|
|
|
|
|
|
|
|
@ -56,7 +56,6 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public Game()
|
|
|
|
public Game()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bag = CreateTileBag(3);
|
|
|
|
|
|
|
|
board = CreateBoard();
|
|
|
|
board = CreateBoard();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -121,6 +120,12 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
/// <returns>Board</returns>
|
|
|
|
/// <returns>Board</returns>
|
|
|
|
public Board GetBoard() { return board; }
|
|
|
|
public Board GetBoard() { return board; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Returns the tile bag of the game
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
public TileBag GetTileBag() { return bag; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a board with a number of columns and rows
|
|
|
|
/// Creates a board with a number of columns and rows
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -148,6 +153,7 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
public void StartGame()
|
|
|
|
public void StartGame()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (players.Count < 2 || players.Count >= 5) return;
|
|
|
|
if (players.Count < 2 || players.Count >= 5) return;
|
|
|
|
|
|
|
|
bag = CreateTileBag(3);
|
|
|
|
GameRunning = true;
|
|
|
|
GameRunning = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -177,7 +183,7 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (GetPlayingPlayerPosition() == -1)
|
|
|
|
if (GetPlayingPlayerPosition() == -1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new ArgumentException("No player play.");
|
|
|
|
throw new ArgumentException("No player currently playing !");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return players[GetPlayingPlayerPosition()];
|
|
|
|
return players[GetPlayingPlayerPosition()];
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -217,10 +223,13 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (int j = 0; j < 6; j++)
|
|
|
|
for (int j = 0; j < 6; j++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int val = RandomNumberGenerator.GetInt32(0, bag.TilesBag.Count);
|
|
|
|
if (bag != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int val = RandomNumberGenerator.GetInt32(0, bag.TilesBag.Count);
|
|
|
|
|
|
|
|
|
|
|
|
p.AddTileToPlayer(bag.TilesBag[val]);
|
|
|
|
p.AddTileToPlayer(bag.TilesBag[val]);
|
|
|
|
bag.RemoveTileInBag(bag.TilesBag[val]);
|
|
|
|
bag.RemoveTileInBag(bag.TilesBag[val]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -650,7 +659,7 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="playerTilesBagPos"></param>
|
|
|
|
/// <param name="playerTilesBagPos"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
public bool CheckBoardTile(List<int> playerTilesBagPos)
|
|
|
|
public bool CheckPlacementPossibilities(List<int> playerTilesBagPos)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (int i = 0; i < playerTilesBagPos.Count; i++)
|
|
|
|
for (int i = 0; i < playerTilesBagPos.Count; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -682,7 +691,7 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
{
|
|
|
|
{
|
|
|
|
List<int> playerTilesBagPos = CheckTilesBag();
|
|
|
|
List<int> playerTilesBagPos = CheckTilesBag();
|
|
|
|
|
|
|
|
|
|
|
|
if (playerTilesBagPos.Count != 0 && !CheckBoardTile(playerTilesBagPos))
|
|
|
|
if (playerTilesBagPos.Count != 0 && !CheckPlacementPossibilities(playerTilesBagPos))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OnEndOfGame(new EndOfGameNotifiedEventArgs(player));
|
|
|
|
OnEndOfGame(new EndOfGameNotifiedEventArgs(player));
|
|
|
|
GameRunning = false;
|
|
|
|
GameRunning = false;
|
|
|
@ -692,5 +701,15 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void ClearGame()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
players.Clear();
|
|
|
|
|
|
|
|
scoreBoard.Clear();
|
|
|
|
|
|
|
|
cellUsed.Clear();
|
|
|
|
|
|
|
|
bag = null;
|
|
|
|
|
|
|
|
board = CreateBoard();
|
|
|
|
|
|
|
|
GameRunning = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|