コード例 #1
0
 //We use this timer for game updates that need to run constantly.
 private void gameTimer_Tick(object sender, EventArgs e)
 {
     //If it is the AI's turn, the delay timer has ticked out, and we're still playing, we calculate the AI's move and reset
     //the delay timer.
     if (currentGame.CurrentPlayer == Game.Participant.AI && currentGame.GameState == Game.State.Playing && currentGame.AIDelay <= 0)
     {
         currentGame.ResetAIDelay();
         currentGame.aiPlayer.CalculateMove(ref currentGame.gameBoard, currentGame.GameDifficulty);
         currentGame.SwitchTurns();
         //Repaint the board so the AI's piece shows up.
         RepaintGame();
         currentGame.GameState = currentGame.CheckVictory();
         //We know the AI has won
         if (currentGame.GameState == Game.State.Won)
         {
             currentGame.GameState = Game.State.Lost;
         }
         CheckWinner();
     }
     else if (currentGame.CurrentPlayer == Game.Participant.Player && currentGame.PlayerTimer <= 0)
     {
         //The player has run out of time, so we switch turns.
         currentGame.SwitchTurns();
         timerLabel.Text = "Player lost a turn after failing to respond.";
     }
 }