36 lines
1.3 KiB
C#
36 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace GameOfLife.Entities
|
|
{
|
|
public class Cell : Tuple<short, short>
|
|
{
|
|
public Cell(short x, short y) : base(x, y)
|
|
{
|
|
}
|
|
public Cell(short x, int y) : base(x, (short)y) { }
|
|
public Cell(int x, short y) : base((short)x, y) { }
|
|
public Cell(int x, int y) : base((short)x, (short)y) { }
|
|
|
|
public static Cell operator +(Cell cell1, Cell cell2)
|
|
=> new Cell(cell1.Item1 + cell2.Item1, cell1.Item2 + cell2.Item2);
|
|
|
|
public static Cell operator -(Cell cell1, Cell cell2)
|
|
=> new Cell(cell1.Item1 - cell2.Item1, cell1.Item2 - cell2.Item2);
|
|
|
|
public Cell Negate()
|
|
=> new Cell(-Item1, -Item2);
|
|
|
|
public IEnumerable<Cell> NeighborCells => new []
|
|
{
|
|
new Cell(Item1 - 1, Item2 - 1), new Cell(Item1 - 1, Item2), new Cell(Item1 - 1, Item2 + 1),
|
|
new Cell(Item1, Item2 - 1), new Cell(Item1, Item2 + 1),
|
|
new Cell(Item1 + 1, Item2 - 1), new Cell(Item1 + 1, Item2), new Cell(Item1 + 1, Item2 + 1),
|
|
};
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"[{Item1}, {Item2}]";
|
|
}
|
|
}
|
|
} |