protected internal override IEnumerator RespondToCommandInternal(string inputCommand) { inputCommand = inputCommand.Trim(); if (!inputCommand.StartsWith("press ", StringComparison.InvariantCultureIgnoreCase)) { yield break; } inputCommand = inputCommand.Substring(6); string sequence = "pressing "; foreach (Match move in Regex.Matches(inputCommand, @"(\b(red|blue|green|yellow)\b|[rbgy])", RegexOptions.IgnoreCase)) { SimonButton button = _buttons[buttonIndex[move.Value.Substring(0, 1).ToLowerInvariant()]]; if (button != null) { yield return(move.Value); sequence += move.Value + " "; if (CoroutineCanceller.ShouldCancel) { CoroutineCanceller.ResetCancel(); yield break; } yield return(DoInteractionClick(button, sequence)); } } }
private void OnButtonClicked(SimonButton simonButton) { if (!_playerTurn) { return; } AudioManager.Instance.PlaySFX(ButtonClicClip); if (simonButton != ButtonSequence[_chosenButtonCount]) { OnLost(); } else { _chosenButtonCount++; if (_chosenButtonCount >= _turnCount) { _turnCount++; if (_turnCount > 3) { OnWin(); } else { ComputerTurn(); } } } }
public void CompareButton(SimonButton button) { if (buttonsToPress[0] == button) { buttonsToPress.RemoveAt(0); if (buttonsToPress.Count == 0) { Level++; } } else { Restart(); } }
// Start is called before the first frame update void Start() { audioSource = gameObject.AddComponent <AudioSource>(); GameEvents.current.BlockUserInput(); SimonRedButton = redButton.GetComponent <SimonButton>(); SimonGreenButton = greenButton.GetComponent <SimonButton>(); SimonYellowButton = yellowButton.GetComponent <SimonButton>(); SimonBlueButton = blueButton.GetComponent <SimonButton>(); GameEvents.current.onButtonPressed += onButtonPressed; allButtons = new SimonButton[4] { SimonRedButton, SimonGreenButton, SimonBlueButton, SimonYellowButton }; }
void onButtonPressed(SimonButton buttonPressed) { SimonButton currentPlay = playerButtonsSequence[0]; playerButtonsSequence.RemoveAt(0); if (buttonPressed != currentPlay) { GameOver(); return; } if (playerButtonsSequence.Count == 0) { SetScore(getCurrentScore()); Play(); } }
private void TrySequence(SimonButton colorButton) { if (_sequence[_indexPlayerSequence] == colorButton) { Score++; _indexPlayerSequence++; } else { IsPlayerLose = true; } if (_sequence.Count == _indexPlayerSequence) { _indexPlayerSequence = 0; ToggleComputerMode(); } }
public IEnumerator GenerateCode() { for (int i = 0; i < buttons.Count && !firstTime; i++) { buttons[i].Activate(false); } firstTime = false; yield return(wait); for (int i = 0; i < activeButtons[level]; i++) { //Activar x botones aleatorios int x = rand.Next(0, buttons.Count); SimonButton button = buttons[x].UseOnce(); //Guardarlos en activos buttonsToPress.Add(button); yield return(wait); } for (int i = 0; i < buttons.Count; i++) { buttons[i].Activate(true); } }
/// <summary> /// Listener for button inputs /// </summary> public void OnUserInput(SimonButton userInputtedButtonComponent) { if (CurrentState != WaitForUserInput || !_inputReady) { // A button was pressed before the sequence started or finished playing, considered a game over RestartGame(); } if (_currentSequence.Count <= 0) { return; } if (_currentSequence[_userInputsThisRound] == userInputtedButtonComponent) { _userInputsThisRound++; } else { // Incorrect, game over RestartGame(); } }
public ComputerPlayMessage(SimonButton color) { Color = color; }
public void ButtonPressed(SimonButton buttonPressed) { onButtonPressed?.Invoke(buttonPressed); }