|
|
|
@ -194,14 +194,16 @@ namespace QwirkleClassLibrary
|
|
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
{
|
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, "was correctly placed !"));
|
|
|
|
|
AddCellUsed(board.GetCell(x, y));
|
|
|
|
|
return player.RemoveTileToPlayer(tile);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, " : Cell already used"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -256,39 +258,6 @@ 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)
|
|
|
|
|
{
|
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, "Color / Shape does not match with the surrounding tiles !"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i == 6)
|
|
|
|
|
{
|
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, "Row/Column already 6 tiles long !"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.PlaceTile(this.GetPlayingPlayer(), tile, x, y))
|
|
|
|
|
{
|
|
|
|
|
this.AddCellUsed(this.GetBoard().GetCell(x, y));
|
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, "Tile correctement placé"));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
public bool CheckExtendedSurroundingCells(Tile tile, int x, int y, int dx, int dy, Board b)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 1; i < 7; i++)
|
|
|
|
@ -302,11 +271,19 @@ namespace QwirkleClassLibrary
|
|
|
|
|
|
|
|
|
|
if (extendedCell.GetTile.GetColor != tile.GetColor && extendedCell.GetTile.GetShape != tile.GetShape)
|
|
|
|
|
{
|
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, " : Color / Shape does not match with the surrounding tiles !"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(extendedCell.GetTile.GetColor == tile.GetColor && extendedCell.GetTile.GetShape == tile.GetShape)
|
|
|
|
|
{
|
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, " : Tile already placed on the same line / column !"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i == 6)
|
|
|
|
|
{
|
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, " : Row/Column already are 6 tiles long !"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -316,13 +293,24 @@ namespace QwirkleClassLibrary
|
|
|
|
|
|
|
|
|
|
public bool CheckTilesInLine(List<Cell> cells, Board b, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
if(cells.Count < 2)
|
|
|
|
|
if(cells.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var x1 = cells[0].GetX;
|
|
|
|
|
var y1 = cells[0].GetY;
|
|
|
|
|
|
|
|
|
|
if(cells.Count < 2 && (x1 == x || y1 == y))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (x1 != x && y1 != y)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var x2 = cells[1].GetX;
|
|
|
|
|
var y2 = cells[1].GetY;
|
|
|
|
|
|
|
|
|
@ -334,15 +322,15 @@ namespace QwirkleClassLibrary
|
|
|
|
|
{
|
|
|
|
|
return y == y1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*public bool IsMoveCorrect(Tile t, int x, int y, Board b)
|
|
|
|
|
public bool IsMoveCorrect(Tile t, int x, int y, Board b)
|
|
|
|
|
{
|
|
|
|
|
if (!b.HasOccupiedCase())
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var surroundingCells = new List<Cell?>
|
|
|
|
@ -359,57 +347,17 @@ namespace QwirkleClassLibrary
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cell.GetTile.GetColor != t.GetColor && cell.GetTile.GetShape != t.GetShape)
|
|
|
|
|
{
|
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, "Tile ne correspond pas au bonne couleur des tiles a coté"));
|
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : Colors / Shapes do not match with the surrounding tiles !"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var dx = cell.GetX - x;
|
|
|
|
|
var dy = cell.GetY - y;
|
|
|
|
|
|
|
|
|
|
return CheckExtendedSurroundingCells(t, x, y, dx, dy, b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CheckTilesInLine(this.cellUsed, b, x, y) && surroundingCells.Any(cell => cell?.GetTile != null))
|
|
|
|
|
{
|
|
|
|
|
if(this.PlaceTile(this.GetPlayingPlayer(), t, x, y))
|
|
|
|
|
{
|
|
|
|
|
this.AddCellUsed(this.GetBoard().GetCell(x, y));
|
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, "Tile correctement placé"));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, "Cell Already use"));
|
|
|
|
|
}
|
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, "La tuile n'a pu etre placé"));
|
|
|
|
|
return false;
|
|
|
|
|
} */
|
|
|
|
|
|
|
|
|
|
public bool IsMoveCorrect(Tile t, int x, int y, Board b)
|
|
|
|
|
{
|
|
|
|
|
if (!b.HasOccupiedCase())
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var surroundingCells = new List<Cell?>
|
|
|
|
|
{
|
|
|
|
|
b.GetCell(x + 1, y),
|
|
|
|
|
b.GetCell(x - 1, y),
|
|
|
|
|
b.GetCell(x, y + 1),
|
|
|
|
|
b.GetCell(x, y - 1)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
foreach (var cell in surroundingCells)
|
|
|
|
|
{
|
|
|
|
|
if (cell?.GetTile == null)
|
|
|
|
|
if (cell.GetTile.GetColor == t.GetColor && cell.GetTile.GetShape == t.GetShape)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : Tile already placed on the same line / column !"));
|
|
|
|
|
|
|
|
|
|
if (cell.GetTile.GetColor != t.GetColor && cell.GetTile.GetShape != t.GetShape)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -422,7 +370,13 @@ namespace QwirkleClassLibrary
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return CheckTilesInLine(this.cellUsed, b, x, y) && surroundingCells.Any(cell => cell?.GetTile != null);
|
|
|
|
|
if (CheckTilesInLine(cellUsed, b, x, y) == false)
|
|
|
|
|
{
|
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, "isn't on the same line as the ones previously placed !"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return surroundingCells.Any(cell => cell?.GetTile != null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetPlayerScore(Player player, ReadOnlyCollection<Cell> cellsPlayed, Board b)
|
|
|
|
@ -490,7 +444,6 @@ namespace QwirkleClassLibrary
|
|
|
|
|
return score;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsGameOver()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|