Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.25 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Master : MonoBehaviour {
  6.  
  7.      ArrayList theList; // jugador
  8.      ArrayList aiList; // máquina
  9.      int index;
  10.     int humanIndex;
  11.      int limit;
  12.     public  GameObject cubo1;
  13.     public  GameObject cubo2;
  14.     public  GameObject cubo3;
  15.     public  GameObject cubo4;
  16.     public  Master instance;
  17.  
  18.     // Use this for initialization
  19.     void Start () {
  20.         cubo1 = GameObject.Find("Cube1");
  21.         cubo2 = GameObject.Find("Cube2");
  22.         cubo3 = GameObject.Find("Cube3");
  23.         cubo4 = GameObject.Find("Cube4");
  24.  
  25.         instance = this;
  26.         index = 0;
  27.         limit = 0;
  28.         humanIndex = 0;
  29.         theList = new ArrayList();
  30.         aiList = new ArrayList();
  31.         aiList.Add(2);
  32.         aiList.Add(1);
  33.         aiList.Add(3);
  34.         aiList.Add(1);
  35.         aiList.Add(4);
  36.         aiList.Add(1);
  37.         StartCoroutine(Play());
  38.     }
  39.  
  40.      void Clear()
  41.     {
  42.         cubo1.GetComponent<Renderer>().material.color = Color.white;
  43.         cubo2.GetComponent<Renderer>().material.color = Color.white;
  44.         cubo3.GetComponent<Renderer>().material.color = Color.white;
  45.         cubo4.GetComponent<Renderer>().material.color = Color.white;
  46.     }
  47.    
  48.      IEnumerator Play() {
  49.         Debug.Log("Playing");
  50.         int num = (int)aiList[index];
  51.         Clear();
  52.         if (num == 1)
  53.         {
  54.             cubo1.GetComponent<Renderer>().material.color = Color.green;
  55.         }
  56.         else if(num == 2)
  57.         {
  58.             cubo2.GetComponent<Renderer>().material.color = Color.red;
  59.         }
  60.         else if (num == 3)
  61.         {
  62.             cubo3.GetComponent<Renderer>().material.color = Color.blue;
  63.         }
  64.         else if (num == 4)
  65.         {
  66.             cubo4.GetComponent<Renderer>().material.color = Color.yellow;
  67.         }
  68.         if(index < limit)
  69.         {
  70.             index++;
  71.             yield return new WaitForSeconds(1);
  72.             StartCoroutine(Play());
  73.         }
  74.         else
  75.         {
  76.             yield return new WaitForSeconds(1);
  77.             Clear();
  78.         }
  79.     }
  80.  
  81.     // Update is called once per frame
  82.     void Update () {
  83.        
  84.     }
  85.  
  86.     public IEnumerator checkPlay()
  87.     {
  88.         bool lost = false;
  89.         Debug.Log("LIMIT="+limit+",HINDEX="+humanIndex+"LIST_SIZE="+theList.Count);
  90.         for(int l = 0; l <= theList.Count - 1; l++)
  91.         {
  92.             int human = (int)theList[l];
  93.             int machine = (int)aiList[l];
  94.             if(human != machine)
  95.             {
  96.                 Debug.Log("LOST");
  97.                 lost = true;
  98.             }
  99.         }
  100.         if(lost == false && humanIndex >= limit)
  101.         {
  102.             Debug.Log("OK. CLEARING PLAYER LIST");
  103.             humanIndex = 0;
  104.             index = 0;
  105.             limit++;
  106.             theList.Clear();
  107.             yield return new WaitForSeconds(1);
  108.             StartCoroutine(Play());
  109.         }
  110.         else if(lost == false)
  111.         {
  112.             yield return new WaitForSeconds(1);
  113.             StartCoroutine(Play());
  114.         }
  115.     }
  116.  
  117.     public void addToList(int number)
  118.     {
  119.         theList.Add(number);
  120.         humanIndex++;
  121.         Debug.Log("CHECK PLAY");
  122.         StartCoroutine(checkPlay());
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement