Initial commit
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
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}]";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user