Completely working Buttons Memory minigame, needs ITask
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using System.Data.SqlTypes;
|
||||
using UnityEditor;
|
||||
|
||||
public enum GameState
|
||||
{
|
||||
Idle,
|
||||
ShowingSequance,
|
||||
PlayerTurn,
|
||||
GameOver
|
||||
GameOver,
|
||||
MinigameWon
|
||||
}
|
||||
|
||||
public class ButtonsMinigame : MonoBehaviour
|
||||
@@ -16,6 +20,10 @@ public class ButtonsMinigame : MonoBehaviour
|
||||
public int round = 1;
|
||||
public float glowDuration = 0.4f;
|
||||
public float gapBetween = 0.15f;
|
||||
public float delayBeforeSequence = 0.8f;
|
||||
public int winRound = 5;
|
||||
public TMP_Text statusText;
|
||||
public GameObject startButton;
|
||||
private int playerStep = 0;
|
||||
private GameState state = GameState.Idle;
|
||||
private List<int> sequence = new List<int>();
|
||||
@@ -32,6 +40,10 @@ public class ButtonsMinigame : MonoBehaviour
|
||||
|
||||
IEnumerator PlaySequence()
|
||||
{
|
||||
|
||||
SetState(GameState.ShowingSequance);
|
||||
yield return new WaitForSeconds(delayBeforeSequence);
|
||||
|
||||
for (int i = 0; i < sequence.Count; i++)
|
||||
{
|
||||
int buttonIndex = sequence[i];
|
||||
@@ -40,10 +52,20 @@ public class ButtonsMinigame : MonoBehaviour
|
||||
lights[buttonIndex].gameObject.SetActive(false);
|
||||
yield return new WaitForSeconds (gapBetween);
|
||||
}
|
||||
|
||||
playerStep = 0;
|
||||
SetState(GameState.PlayerTurn);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
SetState(GameState.Idle);
|
||||
}
|
||||
|
||||
public void StartGame()
|
||||
{
|
||||
round = 1;
|
||||
playerStep = 0;
|
||||
GenerateSequence();
|
||||
StartCoroutine(PlaySequence());
|
||||
}
|
||||
@@ -51,10 +73,54 @@ public class ButtonsMinigame : MonoBehaviour
|
||||
void SetState(GameState newState)
|
||||
{
|
||||
state = newState;
|
||||
|
||||
switch (newState)
|
||||
{
|
||||
case GameState.Idle:
|
||||
statusText.text = "Get Ready!";
|
||||
break;
|
||||
case GameState.ShowingSequance:
|
||||
statusText.text = "Watch the sequence";
|
||||
break;
|
||||
case GameState.PlayerTurn:
|
||||
statusText.text = "Your turn!";
|
||||
break;
|
||||
case GameState.GameOver:
|
||||
statusText.text = "Gameover";
|
||||
break;
|
||||
case GameState.MinigameWon:
|
||||
statusText.text = "Task Completed";
|
||||
break;
|
||||
}
|
||||
|
||||
startButton.SetActive(state == GameState.Idle || state == GameState.GameOver);
|
||||
}
|
||||
public void OnButtonClicked(int buttonIndex)
|
||||
{
|
||||
Debug.Log("Clicked : " + buttonIndex);
|
||||
if (state != GameState.PlayerTurn) return;
|
||||
if (buttonIndex == sequence[playerStep])
|
||||
{
|
||||
playerStep++;
|
||||
if (playerStep >= sequence.Count)
|
||||
{
|
||||
if (round >= winRound)
|
||||
{
|
||||
SetState(GameState.MinigameWon);
|
||||
}
|
||||
else
|
||||
{
|
||||
round++;
|
||||
GenerateSequence();
|
||||
StartCoroutine(PlaySequence());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetState(GameState.GameOver);
|
||||
Debug.Log("GameOver");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user