/// <summary> /// Handle the "Roll" button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void roll_Click(object sender, EventArgs e) { DiceHandler.Roll(); if (gameType == GameTypes.Online) { NetworkManager.Instance.ResetTimeout(); } }
/// <summary> /// Performs the AI player's game logic, based on its current state. /// </summary> public override void PerformPlayerLogic() { // State machine for handling the AI player behavior. switch (State) { case AIState.Roll: // Roll the dice DiceHandler.Roll(); State = AIState.Rolling; break; case AIState.Rolling: // Wait for the dice to stop rolling if (!DiceHandler.DiceRolling()) { State = AIState.ChooseDice; } break; case AIState.ChooseDice: // Hold one of the dice DiceHandler.MoveDice(random.Next(0, 5)); // Randomly move on to selecting the score, or hold another die if (DiceHandler.GetHoldingDice() != null && random.Next(0, 5) == 1) { State = AIState.SelectScore; } break; case AIState.SelectScore: // Select an unused score line if (GameStateHandler.SelectScore((YachtCombination)random.Next(1, 13))) { State = AIState.WriteScore; } break; case AIState.WriteScore: // If a valid score was selected then write the score if (GameStateHandler != null && GameStateHandler.IsScoreSelect) { GameStateHandler.FinishTurn(); DiceHandler.Reset(GameStateHandler.IsGameOver); State = AIState.Roll; } break; default: break; } }
/// <summary> /// Check if the phone was shaken and if so roll the dice. /// </summary> private void HandleShakeInput() { // Register for shake detection if (!registeredForShakeDetection) { Accelerometer.ShakeDetected += Accelerometer_ShakeDetected; registeredForShakeDetection = true; } if (shakeDetect) { DiceHandler.Roll(); if (gameType == GameTypes.Online) { NetworkManager.Instance.ResetTimeout(); } shakeDetect = false; } }