/// <summary> /// Updates the ball state. /// </summary> /// <param name="clickedZone">The zone where the player clicked.</param> /// <param name="caught">If set to <c>true</c> the ball was caught.</param> private void UpdateBallState(GoalZoneType clickedZone, bool caught) { if (!caught) { if (_leftZone.WasClicked) { _ball.SetState(BallState.Left); } else if (_centerZone.WasClicked) { _ball.SetState(BallState.Center); } else if (_rightZone.WasClicked) { _ball.SetState(BallState.Right); } } else { _ball.SetState(BallState.Hidden); } }
/// <summary> /// Updates the state of the goalkeeper. /// </summary> /// <returns><c>true</c>, if the goalkeeper caught the ball, <c>false</c> otherwise.</returns> /// <param name="gazeZone">The zone where the player looked.</param> /// <param name="clickedZone">The zone where the player clicked.</param> private bool UpdateGoalkeeperState(GoalZoneType gazeZone, GoalZoneType clickedZone) { if (gazeZone == GoalZoneType.None) { // Player isn't looking at anything. // Randomize the outcome depending on where the player clicked. return RandomizeGoalkeeperState(clickedZone); } else if (gazeZone == GoalZoneType.Left) { if (clickedZone == GoalZoneType.Left) { SetGoalkeeperState(GoalkeeperState.CatchLeft); return true; } SetGoalkeeperState(GoalkeeperState.MissLeft); } else if (_centerZone.IsBeingLookedAt) { if (_centerZone.WasClicked) { SetGoalkeeperState(GoalkeeperState.CatchCenter); return true; } SetGoalkeeperState(GoalkeeperState.MissCenter); } else if (_rightZone.IsBeingLookedAt) { if (_rightZone.WasClicked) { SetGoalkeeperState(GoalkeeperState.CatchRight); return true; } SetGoalkeeperState(GoalkeeperState.MissRight); } return false; }
/// <summary> /// Randomizes the state of the goalkeeper when we have no gaze data. /// </summary> /// <returns><c>true</c>, if the goalkeeper caught the ball, <c>false</c> otherwise.</returns> /// <param name="clickedZone">The clicked zone.</param> private bool RandomizeGoalkeeperState(GoalZoneType clickedZone) { var state = GoalkeeperState.Playing; var catched = _random.Next(0, 2) == 1; if (catched) { // Make sure we catch the ball in the same zone the player clicked. state = clickedZone == GoalZoneType.Left ? GoalkeeperState.CatchLeft : clickedZone == GoalZoneType.Center ? GoalkeeperState.CatchCenter : clickedZone == GoalZoneType.Right ? GoalkeeperState.CatchRight : GoalkeeperState.MissLeft; } else { // Randomize a state. state = (GoalkeeperState)_random.Next(0, 2); } // Set the goalkeepers state. SetGoalkeeperState(state); // Return whether or not the goalkeeper caught the ball. return catched; }