Exemple #1
0
    private void GameStateTransition(EnumGameState gotoState)
    {
        if (!initalized)
        {
            throw new InvalidOperationException("ReportEvent(): Engine not initalized");
        }

        if (VerifyTrasitionLegality(gotoState) == false)
        {
            throw new NotImplementedException(string.Format("GameStateTransition(): Invalid trasition from {0} to {1} game state", gamestate, gotoState));
        }

        switch (gotoState)
        {
        case EnumGameState.GAME_SETUP:
            gamestate = gotoState;
            GameBoard.Instance.SetupGame(AttendingPlayers.Count);
            GameStateTransition(EnumGameState.BEGINNING_OF_TURN);     // consider sending event after setting up the game...
            break;

        case EnumGameState.BEGINNING_OF_TURN:
            gamestate = gotoState;
            if (ActivePlayer.FulfillsWinningConditions() &&
                winningTurns[activePlayerIterator] == Constants.TURNS_REQUIRED_TO_WIN)
            {
                GameStateTransition(EnumGameState.GAME_END);
            }
            break;

        case EnumGameState.MAKING_TURN_ACTION:
            gamestate = gotoState;
            break;

        case EnumGameState.TURN_ACTION_DONE:
            gamestate = gotoState;
            break;

        case EnumGameState.ACCEPT_NOBLES:
            gamestate = gotoState;
            break;

        case EnumGameState.END_OF_TURN:
            gamestate = gotoState;

            if (ActivePlayer.FulfillsWinningConditions() && Constants.TURNS_REQUIRED_TO_WIN == 0)
            {
                endgame = true;
            }
            else if (ActivePlayer.FulfillsWinningConditions())
            {
                winningTurns[activePlayerIterator]++;
            }
            else
            {
                winningTurns[activePlayerIterator] = 0;
            }

            if (endgame && activePlayerIterator == AttendingPlayers.Count - 1)
            {
                GameStateTransition(EnumGameState.GAME_END);
            }

            activePlayerIterator = (activePlayerIterator + 1) % AttendingPlayers.Count;
            GameStateTransition(EnumGameState.BEGINNING_OF_TURN);
            break;

        default:
            throw new NotImplementedException(string.Format("GameStateTransition(): Not implemented trasition to {0}", gotoState));
        }
    }