diff --git a/Qwirkle/QwirkleClassLibrary/Boards/Board.cs b/Qwirkle/QwirkleClassLibrary/Boards/Board.cs index 7b50f3d..2af84a5 100644 --- a/Qwirkle/QwirkleClassLibrary/Boards/Board.cs +++ b/Qwirkle/QwirkleClassLibrary/Boards/Board.cs @@ -46,14 +46,15 @@ namespace QwirkleClassLibrary.Boards public bool AddTileInCell(int x, int y, Tile tile) { - for (int i = 0; i < cells.Count; i++) + foreach (var t in cells) { - if (cells[i].GetX != x || cells[i].GetY != y) continue; - if (cells[i].IsFree) + if (t.GetX != x || t.GetY != y) continue; + if (t.IsFree) { - return cells[i].SetTile(tile); + return t.SetTile(tile); } } + return false; } @@ -69,13 +70,14 @@ namespace QwirkleClassLibrary.Boards public Cell? GetCell(int x, int y) { - for (int i = 0; i < cells.Count; i++) + foreach (var t in cells) { - if (cells[i].GetX == x && cells[i].GetY == y) + if (t.GetX == x && t.GetY == y) { - return cells[i]; + return t; } } + return null; } } diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index bdbff33..e622436 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -107,7 +107,7 @@ namespace QwirkleClassLibrary.Games public Board CreateBoard() { - board = new Board(8, 8); + board = new Board(15, 12); return board; } @@ -117,11 +117,10 @@ namespace QwirkleClassLibrary.Games return bag; } - public bool StartGame() + public void StartGame() { - if (players.Count < 2 || players.Count >= 5) return false; + if (players.Count < 2 || players.Count >= 5) return; GameRunning = true; - return true; } public void AddCellUsed(Cell? c) @@ -430,11 +429,8 @@ namespace QwirkleClassLibrary.Games cellsY = -1; } } - - foreach (var cell in cellsPlayed) - { - score += CalculateAdjacentScore(cell, b, cellsPlayed, cellsX, cellsY); - } + + score += cellsPlayed.Sum(cell => CalculateAdjacentScore(cell, b, cellsPlayed, cellsX, cellsY)); if (!scoreBoard.TryAdd(player, score)) diff --git a/Qwirkle/QwirkleConsoleApp/Program.cs b/Qwirkle/QwirkleConsoleApp/Program.cs index d24d141..494b9eb 100644 --- a/Qwirkle/QwirkleConsoleApp/Program.cs +++ b/Qwirkle/QwirkleConsoleApp/Program.cs @@ -226,12 +226,14 @@ static void ShowBoard(Game game) { for (int y = 0; y < board.Columns; y++) { - if (board.GetCell(y, i)!.IsFree == false) + Cell? cell = board.GetCell(y, i); + if (cell != null && cell.IsFree == false) { - Tile? tile = board.GetCell(y, i)?.GetTile; + Tile? tile = cell.GetTile; if (tile != null) { - 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 @@ -239,6 +241,7 @@ static void ShowBoard(Game game) Console.Write("| |"); } } + Console.WriteLine(); } }