/// <summary> /// Play again the same scene. /// </summary> /// <param name="sender">The object that sends the event</param> /// <param name="e">The parameters of the event.</param> private void OnPlayAgainButtonClicked(object sender, EventArgs e) { _soundManager.PlaySound(SimpleSoundService.SoundType.Button); var screenContext = new ScreenContext(new PlayScene(_numberOfPlayers), new PlayGameOverPopupScene(_numberOfPlayers)); var transition = new ColorFadeTransition(Color.White, TimeSpan.FromSeconds(1)); WaveServices.ScreenContextManager.To(screenContext, transition); }
/// <summary> /// Choose 1 Player. /// </summary> /// <param name="sender">The object that sends the event</param> /// <param name="e">The parameters of the event.</param> private void OnPlayerToggleButtonClicked(object sender, EventArgs e) { _soundManager.PlaySound(SimpleSoundService.SoundType.Button); _numberOfPlayers = NumberPlayerEnum.OnePlayer; _onePlayerToggleButtonUI.IsChecked = true; _twoPlayersPlayToggleButtonUI.IsChecked = false; _twoPlayersRouletteToggleButtonUI.IsChecked = false; }
/// <summary> /// Initializes the Automatic State Mode of the game. /// </summary> /// <param name="sender">The object that sends the event</param> /// <param name="e">The parameters of the event.</param> private void OnToggleAutomaticOnClicked(object sender, EventArgs e) { _soundManager.StopAllSounds(); _soundManager.PlaySound(SimpleSoundService.SoundType.Button); GameState = GameStateEnum.Manual; _toggleAutomaticOn.IsVisible = false; _toggleAutomaticOff.IsVisible = true; TimerButtonsChanged(); }
/// <summary> /// Goes Back to the Main Menu Scene, hiding the RulesScene. /// </summary> /// <param name="sender">The object that sends the event</param> /// <param name="e">The parameters of the event.</param> private void OnButtonCloseClicked(object sender, EventArgs e) { _soundManager.PlaySound(SimpleSoundService.SoundType.Back); MainMenuScene mainMenuScene = WaveServices.ScreenContextManager.CurrentContext.FindScene <MainMenuScene>(); if (mainMenuScene != null) { mainMenuScene.Resume(); IsVisible = false; Pause(); } }
public void OpenGameOver1PlayerPopup(int movementsCount) { Pause(); var playGameOverPopupScene = WaveServices.ScreenContextManager.CurrentContext.FindScene <PlayGameOverPopupScene>(); playGameOverPopupScene.MovementsRecord = _gameStorage.Record; if (movementsCount > _gameStorage.Record) { _soundManager.PlaySound(SimpleSoundService.SoundType.Win); _gameStorage.Record = movementsCount; } else { _soundManager.PlaySound(SimpleSoundService.SoundType.Lose); } playGameOverPopupScene.MovementsCount = movementsCount; playGameOverPopupScene.Resume(); }
/// <summary> /// Goes to the Play Scene. /// </summary> /// <param name="sender">The object that sends the event</param> /// <param name="e">The parameters of the event.</param> private void OnPlayButtonClicked(object sender, EventArgs e) { _soundManager.PlaySound(SimpleSoundService.SoundType.Button); var playersPopupScene = WaveServices.ScreenContextManager.CurrentContext.FindScene <PlayersPopupScene>(); if (playersPopupScene != null) { playersPopupScene.GameMode = GameModeEnum.PlayMode; playersPopupScene.Resume(); Pause(); } }
/// <summary> /// Update Method /// </summary> /// <param name="gameTime">Current Game Time</param> protected override void Update(TimeSpan gameTime) { WaveServices.Layout.PerformLayout(); switch (_scene.GameState) { case GameStateEnum.Automatic: if (_timer == null) { _soundManager.PlaySound(SimpleSoundService.SoundType.Timer, 1f, true); _timer = WaveServices.TimerFactory.CreateTimer("TimeToWait", TimeSpan.FromSeconds(1f), () => { _time--; _scene.TimerLeftTextBlock.Text = _time + " s"; }); } else if (_time <= 0) { WaveServices.TimerFactory.RemoveTimer("TimeToWait"); _scene.TimerLeftTextBlock.Text = "- s"; if (_timer2 == null) { _soundManager.StopAllSounds(); _revoluteJoint.EnableMotor = true; _timer2 = WaveServices.TimerFactory.CreateTimer("TimeToAceletare", TimeSpan.FromSeconds(1f), () => { _aceleratingTime--; }); } if (_aceleratingTime <= 0) { WaveServices.TimerFactory.RemoveTimer("TimeToAceletare"); _revoluteJoint.EnableMotor = false; } } break; case GameStateEnum.Manual: WaveServices.TimerFactory.RemoveAllTimers(); _timer = null; _timer2 = null; _scene.TimerLeftTextBlock.Text = "- s"; _revoluteJoint.EnableMotor = false; _touchState = WaveServices.Input.TouchPanelState; if (_touchState.IsConnected) { // Checks Mouse Left Button Click and anyone entity linked if (_touchState.Count > 0 && _mouseJoint == null) { foreach (var touch in _touchState) { // Updates Mouse Position _touchPosition = touch.Position; // Adjust the position to the Viewport. _scene.VirtualScreenManager.ToVirtualPosition(ref _touchPosition); // Collider Test var collider = _needleImage.FindComponent <CircleCollider2D>(); if (collider != null && collider.Contain(_touchPosition)) { var rigidBody = _needleImage.FindComponent <RigidBody2D>(); if (rigidBody != null) { _touchingId = touch.Id; // Create Mouse Joint _mouseJoint = new MouseJoint2D() { Target = _touchPosition }; _needleImage.AddComponent(_mouseJoint); // We break after collide because no more than one touch can be Joint to entity. break; } } } } // If joint exists then update joint anchor position. // If touchReleased Then touchFound = false; so Remove the Joint to conserve physics. if (_mouseJoint != null) { TouchLocation touchLocation; if (_touchState.TryGetTouch(_touchingId, out touchLocation)) { _touchPosition = touchLocation.Position; _scene.VirtualScreenManager.ToVirtualPosition(ref _touchPosition); _mouseJoint.Target = _touchPosition; } else { if (!_needleImage.IsDisposed) { _needleImage.RemoveComponent <MouseJoint2D>(); } _mouseJoint = null; } } } break; } // Collision with pieces when the needle stops. var angularVelocity = _needleImageRigidBody2D.AngularVelocity; if (!_stopRepeat && angularVelocity > -0.005f && angularVelocity < 0.005f) { _soundManager.StopAllSounds(); Movement movement = RouletteHelper.GetMovementFromRotation(_needleImage.FindComponent <Transform2D>().Rotation); movement.Number = _movementsCount++; movement.NumberOfPlayers = _numberOfPlayers; Movement repeatedFingerMovement = null; switch (_numberOfPlayers) { case NumberPlayerEnum.OnePlayer: repeatedFingerMovement = _movementsList.Find(x => x.Finger == movement.Finger); if (repeatedFingerMovement != null) { if (repeatedFingerMovement.Color != movement.Color) { _movementToRemove = repeatedFingerMovement; _movementsList.Add(movement); } } else { _movementsList.Add(movement); } break; case NumberPlayerEnum.TwoPlayers: repeatedFingerMovement = _movementsList.Find(x => x.PlayerNumber != _playerPlaying && x.Finger == movement.Finger); if (repeatedFingerMovement != null) { if (repeatedFingerMovement.Color != movement.Color) { _movementToRemove = repeatedFingerMovement; _movementsList.Add(movement); } } else { _movementsList.Add(movement); } break; } _noMovementsTextBlock.IsVisible = false; _movementsTextBlockText.Text += "\n" + movement.ToString(); if (_numberOfPlayers == NumberPlayerEnum.TwoPlayers) { if (_playerPlaying == 1) { _playerPlaying++; } else { _playerPlaying--; } } if (_scene.GameState == GameStateEnum.Automatic) { ResetAutomaticTimers(); } _soundManager.PlaySound(SimpleSoundService.SoundType.Pick); _stopRepeat = true; } // When needle start to ride, it's time to another movement if (angularVelocity > 0.01f || angularVelocity < -0.01f) { _stopRepeat = false; if (_movementsList.Any(x => x.CirclePressed == null)) { GameOver(); } } if (angularVelocity > 2f || angularVelocity < -2f) { if (_sound == null || _sound.State == SoundState.Stopped) { _sound = _soundManager.PlaySound(SimpleSoundService.SoundType.Rotating); } } List <Entity> circlesPressed = new List <Entity>(); // We check the Circles to assign the collider with touch. _touchState = WaveServices.Input.TouchPanelState; if (_touchState.IsConnected) { foreach (Entity entity in _scene.EntityManager.FindAllByTag("MatCircles")) { var opacity = 1f; foreach (var touch in _touchState) { // Updates Mouse Position _touchPosition = touch.Position; _scene.VirtualScreenManager.ToVirtualPosition(ref _touchPosition); var collider = entity.FindComponent <CircleCollider2D>(); if (collider != null && collider.Contain(_touchPosition)) { circlesPressed.Add(entity); opacity = 0.5f; break; } } entity.FindComponent <Transform2D>().Opacity = opacity; } } // Check if user adds a new circle touch. foreach (var circle in circlesPressed) { if (!_movementsList.Any(x => x.CirclePressed == circle)) { var emptyMovement = _movementsList.Find(x => x.CirclePressed == null); if (emptyMovement != null && emptyMovement.Color == circle.FindComponent <Sprite>().TintColor) { emptyMovement.CirclePressed = circle; _movementsList.Remove(_movementToRemove); _movementToRemove = null; } else { GameOver(); } } } // Check if user removes a circle touch. if (circlesPressed.Count < _lastCirclesPressed.Count) { Entity circleRemoved = null; foreach (var lastCircle in _lastCirclesPressed) { if (!circlesPressed.Contains(lastCircle)) { circleRemoved = lastCircle; break; } } if (circleRemoved != null) { var movement = _movementsList.Find(x => x.CirclePressed == circleRemoved); if (movement != null && movement != _movementToRemove) { GameOver(); } } } _lastCirclesPressed = circlesPressed.ToList(); }
/// <summary> /// Update Method /// </summary> /// <param name="gameTime">Current Game Time</param> protected override void Update(TimeSpan gameTime) { WaveServices.Layout.PerformLayout(); switch (_scene.GameState) { case GameStateEnum.Automatic: if (_timer == null) { _soundManager.PlaySound(SimpleSoundService.SoundType.Timer, 1f, true); _timer = WaveServices.TimerFactory.CreateTimer("TimeToWait", TimeSpan.FromSeconds(1f), () => { _time--; _scene.TimerLeftTextBlock.Text = _time + " s"; }); } else if (_time <= 0) { WaveServices.TimerFactory.RemoveTimer("TimeToWait"); _scene.TimerLeftTextBlock.Text = "- s"; if (_timer2 == null) { _soundManager.StopAllSounds(); _revoluteJoint.EnableMotor = true; _timer2 = WaveServices.TimerFactory.CreateTimer("TimeToAceletare", TimeSpan.FromSeconds(1f), () => { _aceleratingTime--; }); } if (_aceleratingTime <= 0) { WaveServices.TimerFactory.RemoveTimer("TimeToAceletare"); _revoluteJoint.EnableMotor = false; } } break; case GameStateEnum.Manual: WaveServices.TimerFactory.RemoveAllTimers(); _timer = null; _timer2 = null; _scene.TimerLeftTextBlock.Text = "- s"; _revoluteJoint.EnableMotor = false; _touchState = WaveServices.Input.TouchPanelState; if (_touchState.IsConnected) { // Checks Mouse Left Button Click and anyone entity linked if (_touchState.Count > 0 && _mouseJoint == null) { foreach (var touch in _touchState) { // Updates Mouse Position _touchPosition = touch.Position; // Adjust the position to the Viewport. _scene.VirtualScreenManager.ToVirtualPosition(ref _touchPosition); // Collider Test var collider = _needleImage.FindComponent <CircleCollider2D>(); if (collider != null && collider.Contain(_touchPosition)) { var rigidBody = _needleImage.FindComponent <RigidBody2D>(); if (rigidBody != null) { _touchingId = touch.Id; // Create Mouse Joint _mouseJoint = new MouseJoint2D() { Target = _touchPosition }; _needleImage.AddComponent(_mouseJoint); // We break after collide because no more than one touch can be Joint to entity. break; } } } } // If joint exists then update joint anchor position. // If touchReleased Then touchFound = false; so Remove the Joint to conserve physics. if (_mouseJoint != null) { TouchLocation touchLocation; if (_touchState.TryGetTouch(_touchingId, out touchLocation)) { _touchPosition = touchLocation.Position; _scene.VirtualScreenManager.ToVirtualPosition(ref _touchPosition); _mouseJoint.Target = _touchPosition; } else { if (!_needleImage.IsDisposed) { _needleImage.RemoveComponent <MouseJoint2D>(); } _mouseJoint = null; } } } break; } // Collision with pieces when the needle stops. float angularVelocity = _needleImageRigidBody2D.AngularVelocity; if (!_stopRepeat && angularVelocity > -0.005f && angularVelocity < 0.005f) { _soundManager.StopAllSounds(); Movement movement = RouletteHelper.GetMovementFromRotation(_needleImage.FindComponent <Transform2D>().Rotation); movement.Number = _movementsCount++; movement.NumberOfPlayers = _scene.NumberOfPlayers; _noMovementsTextBlock.IsVisible = false; _movementsTextBlockText.Text += "\n" + movement.ToString(); if (_scene.GameState == GameStateEnum.Automatic) { ResetAutomaticTimers(); } _soundManager.PlaySound(SimpleSoundService.SoundType.Pick); _stopRepeat = true; } // When needle start to ride, it's time to another movement if (angularVelocity > 0.01f || angularVelocity < -0.01f) { _stopRepeat = false; } if (angularVelocity > 2f || angularVelocity < -2f) { if (_sound == null || _sound.State == SoundState.Stopped) { _sound = _soundManager.PlaySound(SimpleSoundService.SoundType.Rotating); } } }