You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.0 KiB
83 lines
2.0 KiB
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<Cell> ReadCells => cells.AsReadOnly();
|
|
private readonly List<Cell> 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<Cell> GetCells()
|
|
{
|
|
return cells;
|
|
}
|
|
|
|
public IReadOnlyCollection<Cell> 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;
|
|
}
|
|
}
|
|
}
|