Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
DMD2542/SimonSays_Wolf/Scripts/Simon.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
200 lines (138 sloc)
3.48 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using UnityEngine.UI; | |
public class Simon : MonoBehaviour { | |
public int button = 0; | |
public GameObject redButton; | |
public GameObject greenButton; | |
public GameObject yellowButton; | |
public GameObject blueButton; | |
public GameObject start; | |
public GameObject gameOverText; | |
public bool isPlayer = false; | |
public int level = 1; | |
public int playerIndex = 0; | |
public bool isPlaying = true; | |
public int[] computerSequence; | |
//int ComputerSequence [100]; | |
//int PlayerSequence [100]; | |
public int ButtonComp = 0; | |
// Use this for initialization | |
void Start () { | |
computerSequence = new int[400]; | |
for (int level = 0; level < 400; level++){ | |
ButtonComp = Random.Range (0, 4); | |
computerSequence[level] = ButtonComp; | |
} | |
} | |
//RED | |
public void red () { | |
redButton.GetComponent<AudioSource> ().Play(); | |
redButton.GetComponent<Image> ().color = new Color (1f, 0.45f, 0.45f); | |
Invoke ("RedbuttonNormal", 1); | |
if (isPlayer == true) { | |
if (computerSequence [playerIndex] == 0) { | |
playerIndex++; | |
checkIfPlayerRight (); | |
} else { | |
GameOver (); | |
} | |
} | |
} | |
public void RedbuttonNormal () { | |
redButton.GetComponent<Image> ().color = Color.red; | |
} | |
//GREEN | |
public void green () { | |
greenButton.GetComponent<AudioSource> ().Play(); | |
greenButton.GetComponent<Image> ().color = new Color (0.369f, 0.875f, 0.431f); | |
Invoke ("GreenbuttonNormal", 1); | |
if (isPlayer == true) { | |
if (computerSequence [playerIndex] == 1) { | |
playerIndex++; | |
checkIfPlayerRight (); | |
} else { | |
GameOver (); | |
} | |
} | |
} | |
public void GreenbuttonNormal () { | |
greenButton.GetComponent<Image> ().color = new Color (0.055f, 0.816f, 0.149f); | |
} | |
// YELLOW | |
public void yellow () { | |
yellowButton.GetComponent<AudioSource> ().Play(); | |
yellowButton.GetComponent<Image> ().color = new Color (0.988f, 0.996f, 0.376f); | |
Invoke ("YellowbuttonNormal", 1); | |
if (isPlayer == true) { | |
if (computerSequence [playerIndex] == 2) { | |
playerIndex++; | |
checkIfPlayerRight (); | |
} else { | |
GameOver (); | |
} | |
} | |
} | |
public void YellowbuttonNormal () { | |
yellowButton.GetComponent<Image> ().color = new Color (0.949f, 0.961f, 0f); | |
} | |
// Blue | |
public void blue () { | |
blueButton.GetComponent<AudioSource> ().Play(); | |
blueButton.GetComponent<Image> ().color = new Color (0.42f, 0.325f, 0.945f); | |
Invoke ("BluebuttonNormal", 1); | |
if (isPlayer == true) { | |
if (computerSequence [playerIndex] == 3) { | |
playerIndex++; | |
checkIfPlayerRight (); | |
} else { | |
GameOver (); | |
} | |
} | |
} | |
public void BluebuttonNormal () { | |
blueButton.GetComponent<Image> ().color = new Color (0.184f, 0.043f, 0.961f); | |
} | |
public void checkIfPlayerRight () { | |
if (playerIndex == level) { | |
level++; | |
startGame (); | |
playerIndex = 0; | |
} | |
} | |
public void GameOver () { | |
gameOverText.SetActive(true); | |
} | |
public void reStart () { | |
gameOverText.SetActive(false); | |
isPlayer = false; | |
level = 1; | |
playerIndex = 0; | |
isPlaying = true; | |
} | |
public void startGame () { | |
gameOverText.SetActive(false); | |
isPlayer = false; | |
for (int i = 0; i < level; i++) { | |
if (computerSequence [i] == 0) { | |
Invoke ("red", i+2); | |
} | |
if (computerSequence [i] == 1) { | |
Invoke ("green", i+2); | |
} | |
if (computerSequence [i] == 2) { | |
Invoke ("yellow", i+2); | |
} | |
if (computerSequence [i] == 3) { | |
Invoke ("blue", i+2); | |
} | |
} | |
Invoke ("isPlayerTest", level+2); | |
} | |
public void isPlayerTest () { | |
isPlayer = true; | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
} |