I could be a fucking genius
continuous-integration/drone/push Build is passing Details

test_old_branch
Jules LASCRET 11 months ago
parent ef49b7ea53
commit a86a39cbb1

@ -51,7 +51,6 @@ namespace QwirkleClassLibrary
if (cells[i].IsFree == true) if (cells[i].IsFree == true)
{ {
return cells[i].SetTile(tile); return cells[i].SetTile(tile);
} }
} }
return false; return false;

@ -20,6 +20,9 @@ namespace QwirkleClassLibrary
public ReadOnlyCollection<Score> ScoreList => scores.AsReadOnly(); public ReadOnlyCollection<Score> ScoreList => scores.AsReadOnly();
private readonly List<Score> scores = new(); private readonly List<Score> scores = new();
public ReadOnlyCollection<Cell> CellsUsed => cellUsed.AsReadOnly();
private readonly List<Cell> cellUsed = new();
public Game() public Game()
{ {
@ -80,6 +83,16 @@ namespace QwirkleClassLibrary
return true; return true;
} }
public void AddCellUsed(Cell? c)
{
if (c != null) cellUsed.Add(c);
}
public void EmptyCellUsed()
{
cellUsed.Clear();
}
public Player GetPlayingPlayer() public Player GetPlayingPlayer()
{ {
if(GetPlayingPlayerPosition() == -1) if(GetPlayingPlayerPosition() == -1)
@ -163,7 +176,7 @@ namespace QwirkleClassLibrary
/// <summary> /// <summary>
/// /// Allows a player to draw tiles from the bag as soon as he has less than 6 tiles
/// </summary> /// </summary>
/// <param name="player"></param> /// <param name="player"></param>
/// <returns></returns> /// <returns></returns>
@ -238,6 +251,30 @@ namespace QwirkleClassLibrary
return true; 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) public bool IsMoveCorrect(Tile t, int x, int y, Board b)
{ {
if (!b.HasOccupiedCase()) if (!b.HasOccupiedCase())
@ -274,8 +311,8 @@ namespace QwirkleClassLibrary
} }
} }
return surroundingCells.Any(cell => cell?.GetTile != null); return CheckTilesInLine(this.cellUsed, b, x, y) && surroundingCells.Any(cell => cell?.GetTile != null);
} }
public bool IsGameOver() public bool IsGameOver()

@ -16,6 +16,8 @@ namespace QwirkleClassLibrary
bool CheckExtendedSurroundingCells(Tile tile, int x, int y, int dx, int dy, Board b); bool CheckExtendedSurroundingCells(Tile tile, int x, int y, int dx, int dy, Board b);
bool CheckTilesInLine(List<Cell> cells, Board b, int x, int y);
bool IsGameOver(); bool IsGameOver();
} }
} }

@ -76,6 +76,7 @@ static void AddTile(Game game)
if (game.PlaceTile(game.GetPlayingPlayer(), tile, x, y) == true) if (game.PlaceTile(game.GetPlayingPlayer(), tile, x, y) == true)
{ {
WriteLine("ok ! your tile is placed"); WriteLine("ok ! your tile is placed");
game.AddCellUsed(game.GetBoard().GetCell(x, y));
} }
else else
{ {
@ -149,6 +150,7 @@ static void MenuSwitch(Game game)
enter = 3; enter = 3;
break; break;
case 3: case 3:
game.EmptyCellUsed();
return; return;
} }
} }

Loading…
Cancel
Save