added some ground rules for the tile placement
continuous-integration/drone/push Build is passing Details

test_old_branch
Jules LASCRET 12 months ago
parent 69d6d2f9d3
commit 26c5d7395c

@ -23,7 +23,7 @@ namespace QwirkleClassLibrary
public Game() public Game()
{ {
bag = CreateTileBag(1); bag = CreateTileBag(3);
board = CreateBoard(); board = CreateBoard();
} }
@ -48,7 +48,7 @@ namespace QwirkleClassLibrary
} }
players.Add(CreatePlayer(playerTag)); players.Add(CreatePlayer(playerTag));
scores.Add(new Score(players[players.Count-1])); scores.Add(new Score(players[players.Count - 1]));
return true; return true;
} }
@ -63,7 +63,7 @@ namespace QwirkleClassLibrary
public Board CreateBoard() public Board CreateBoard()
{ {
board = new Board(5, 5); board = new Board(8, 8);
return board; return board;
} }
@ -214,28 +214,90 @@ namespace QwirkleClassLibrary
return true; return true;
} }
var surroundingTiles = new List<Tile?>(); var surroundingCells = new List<Cell?>();
surroundingTiles.Add(b.GetCell(x + 1, y)?.GetTile); surroundingCells.Add(b.GetCell(x + 1, y));
surroundingTiles.Add(b.GetCell(x - 1, y)?.GetTile); surroundingCells.Add(b.GetCell(x - 1, y));
surroundingTiles.Add(b.GetCell(x, y + 1)?.GetTile); surroundingCells.Add(b.GetCell(x, y + 1));
surroundingTiles.Add(b.GetCell(x, y - 1)?.GetTile); surroundingCells.Add(b.GetCell(x, y - 1));
foreach (var tile in surroundingTiles.ToList()) foreach (var cell in surroundingCells.ToList())
{ {
if (tile == null) if (cell?.GetTile == null)
{ {
surroundingTiles.Remove(tile); surroundingCells.Remove(cell);
continue; continue;
} }
if (tile.GetColor != t.GetColor && tile.GetShape != t.GetShape) if (cell?.GetTile.GetColor != t.GetColor && cell?.GetTile.GetShape != t.GetShape)
{ {
return false; return false;
} }
} }
if(surroundingTiles.Count == 0) return false; if(surroundingCells.Count == 0) return false;
foreach (var cell in surroundingCells.ToList())
{
var extendedCells = new List<Cell?>();
if (cell?.GetX == x && cell?.GetY == y + 1)
{
for (int i = 1; i < 7; i++)
{
if (b.GetCell(x, y + i)?.GetTile != null)
{
extendedCells.Add(b.GetCell(x, y + i));
}
}
}
else if (cell?.GetX == x && cell?.GetY == y - 1)
{
for (int i = 1; i < 7; i++)
{
if (b.GetCell(x, y - i)?.GetTile != null)
{
extendedCells.Add(b.GetCell(x, y - i));
}
}
}
else if (cell?.GetX == x + 1 && cell?.GetY == y)
{
for (int i = 1; i < 7; i++)
{
if (b.GetCell(x + i, y)?.GetTile != null)
{
extendedCells.Add(b.GetCell(x + i, y));
}
}
}
else if (cell?.GetX == x - 1 && cell?.GetY == y)
{
for (int i = 1; i < 7; i++)
{
if (b.GetCell(x - i, y)?.GetTile != null)
{
extendedCells.Add(b.GetCell(x - i, y));
}
}
}
foreach (var e in extendedCells)
{
if (e?.GetTile?.GetColor != t.GetColor && e?.GetTile?.GetShape != t.GetShape)
{
return false;
}
}
if (extendedCells.Count == 6)
{
return false;
}
}
return true; return true;
} }

@ -159,13 +159,13 @@ static void ShowBoard(Game game)
Board board = game.GetBoard(); Board board = game.GetBoard();
List<Cell> cells = board.GetCells(); List<Cell> cells = board.GetCells();
for(int i=0; i<board.Rows; i++) for(int i = 0; i<board.Rows; i++)
{ {
for(int y=0; y<board.Columns; y++) for(int y = 0; y<board.Columns; y++)
{ {
if(board.GetCell(i, y)!.IsFree == false) if(board.GetCell(y, i)!.IsFree == false)
{ {
Tile? tile = board.GetCell(i, y)?.GetTile; Tile? tile = board.GetCell(y, i)?.GetTile;
Console.Write("| " + tile.GetShape.ToString()[0] + tile.GetShape.ToString()[1] + tile.GetColor.ToString()[0] + " |"); Console.Write("| " + tile.GetShape.ToString()[0] + tile.GetShape.ToString()[1] + tile.GetColor.ToString()[0] + " |");
} }
else else
@ -195,7 +195,7 @@ static void MainMenu(Game game)
game.DrawTiles(game.GetPlayingPlayer()); game.DrawTiles(game.GetPlayingPlayer());
MenuSwitch(game); MenuSwitch(game);
} while (game.GetPlayingPlayerPosition() != game.PlayerList.Count - 1); } while (true); //while (game.GetPlayingPlayerPosition() != game.PlayerList.Count - 1);
} }
static void MainGame() static void MainGame()

Loading…
Cancel
Save