|
|
@ -6,11 +6,15 @@ using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Xml.Linq;
|
|
|
|
using System.Xml.Linq;
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
|
|
|
|
|
|
namespace QwirkleClassLibrary
|
|
|
|
namespace QwirkleClassLibrary
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public class Game : IPlayer, IRules
|
|
|
|
public class Game : IPlayer, IRules
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
@ -314,7 +318,58 @@ namespace QwirkleClassLibrary
|
|
|
|
return CheckTilesInLine(this.cellUsed, b, x, y) && 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)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 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[]
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
board.GetCell(cellsPlayed[i].GetX + 1, cellsPlayed[i].GetY),
|
|
|
|
|
|
|
|
board.GetCell(cellsPlayed[i].GetX - 1, cellsPlayed[i].GetY),
|
|
|
|
|
|
|
|
board.GetCell(cellsPlayed[i].GetX, cellsPlayed[i].GetY + 1),
|
|
|
|
|
|
|
|
board.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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else if (cellsPlayed.Contains(cell) != true)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var dx = cell.GetX - cellsPlayed[i].GetX;
|
|
|
|
|
|
|
|
var dy = cell.GetY - cellsPlayed[i].GetY;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int j = 1; j < board.Rows; j++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var extendedCell = board.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 bool IsGameOver()
|
|
|
|
public bool IsGameOver()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|