/// <summary> /// Move dice that are tapped. /// </summary> /// <param name="sample">Input gesture performed.</param> private void HandleDiceHandlerInput(GestureSample sample) { if (DiceHandler.Rolls < 3) { Dice[] rollingDice = DiceHandler.GetRollingDice(); Dice[] holdingDice = DiceHandler.GetHoldingDice(); if (sample.GestureType == GestureType.Tap) { // Create the touch rectangle Rectangle touchRect = new Rectangle((int)sample.Position.X - 5, (int)sample.Position.Y - 5, 10, 10); for (int i = 0; i < DiceHandler.DiceAmount; i++) { // Check for intersection between the touch rectangle and any of the dice if ((rollingDice != null && rollingDice[i] != null && !rollingDice[i].IsRolling && rollingDice[i].Intersects(touchRect)) || (holdingDice != null && holdingDice[i] != null && holdingDice[i].Intersects(touchRect))) { DiceHandler.MoveDice(i); if (DiceHandler.GetHoldingDice() == null) { GameStateHandler.SelectScore(null); } } } } } }
/// <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> /// Highlight the score card line that was tapped. /// </summary> /// <param name="sample">Input gesture performed.</param> private void HandleSelectScoreInput(GestureSample sample) { if (sample.GestureType == GestureType.Tap) { // Create the touch rectangle Rectangle touchRect = new Rectangle((int)sample.Position.X - 5, (int)sample.Position.Y - 5, 10, 10); for (int i = 0; i < 12; i++) { if (GameStateHandler.IntersectLine(touchRect, i)) { GameStateHandler.SelectScore((YachtCombination)(i + 1)); } } } }