Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Master : MonoBehaviour {
- ArrayList theList; // jugador
- ArrayList aiList; // máquina
- int index;
- int humanIndex;
- int limit;
- public GameObject cubo1;
- public GameObject cubo2;
- public GameObject cubo3;
- public GameObject cubo4;
- public Master instance;
- // Use this for initialization
- void Start () {
- cubo1 = GameObject.Find("Cube1");
- cubo2 = GameObject.Find("Cube2");
- cubo3 = GameObject.Find("Cube3");
- cubo4 = GameObject.Find("Cube4");
- instance = this;
- index = 0;
- limit = 0;
- humanIndex = 0;
- theList = new ArrayList();
- aiList = new ArrayList();
- aiList.Add(2);
- aiList.Add(1);
- aiList.Add(3);
- aiList.Add(1);
- aiList.Add(4);
- aiList.Add(1);
- StartCoroutine(Play());
- }
- void Clear()
- {
- cubo1.GetComponent<Renderer>().material.color = Color.white;
- cubo2.GetComponent<Renderer>().material.color = Color.white;
- cubo3.GetComponent<Renderer>().material.color = Color.white;
- cubo4.GetComponent<Renderer>().material.color = Color.white;
- }
- IEnumerator Play() {
- Debug.Log("Playing");
- int num = (int)aiList[index];
- Clear();
- if (num == 1)
- {
- cubo1.GetComponent<Renderer>().material.color = Color.green;
- }
- else if(num == 2)
- {
- cubo2.GetComponent<Renderer>().material.color = Color.red;
- }
- else if (num == 3)
- {
- cubo3.GetComponent<Renderer>().material.color = Color.blue;
- }
- else if (num == 4)
- {
- cubo4.GetComponent<Renderer>().material.color = Color.yellow;
- }
- if(index < limit)
- {
- index++;
- yield return new WaitForSeconds(1);
- StartCoroutine(Play());
- }
- else
- {
- yield return new WaitForSeconds(1);
- Clear();
- }
- }
- // Update is called once per frame
- void Update () {
- }
- public IEnumerator checkPlay()
- {
- bool lost = false;
- Debug.Log("LIMIT="+limit+",HINDEX="+humanIndex+"LIST_SIZE="+theList.Count);
- for(int l = 0; l <= theList.Count - 1; l++)
- {
- int human = (int)theList[l];
- int machine = (int)aiList[l];
- if(human != machine)
- {
- Debug.Log("LOST");
- lost = true;
- }
- }
- if(lost == false && humanIndex >= limit)
- {
- Debug.Log("OK. CLEARING PLAYER LIST");
- humanIndex = 0;
- index = 0;
- limit++;
- theList.Clear();
- yield return new WaitForSeconds(1);
- StartCoroutine(Play());
- }
- else if(lost == false)
- {
- yield return new WaitForSeconds(1);
- StartCoroutine(Play());
- }
- }
- public void addToList(int number)
- {
- theList.Add(number);
- humanIndex++;
- Debug.Log("CHECK PLAY");
- StartCoroutine(checkPlay());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement