|
|
@ -13,8 +13,8 @@ namespace QwirkleClassLibrary
|
|
|
|
|
|
|
|
|
|
|
|
public class Game : IPlayer, IRules
|
|
|
|
public class Game : IPlayer, IRules
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
private Dictionary<Player, int> scoreBoard = new();
|
|
|
|
public Dictionary<Player, int> ScoreBoard = new();
|
|
|
|
|
|
|
|
private TileBag bag;
|
|
|
|
private TileBag bag;
|
|
|
|
public bool GameRunning { get; private set; }
|
|
|
|
public bool GameRunning { get; private set; }
|
|
|
|
private Board board;
|
|
|
|
private Board board;
|
|
|
@ -49,13 +49,13 @@ namespace QwirkleClassLibrary
|
|
|
|
|
|
|
|
|
|
|
|
public bool AddPlayerInGame(string? playerTag)
|
|
|
|
public bool AddPlayerInGame(string? playerTag)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(playerTag) == true)
|
|
|
|
if (string.IsNullOrWhiteSpace(playerTag))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : The name is null or white space."));
|
|
|
|
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : The name is null or white space."));
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(this.GameRunning == true)
|
|
|
|
if(this.GameRunning)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : The game is running."));
|
|
|
|
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : The game is running."));
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -134,7 +134,7 @@ namespace QwirkleClassLibrary
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (int i = 0; i < players.Count; i++)
|
|
|
|
for (int i = 0; i < players.Count; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (players[i].IsPlaying == true)
|
|
|
|
if (players[i].IsPlaying)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -163,7 +163,7 @@ namespace QwirkleClassLibrary
|
|
|
|
|
|
|
|
|
|
|
|
public string SetFirstPlayer()
|
|
|
|
public string SetFirstPlayer()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (GameRunning == true)
|
|
|
|
if (GameRunning)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
players[0].IsPlaying = true;
|
|
|
|
players[0].IsPlaying = true;
|
|
|
|
//OnNextPlayer(new NextPlayerNotifiedEventArgs(players[0]));
|
|
|
|
//OnNextPlayer(new NextPlayerNotifiedEventArgs(players[0]));
|
|
|
@ -194,9 +194,9 @@ namespace QwirkleClassLibrary
|
|
|
|
|
|
|
|
|
|
|
|
public bool PlaceTile(Player player, Tile tile, int x, int y)
|
|
|
|
public bool PlaceTile(Player player, Tile tile, int x, int y)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (board.AddTileInCell(x, y, tile) == true)
|
|
|
|
if (board.AddTileInCell(x, y, tile))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return player.RemoveTileToPlayer(tile) == true;
|
|
|
|
return player.RemoveTileToPlayer(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -269,13 +269,13 @@ namespace QwirkleClassLibrary
|
|
|
|
|
|
|
|
|
|
|
|
if (extendedCell.GetTile.GetColor != tile.GetColor && extendedCell.GetTile.GetShape != tile.GetShape)
|
|
|
|
if (extendedCell.GetTile.GetColor != tile.GetColor && extendedCell.GetTile.GetShape != tile.GetShape)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, "Les couleurs/formes adjacentes ne correspondes pas"));
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, "Color / Shape does not match with the surrounding tiles !"));
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (i == 6)
|
|
|
|
if (i == 6)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, "La ligne ou colonne fait deja 6 tuiles !"));
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, "Row/Column already 6 tiles long !"));
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -311,10 +311,10 @@ namespace QwirkleClassLibrary
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!b.HasOccupiedCase())
|
|
|
|
if (!b.HasOccupiedCase())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (this.PlaceTile(this.GetPlayingPlayer(), t, x, y) == true)
|
|
|
|
if (this.PlaceTile(this.GetPlayingPlayer(), t, x, y))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.AddCellUsed(this.GetBoard().GetCell(x, y));
|
|
|
|
this.AddCellUsed(this.GetBoard().GetCell(x, y));
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, "Tile correctement placé"));
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, "Tile correctly placed"));
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -342,16 +342,13 @@ namespace QwirkleClassLibrary
|
|
|
|
|
|
|
|
|
|
|
|
var dx = cell.GetX - x;
|
|
|
|
var dx = cell.GetX - x;
|
|
|
|
var dy = cell.GetY - y;
|
|
|
|
var dy = cell.GetY - y;
|
|
|
|
|
|
|
|
|
|
|
|
if (CheckExtendedSurroundingCells(t, x, y, dx, dy, b) == false)
|
|
|
|
return CheckExtendedSurroundingCells(t, x, y, dx, dy, b);
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (CheckTilesInLine(this.cellUsed, b, x, y) && surroundingCells.Any(cell => cell?.GetTile != null))
|
|
|
|
if (CheckTilesInLine(this.cellUsed, b, x, y) && surroundingCells.Any(cell => cell?.GetTile != null))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(this.PlaceTile(this.GetPlayingPlayer(), t, x, y) == true)
|
|
|
|
if(this.PlaceTile(this.GetPlayingPlayer(), t, x, y))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.AddCellUsed(this.GetBoard().GetCell(x, y));
|
|
|
|
this.AddCellUsed(this.GetBoard().GetCell(x, y));
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, "Tile correctement placé"));
|
|
|
|
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, "Tile correctement placé"));
|
|
|
@ -363,57 +360,6 @@ namespace QwirkleClassLibrary
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// public int GetPlayerScore(Player player, List<Cell> cellsPlayed, Board b)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// // Compte le nombre de tuiles et ajoute ce nombre au score
|
|
|
|
|
|
|
|
// int score = cellsPlayed.Count;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // Check les lignes / colonnes adjacentes aux tuiles placées
|
|
|
|
|
|
|
|
// for(int i= 0; i < cellsPlayed.Count; i++)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// // A chaque tour, crée la liste des 4 cellules adjacentes à la cellule sélectionnée
|
|
|
|
|
|
|
|
// var surroundingCells = new[]
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// b.GetCell(cellsPlayed[i].GetX + 1, cellsPlayed[i].GetY),
|
|
|
|
|
|
|
|
// b.GetCell(cellsPlayed[i].GetX - 1, cellsPlayed[i].GetY),
|
|
|
|
|
|
|
|
// b.GetCell(cellsPlayed[i].GetX, cellsPlayed[i].GetY + 1),
|
|
|
|
|
|
|
|
// b.GetCell(cellsPlayed[i].GetX, cellsPlayed[i].GetY - 1)
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // Parcourt le tableau dans la direction par rapport à ces cellules adjacentes
|
|
|
|
|
|
|
|
// foreach (var cell in surroundingCells)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// // Si la cellule adjacente ne contient pas de tuile, on passe à la cellule adjacente suivante
|
|
|
|
|
|
|
|
// if (cell?.GetTile == null) break;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (cellsPlayed.Contains(cell) != true)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// var dx = cell.GetX - cellsPlayed[i].GetX;
|
|
|
|
|
|
|
|
// var dy = cell.GetY - cellsPlayed[i].GetY;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// for (int j = 1; j < b.Rows; j++)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// var extendedCell = b.GetCell(cellsPlayed[i].GetX + j * dx, cellsPlayed[i].GetY + j * dy);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (extendedCell?.GetTile == null)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// score += 1;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// ScoreBoard.Add(player, score);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// return score;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int GetPlayerScore(Player player, ReadOnlyCollection<Cell> cellsPlayed, Board b)
|
|
|
|
public int GetPlayerScore(Player player, ReadOnlyCollection<Cell> cellsPlayed, Board b)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int score = cellsPlayed.Count;
|
|
|
|
int score = cellsPlayed.Count;
|
|
|
@ -424,9 +370,9 @@ namespace QwirkleClassLibrary
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ScoreBoard.TryAdd(player, score) == false)
|
|
|
|
if(scoreBoard.TryAdd(player, score) == false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ScoreBoard[player] += score;
|
|
|
|
scoreBoard[player] += score;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return score;
|
|
|
|
return score;
|
|
|
|