示例#1
0
        public static GameStatus CreateForMove(GameStatus status, GameMove move, GameMoveResultType result, Token attacker, Token defender)
        {
            var active = !result.IsGameOver();
            var winner = result.GetWinner(status.CurrentPlayer, status.OtherPlayer);
            
            // switch current player
            var currentPlayer = status.OtherPlayer;
            var otherPlayer = status.CurrentPlayer;

            return new GameStatus(currentPlayer, otherPlayer, winner, active, move, result, attacker, defender);
        }
示例#2
0
 public Game(long id,
             Player player1,
             Player player2,
             GameStatus gameStatus,
             GameBoard gameBoard)
 {
     this.ID = id;
     this.Player1 = player1;
     this.Player2 = player2;
     this.GameStatus = gameStatus;
     this.GameBoard = gameBoard;
 }
示例#3
0
        public void MoveToken(GameMove move)
        {
            Token token  = move.Token;
            Point moveTo = move.MoveTo;

            if (token.TokenType == TokenType.Empty ||
                token.TokenType == TokenType.Flag ||
                token.TokenType == TokenType.Bomb)
            {
                throw new InvalidMoveException(string.Format("Invalid move.  Token type {0} cannot be moved.", token.TokenType));
            }

            var defender = this.GameBoard.Get(moveTo);

            var result = token.Attack(defender);

            switch (result)
            {
            case GameMoveResultType.AttackerWins:
                this.GameBoard.Remove(defender.Point);
                token.SetPoint(moveTo);
                break;

            case GameMoveResultType.DefenderWins:
                this.GameBoard.Remove(token.Point);
                break;

            case GameMoveResultType.BothLose:
                this.GameBoard.Remove(token.Point);
                this.GameBoard.Remove(defender.Point);
                break;

            case GameMoveResultType.TokenMove:
                token.SetPoint(moveTo);
                break;
            }

            if (result != GameMoveResultType.FlagCapturedByAttacker)
            {
                var p1ActiveTokens = this.GameBoard.GetTokens().Count(x => x.PlayerID == Player1.ID && x.IsMovable());
                var p2ActiveTokens = this.GameBoard.GetTokens().Count(x => x.PlayerID == Player2.ID && x.IsMovable());

                if (p1ActiveTokens == 0)
                {
                    if (p2ActiveTokens == 0)
                    {
                        result = GameMoveResultType.BothOutOfPieces;
                    }
                    else
                    {
                        result = GameMoveResultType.AttackerOutOfPieces;
                    }
                }
                else if (p2ActiveTokens == 0)
                {
                    result = GameMoveResultType.DefenderOutOfPieces;
                }
            }

            this.GameStatus = GameStatus.CreateForMove(this.GameStatus, move, result, token, defender);
        }