|
|
|
@ -25,6 +25,9 @@ namespace QwirkleClassLibrary
|
|
|
|
|
public ReadOnlyCollection<Score> ScoreList => scores.AsReadOnly();
|
|
|
|
|
private readonly List<Score> scores = new();
|
|
|
|
|
|
|
|
|
|
public ReadOnlyCollection<Cell> CellsUsed => cellUsed.AsReadOnly();
|
|
|
|
|
private readonly List<Cell> cellUsed = new();
|
|
|
|
|
|
|
|
|
|
public Game()
|
|
|
|
|
{
|
|
|
|
|
bag = CreateTileBag(3);
|
|
|
|
@ -84,6 +87,16 @@ namespace QwirkleClassLibrary
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddCellUsed(Cell? c)
|
|
|
|
|
{
|
|
|
|
|
if (c != null) cellUsed.Add(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EmptyCellUsed()
|
|
|
|
|
{
|
|
|
|
|
cellUsed.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Player GetPlayingPlayer()
|
|
|
|
|
{
|
|
|
|
|
if(GetPlayingPlayerPosition() == -1)
|
|
|
|
@ -165,6 +178,12 @@ namespace QwirkleClassLibrary
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Allows a player to draw tiles from the bag as soon as he has less than 6 tiles
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="player"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool DrawTiles(Player player)
|
|
|
|
|
{
|
|
|
|
|
while(player.Tiles.Count < 6)
|
|
|
|
@ -211,6 +230,55 @@ namespace QwirkleClassLibrary
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CheckExtendedSurroundingCells(Tile tile, int x, int y, int dx, int dy, Board b)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 1; i < 7; i++)
|
|
|
|
|
{
|
|
|
|
|
var extendedCell = b.GetCell(x + i * dx, y + i * dy);
|
|
|
|
|
|
|
|
|
|
if (extendedCell?.GetTile == null)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (extendedCell.GetTile.GetColor != tile.GetColor && extendedCell.GetTile.GetShape != tile.GetShape)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i == 6)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CheckTilesInLine(List<Cell> cells, Board b, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
if(cells.Count < 2)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var x1 = cells[0].GetX;
|
|
|
|
|
var y1 = cells[0].GetY;
|
|
|
|
|
var x2 = cells[1].GetX;
|
|
|
|
|
var y2 = cells[1].GetY;
|
|
|
|
|
|
|
|
|
|
if (x1 == x2)
|
|
|
|
|
{
|
|
|
|
|
return x == x1;
|
|
|
|
|
}
|
|
|
|
|
if (y1 == y2)
|
|
|
|
|
{
|
|
|
|
|
return y == y1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsMoveCorrect(Tile t, int x, int y, Board b)
|
|
|
|
|
{
|
|
|
|
|
if (!b.HasOccupiedCase())
|
|
|
|
@ -218,7 +286,7 @@ namespace QwirkleClassLibrary
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var surroundingCells = new[]
|
|
|
|
|
var surroundingCells = new List<Cell?>
|
|
|
|
|
{
|
|
|
|
|
b.GetCell(x + 1, y),
|
|
|
|
|
b.GetCell(x - 1, y),
|
|
|
|
@ -241,28 +309,13 @@ namespace QwirkleClassLibrary
|
|
|
|
|
var dx = cell.GetX - x;
|
|
|
|
|
var dy = cell.GetY - y;
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < 7; i++)
|
|
|
|
|
{
|
|
|
|
|
var extendedCell = b.GetCell(x + i * dx, y + i * dy);
|
|
|
|
|
|
|
|
|
|
if (extendedCell?.GetTile == null)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (extendedCell.GetTile.GetColor != t.GetColor && extendedCell.GetTile.GetShape != t.GetShape)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i == 6)
|
|
|
|
|
if (CheckExtendedSurroundingCells(t, x, y, dx, dy, b) == false)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return surroundingCells.Any(cell => cell?.GetTile != null);
|
|
|
|
|
return CheckTilesInLine(this.cellUsed, b, x, y) && surroundingCells.Any(cell => cell?.GetTile != null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetPlayerScore(Player player, List<Cell> cellsPlayed, Board board)
|
|
|
|
@ -319,7 +372,7 @@ namespace QwirkleClassLibrary
|
|
|
|
|
|
|
|
|
|
public bool IsGameOver()
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|