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()); }
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; }