示例#1
0
 private async void _runNextMoveAsync()
 {
     while (subeventEnded())
     {
         System.Threading.Thread.Sleep(AITurnDelayMilliseconds);
         foreach (Player p in this.playerPanels)
         {
             p.Refresh();
         }
         await PlayerSemaphore.waitForEventEnd();
     }
 }
示例#2
0
        //Runs when an event has sucessfully resolved.
        public bool subeventEnded()
        {
            PlayerSemaphore.lockGame();
            switch (this.currentGameState)
            {
            case GameState.FirstPlayer:
                currentGameState = GameState.FirstDiceRoll;
                currentGameEvent = new FirstPlayerEvt();
                currentGameEvent.beginExecution(this, this);
                break;

            case GameState.FirstDiceRoll:
                //Move to the next stage

                //Re order the players so the firstPlayer is the first item in the playerOrder list.
                int fp = firstPlayer.getNumber();
                for (int i = 0; i < playerOrder.Count(); i++)
                {
                    playerOrder[i] = playerPanels[fp];
                    fp++;
                    if (fp == playerPanels.Count())
                    {
                        fp = 0;
                    }
                }
                currentGameState = GameState.FirstSettlement;
                currentGameEvent = new FirstSettlementEvt();
                currentGameEvent.beginExecution(this, this);
                break;

            case GameState.FirstSettlement:
                //We are finished placing settlements
                currentGameState = GameState.FirstResources;
                currentGameEvent = new FirstResourcesEvt();
                currentGameEvent.beginExecution(this, this);
                break;

            case GameState.FirstResources:
                //We can finally move to the gameplay loop.
                currentPlayer = firstPlayer;
                addEventText(UserMessages.PlayerDiceRollPrompt(currentPlayer));
                currentGameState = GameState.DiceRoll;
                currentGameEvent = new DiceRollEvt();
                currentGameEvent.beginExecution(this, this);
                break;

            case GameState.DiceRoll:
                //Run the player turn event.
                currentGameState = GameState.PlayerTurn;
                currentGameEvent = new PlayerTurnEvt();
                currentGameEvent.beginExecution(this, this);
                break;

            case GameState.PlayerTurn:
                //Increment to the next player and start the dice roll event.
                turnCounter   = (turnCounter == playerPanels.Count() - 1) ? 0 : turnCounter + 1;
                currentPlayer = playerOrder[turnCounter];
                addEventText(UserMessages.PlayerDiceRollPrompt(currentPlayer));
                currentGameState = GameState.DiceRoll;
                currentGameEvent = new DiceRollEvt();
                currentGameEvent.beginExecution(this, this);
                break;

            case GameState.End:
                return(false);
            }
            return(true);
        }