public void SetAllAdjacent(Cell above, Cell right, Cell below, Cell left) { this._adjacent[(int) Touching.Above] = above; this._adjacent[(int) Touching.Right] = right; this._adjacent[(int) Touching.Below] = below; this._adjacent[(int) Touching.Left] = left; }
public void CanRemoveCellPiece() { var cell = new Cell(); var piece = new Piece("Orange", Army.Rank.Scout); Assert.AreEqual(Cell.State.Empty, cell.GetState()); cell.SetPiece(piece); Assert.AreEqual(Cell.State.Occupied, cell.GetState()); cell.RemovePiece(); Assert.AreEqual(Cell.State.Empty, cell.GetState()); }
public void CanSetCellPiece() { var cell = new Cell("Test"); var piece = new Piece("Green", Army.Rank.Major); Assert.AreEqual(Cell.State.Empty, cell.GetState()); cell.SetPiece(piece); Assert.AreEqual(Cell.State.Occupied, cell.GetState()); Assert.AreEqual(piece, cell.GetPiece()); Assert.AreEqual("Green", cell.GetPiece().GetColor()); }
private void InstantiateCells() { for (int i = 0; i < 10; i++) for (int j = 1; j <= 10; j++) { string name = col[i] + j.ToString(); _cells.Add(name, new Cell(name)); } foreach (var lake in lakeCells) _cells[lake] = new Cell(lake, Cell.State.Invalid); _cells.Add(OutOfBounds, new Cell(OutOfBounds, Cell.State.Invalid)); }
public void Move(Cell source, Cell destination) { if (!source.IsOccupied() || !_gameMover.GetValidMoves(source).Contains(destination)) return; if (destination.GetState() == Cell.State.Empty) destination.SetPiece(source.GetPiece()); else { int winner = Attack((int) source.GetPieceRank(), (int) destination.GetPieceRank()); if (winner == 1) destination.SetPiece(source.GetPiece()); if (winner == 0) destination.RemovePiece(); } source.RemovePiece(); }
public List<Cell> GetValidMoves(Cell source) { if (source.GetPiece() == null) throw new NullPieceCannotMoveException(); _cellToMove = source; var piece = source.GetPiece(); int range = _gametype.GetPieceMoveRule(piece); var moves = new List<Cell>(); moves.AddRange(GetMovesForARangeInDirection(source, range, Cell.Touching.Above)); moves.AddRange(GetMovesForARangeInDirection(source, range, Cell.Touching.Right)); moves.AddRange(GetMovesForARangeInDirection(source, range, Cell.Touching.Below)); moves.AddRange(GetMovesForARangeInDirection(source, range, Cell.Touching.Left)); return moves; }
private List<Cell> GetMovesForARangeInDirection(Cell source, int range, Cell.Touching direction) { var moves = new List<Cell>(); if (range == 0) return moves; if (source.GetAdjacent(direction).GetState() == Cell.State.Empty) { moves.Add(source.GetAdjacent(direction)); moves.AddRange(GetMovesForARangeInDirection(source.GetAdjacent(direction), --range, direction)); } else if (source.GetAdjacent(direction).GetState() == Cell.State.Occupied && _cellToMove.GetPieceColor() != source.GetAdjacent(direction).GetPieceColor()) { moves.Add(source.GetAdjacent(direction)); } return moves; }
public void CellCanGetPieceRank() { var cell = new Cell("Test"); var piece = new Piece("Blue", Army.Rank.Bomb); cell.SetPiece(piece); Army.Rank? cellPieceRank = cell.GetPieceRank(); Assert.AreEqual(Army.Rank.Bomb, cellPieceRank); }
public void CellCanGetPieceColor() { var cell = new Cell("Test"); var piece = new Piece("Blue", Army.Rank.Bomb); cell.SetPiece(piece); Assert.AreEqual("Blue", cell.GetPieceColor()); }
private void Adjacent(Cell source, Cell above, Cell right, Cell below, Cell left) { Assert.AreEqual(above, source.GetAdjacent(Cell.Touching.Above)); Assert.AreEqual(right, source.GetAdjacent(Cell.Touching.Right)); Assert.AreEqual(below, source.GetAdjacent(Cell.Touching.Below)); Assert.AreEqual(left, source.GetAdjacent(Cell.Touching.Left)); }