Esempio n. 1
0
 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());
 }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        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;
        }