Beispiel #1
0
        public GameRules.MoveOutcomes applyMove(Move m, GameRules rules) // move must be legal
        {
            // apply the movement
            m.movingPiece.pos = m.ToCoord;
            this.PiecesLayout[m.FromCoord.X, m.FromCoord.Y] = null;
            this.PiecesLayout[m.ToCoord.X, m.ToCoord.Y]     = null;

            // using a single battle function allows for easier customization

            // if a battle took place at all, reveal the pieces
            if (m.movingPiece != null && m.opponentPiece != null)
            {
                m.movingPiece.turnRevealed = TurnNumber;
            }
            if (m.opponentPiece != null)
            {
                m.opponentPiece.turnRevealed = TurnNumber;
            }

            m.outcome = rules.BattleFunction(m.movingPiece, m.opponentPiece);

            switch (m.outcome)
            {
            case GameRules.MoveOutcomes.Move:
                this.PiecesLayout[m.ToCoord.X, m.ToCoord.Y] = m.movingPiece;
                break;

            case GameRules.MoveOutcomes.Win:
                this.PiecesLayout[m.ToCoord.X, m.ToCoord.Y] = m.movingPiece;

                // remove the opponent
                m.opponentPiece.pos = Piece.removedPos;
                PieceSet.Remove(m.opponentPiece);
                break;

            case GameRules.MoveOutcomes.Lose:
                this.PiecesLayout[m.ToCoord.X, m.ToCoord.Y] = m.opponentPiece;

                // remove our piece
                m.movingPiece.pos = Piece.removedPos;
                PieceSet.Remove(m.movingPiece);
                break;

            case GameRules.MoveOutcomes.Tie:
                // remove the opponent
                m.opponentPiece.pos = Piece.removedPos;
                PieceSet.Remove(m.opponentPiece);
                // remove our piece
                m.movingPiece.pos = Piece.removedPos;
                PieceSet.Remove(m.movingPiece);
                break;
            }

            return(m.outcome);
        }