|
|
|
@ -23,7 +23,15 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
|
|
|
|
|
|
private TileBag? bag = null;
|
|
|
|
|
public bool GameRunning { get; private set; }
|
|
|
|
|
private Board? board = null;
|
|
|
|
|
|
|
|
|
|
private Board _board = new Board(15, 12);
|
|
|
|
|
public Board Board
|
|
|
|
|
{
|
|
|
|
|
get { return _board; }
|
|
|
|
|
private set { _board = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ObservableCollection<Cell> GetCellsInBoard => new ObservableCollection<Cell>(Board!.GetCells());
|
|
|
|
|
|
|
|
|
|
public ReadOnlyCollection<Player> PlayerList => players.AsReadOnly();
|
|
|
|
|
private readonly List<Player> players = new();
|
|
|
|
@ -135,10 +143,10 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the board of the game
|
|
|
|
|
/// Returns the Board of the game
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Board</returns>
|
|
|
|
|
public Board? GetBoard() { return board; }
|
|
|
|
|
public Board? GetBoard() { return Board; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the tile bag of the game
|
|
|
|
@ -147,13 +155,13 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
|
public TileBag? GetTileBag() { return bag; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a board with a number of columns and rows
|
|
|
|
|
/// Creates a Board with a number of columns and rows
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Board</returns>
|
|
|
|
|
public Board CreateBoard()
|
|
|
|
|
{
|
|
|
|
|
board = new Board(7, 7);
|
|
|
|
|
return board;
|
|
|
|
|
Board = new Board(15, 12);
|
|
|
|
|
return Board;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -173,7 +181,7 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
|
public void StartGame()
|
|
|
|
|
{
|
|
|
|
|
if (players.Count < 2 || players.Count >= 5) return;
|
|
|
|
|
board = CreateBoard();
|
|
|
|
|
Board = CreateBoard();
|
|
|
|
|
bag = CreateTileBag(3);
|
|
|
|
|
GameRunning = true;
|
|
|
|
|
}
|
|
|
|
@ -293,7 +301,7 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Allows the player to place a tile on the board at a (x, y) position
|
|
|
|
|
/// Allows the player to place a tile on the Board at a (x, y) position
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="player"></param>
|
|
|
|
|
/// <param name="tile"></param>
|
|
|
|
@ -302,11 +310,11 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
|
/// <returns>bool</returns>
|
|
|
|
|
public bool PlaceTile(Player player, Tile tile, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
if (!IsMoveCorrect(tile, x, y, board!)) return false;
|
|
|
|
|
if (board!.AddTileInCell(x, y, tile))
|
|
|
|
|
if (!IsMoveCorrect(tile, x, y, Board!)) return false;
|
|
|
|
|
if (Board!.AddTileInCell(x, y, tile))
|
|
|
|
|
{
|
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, "was correctly placed !"));
|
|
|
|
|
AddCellUsed(board.GetCell(x, y));
|
|
|
|
|
AddCellUsed(Board.GetCell(x, y));
|
|
|
|
|
return player.RemoveTileToPlayer(tile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -689,7 +697,7 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns a boolean to check if the player can play a tile on the board
|
|
|
|
|
/// Returns a boolean to check if the player can play a tile on the Board
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="playerTilesBagPos"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
@ -699,12 +707,12 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < players[playerTilesBagPos[i]].Tiles.Count; j++)
|
|
|
|
|
{
|
|
|
|
|
for (int b = 0; b < board!.ReadCells.Count; b++)
|
|
|
|
|
for (int b = 0; b < Board!.ReadCells.Count; b++)
|
|
|
|
|
{
|
|
|
|
|
int x = board.ReadCells[b].GetX;
|
|
|
|
|
int y = board.ReadCells[b].GetY;
|
|
|
|
|
int x = Board.ReadCells[b].GetX;
|
|
|
|
|
int y = Board.ReadCells[b].GetY;
|
|
|
|
|
|
|
|
|
|
if (IsMoveCorrect(players[playerTilesBagPos[i]].Tiles[j], x, y, board))
|
|
|
|
|
if (IsMoveCorrect(players[playerTilesBagPos[i]].Tiles[j], x, y, Board))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
@ -742,7 +750,7 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
|
scoreBoard.Clear();
|
|
|
|
|
cellUsed.Clear();
|
|
|
|
|
bag = null;
|
|
|
|
|
board = CreateBoard();
|
|
|
|
|
Board = CreateBoard();
|
|
|
|
|
GameRunning = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|