using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace QwirkleClassLibrary { 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 == false) { return true; } } return false; } public bool AddTileInCell(int x, int y, Tile tile) { for (int i = 0; i < cells.Count; i++) { if (this.cells[i].GetX != x || this.cells[i].GetY != y) continue; if (cells[i].IsFree == true) { 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 (this.cells[i].GetX == x && this.cells[i].GetY == y) { return cells[i]; } } return null; } } }