Tile.cs 1.1 KB

1234567891011121314151617181920212223242526272829
  1. using System;
  2. namespace DevilLink2.Core
  3. {
  4. /// <summary>Immutable tile identity with board-controlled location. IDs are unique within a board.</summary>
  5. public sealed class Tile
  6. {
  7. internal Board Owner { get; set; }
  8. public int Id { get; }
  9. public TileSymbol Symbol { get; }
  10. public int Row { get; private set; }
  11. public int Column { get; private set; }
  12. public GridPosition Position => new GridPosition(Row, Column);
  13. internal void SetPosition(int row, int column)
  14. {
  15. Row = row; Column = column;
  16. }
  17. public Tile(int id, TileSymbol symbol, int row, int column)
  18. {
  19. if (id <= 0) throw new ArgumentOutOfRangeException(nameof(id));
  20. if (!Enum.IsDefined(typeof(TileSymbol), symbol)) throw new ArgumentOutOfRangeException(nameof(symbol));
  21. if (row < 0) throw new ArgumentOutOfRangeException(nameof(row));
  22. if (column < 0) throw new ArgumentOutOfRangeException(nameof(column));
  23. Id = id; Symbol = symbol; Row = row; Column = column;
  24. }
  25. }
  26. }