using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using QwirkleClassLibrary.Tiles; namespace QwirkleClassLibrary.Boards { public class Board { public ReadOnlyCollection ReadCells => cells.AsReadOnly(); private readonly List cells = new(); public int Rows { get; } public int Columns { get; } public Board(int rows, int cols) { Rows = rows; Columns = cols; for (int a = 0; a < Rows; a++) { for (int b = 0; b < Columns; b++) { Cell localcell = new(a, b); cells.Add(localcell); } } } public bool HasOccupiedCase() { foreach (var cell in cells) { if (!cell.IsFree) { return true; } } return false; } public bool AddTileInCell(int x, int y, Tile tile) { for (int i = 0; i < cells.Count; i++) { if (cells[i].GetX != x || cells[i].GetY != y) continue; if (cells[i].IsFree) { return cells[i].SetTile(tile); } } return false; } public List GetCells() { return cells; } public IReadOnlyCollection GetReadCells() { return ReadCells; } public Cell? GetCell(int x, int y) { for (int i = 0; i < cells.Count; i++) { if (cells[i].GetX == x && cells[i].GetY == y) { return cells[i]; } } return null; } } }