Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- using System.Collections.Generic;
- public class CardSystem : MonoBehaviour {
- public List<string> Cards = new List<string>();
- public int CardsCount;
- public int DiscardedCardsCount;
- public int timesLeft;
- public bool isEmpty = false;
- public bool isEmpty1 = false;
- public bool isEmpty2 = false;
- public bool isEmpty3 = false;
- public bool isEmpty4 = false;
- public GameObject TotalCards;
- public GameObject DiscardedCards;
- public GameObject NewHandButton;
- public GameObject TakeCardsButton;
- public GameObject CardBox;
- public GameObject CardBox1;
- public GameObject CardBox2;
- public GameObject CardBox3;
- public GameObject CardBox4;
- public GameObject DiscardButton;
- public GameObject DiscardButton1;
- public GameObject DiscardButton2;
- public GameObject DiscardButton3;
- public GameObject DiscardButton4;
- void Start ()
- {
- CardsCount = 52;
- DiscardedCardsCount = 0;
- timesLeft = 0;
- NewList();
- DiscardButton.gameObject.SetActive(false);
- DiscardButton1.gameObject.SetActive(false);
- DiscardButton2.gameObject.SetActive(false);
- DiscardButton3.gameObject.SetActive(false);
- DiscardButton4.gameObject.SetActive(false);
- TakeCardsButton.GetComponent<Button>().interactable = false;
- isEmpty = true;
- isEmpty1 = true;
- isEmpty2 = true;
- isEmpty3 = true;
- isEmpty4 = true;
- }
- void Update ()
- {
- TotalCards.GetComponent<InputField>().text = CardsCount.ToString();
- DiscardedCards.GetComponent<InputField>().text = DiscardedCardsCount.ToString();
- }
- public void NewHand ()
- {
- StartCoroutine(GiveCardsNew());
- NewHandButton.GetComponent<Button>().interactable = false;
- isEmpty = false;
- isEmpty1 = false;
- isEmpty2 = false;
- isEmpty3 = false;
- isEmpty4 = false;
- }
- public IEnumerator GiveCardsNew()
- {
- CardBox.GetComponent<InputField>().text = "";
- CardBox1.GetComponent<InputField>().text = "";
- CardBox2.GetComponent<InputField>().text = "";
- CardBox3.GetComponent<InputField>().text = "";
- CardBox4.GetComponent<InputField>().text = "";
- yield return new WaitForSeconds(0.5f);
- int newRandom1 = Random.Range(0, Cards.Count);
- CardBox.GetComponent<InputField>().text = Cards[newRandom1];
- Cards.RemoveAt(newRandom1);
- CardsCount -= 1;
- yield return new WaitForSeconds(0.5f);
- int newRandom2 = Random.Range(0, Cards.Count);
- CardBox1.GetComponent<InputField>().text = Cards[newRandom2];
- Cards.RemoveAt(newRandom2);
- CardsCount -= 1;
- yield return new WaitForSeconds(0.5f);
- int newRandom3 = Random.Range(0, Cards.Count);
- CardBox2.GetComponent<InputField>().text = Cards[newRandom3];
- Cards.RemoveAt(newRandom3);
- CardsCount -= 1;
- yield return new WaitForSeconds(0.5f);
- int newRandom4 = Random.Range(0, Cards.Count);
- CardBox3.GetComponent<InputField>().text = Cards[newRandom4];
- Cards.RemoveAt(newRandom4);
- CardsCount -= 1;
- yield return new WaitForSeconds(0.5f);
- int newRandom5 = Random.Range(0, Cards.Count);
- CardBox4.GetComponent<InputField>().text = Cards[newRandom5];
- Cards.RemoveAt(newRandom5);
- CardsCount -= 1;
- yield return new WaitForSeconds(0.5f);
- if (timesLeft < 2)
- {
- DiscardButton.gameObject.SetActive(true);
- DiscardButton1.gameObject.SetActive(true);
- DiscardButton2.gameObject.SetActive(true);
- DiscardButton3.gameObject.SetActive(true);
- DiscardButton4.gameObject.SetActive(true);
- } else if (timesLeft >= 2)
- {
- DiscardButton.gameObject.SetActive(false);
- DiscardButton1.gameObject.SetActive(false);
- DiscardButton2.gameObject.SetActive(false);
- DiscardButton3.gameObject.SetActive(false);
- DiscardButton4.gameObject.SetActive(false);
- }
- }
- public IEnumerator GiveCardsTake()
- {
- TakeCardsButton.GetComponent<Button>().interactable = false;
- yield return new WaitForSeconds(0.5f);
- if (isEmpty)
- {
- int newRandom1 = Random.Range(0, Cards.Count);
- CardBox.GetComponent<InputField>().text = Cards[newRandom1];
- Cards.RemoveAt(newRandom1);
- isEmpty = false;
- CardsCount -= 1;
- yield return new WaitForSeconds(0.5f);
- }
- if (isEmpty1)
- {
- int newRandom1 = Random.Range(0, Cards.Count);
- CardBox1.GetComponent<InputField>().text = Cards[newRandom1];
- Cards.RemoveAt(newRandom1);
- isEmpty1 = false;
- CardsCount -= 1;
- yield return new WaitForSeconds(0.5f);
- }
- if (isEmpty2)
- {
- int newRandom1 = Random.Range(0, Cards.Count);
- CardBox2.GetComponent<InputField>().text = Cards[newRandom1];
- Cards.RemoveAt(newRandom1);
- isEmpty2 = false;
- CardsCount -= 1;
- yield return new WaitForSeconds(0.5f);
- }
- if (isEmpty3)
- {
- int newRandom1 = Random.Range(0, Cards.Count);
- CardBox3.GetComponent<InputField>().text = Cards[newRandom1];
- Cards.RemoveAt(newRandom1);
- isEmpty3 = false;
- CardsCount -= 1;
- yield return new WaitForSeconds(0.5f);
- }
- if (isEmpty4)
- {
- int newRandom1 = Random.Range(0, Cards.Count);
- CardBox4.GetComponent<InputField>().text = Cards[newRandom1];
- Cards.RemoveAt(newRandom1);
- isEmpty4 = false;
- CardsCount -= 1;
- yield return new WaitForSeconds(0.5f);
- }
- if (timesLeft < 2)
- {
- DiscardButton.gameObject.SetActive(true);
- DiscardButton1.gameObject.SetActive(true);
- DiscardButton2.gameObject.SetActive(true);
- DiscardButton3.gameObject.SetActive(true);
- DiscardButton4.gameObject.SetActive(true);
- }
- else if (timesLeft >= 2)
- {
- DiscardButton.gameObject.SetActive(false);
- DiscardButton1.gameObject.SetActive(false);
- DiscardButton2.gameObject.SetActive(false);
- DiscardButton3.gameObject.SetActive(false);
- DiscardButton4.gameObject.SetActive(false);
- }
- }
- public void Reset ()
- {
- CardsCount = 52;
- DiscardedCardsCount = 0;
- NewList();
- NewHandButton.GetComponent<Button>().interactable = true;
- TakeCardsButton.GetComponent<Button>().interactable = false;
- CardBox.GetComponent<InputField>().text = "";
- CardBox1.GetComponent<InputField>().text = "";
- CardBox2.GetComponent<InputField>().text = "";
- CardBox3.GetComponent<InputField>().text = "";
- CardBox4.GetComponent<InputField>().text = "";
- DiscardButton.gameObject.SetActive(false);
- DiscardButton1.gameObject.SetActive(false);
- DiscardButton2.gameObject.SetActive(false);
- DiscardButton3.gameObject.SetActive(false);
- DiscardButton4.gameObject.SetActive(false);
- isEmpty = true;
- isEmpty1 = true;
- isEmpty2 = true;
- isEmpty3 = true;
- isEmpty4 = true;
- timesLeft = 0;
- }
- public void TakeCards ()
- {
- StartCoroutine(GiveCardsTake());
- timesLeft += 1;
- }
- public void Discard ()
- {
- CardBox.GetComponent<InputField>().text = "";
- DiscardButton.gameObject.SetActive(false);
- DiscardedCardsCount += 1;
- isEmpty = true;
- TakeCardsButton.GetComponent<Button>().interactable = true;
- }
- public void Discard1()
- {
- CardBox1.GetComponent<InputField>().text = "";
- DiscardButton1.gameObject.SetActive(false);
- DiscardedCardsCount += 1;
- isEmpty1 = true;
- TakeCardsButton.GetComponent<Button>().interactable = true;
- }
- public void Discard2()
- {
- CardBox2.GetComponent<InputField>().text = "";
- DiscardButton2.gameObject.SetActive(false);
- DiscardedCardsCount += 1;
- isEmpty2 = true;
- TakeCardsButton.GetComponent<Button>().interactable = true;
- }
- public void Discard3()
- {
- CardBox3.GetComponent<InputField>().text = "";
- DiscardButton3.gameObject.SetActive(false);
- DiscardedCardsCount += 1;
- isEmpty3 = true;
- TakeCardsButton.GetComponent<Button>().interactable = true;
- }
- public void Discard4()
- {
- CardBox4.GetComponent<InputField>().text = "";
- DiscardButton4.gameObject.SetActive(false);
- DiscardedCardsCount += 1;
- isEmpty4 = true;
- TakeCardsButton.GetComponent<Button>().interactable = true;
- }
- void NewList()
- {
- Cards.Add ("2s");
- Cards.Add ("2h");
- Cards.Add ("2d");
- Cards.Add ("2c");
- Cards.Add ("3s");
- Cards.Add ("3h");
- Cards.Add ("3d");
- Cards.Add ("3c");
- Cards.Add ("4s");
- Cards.Add ("4h");
- Cards.Add ("4d");
- Cards.Add ("4c");
- Cards.Add ("5s");
- Cards.Add ("5h");
- Cards.Add ("5d");
- Cards.Add ("5c");
- Cards.Add ("6s");
- Cards.Add ("6h");
- Cards.Add ("6d");
- Cards.Add ("6c");
- Cards.Add ("7s");
- Cards.Add ("7h");
- Cards.Add ("7d");
- Cards.Add ("7c");
- Cards.Add ("8s");
- Cards.Add ("8h");
- Cards.Add ("8d");
- Cards.Add ("8c");
- Cards.Add ("9s");
- Cards.Add ("9h");
- Cards.Add ("9d");
- Cards.Add ("9c");
- Cards.Add ("10s");
- Cards.Add ("10h");
- Cards.Add ("10d");
- Cards.Add ("10c");
- Cards.Add ("Js");
- Cards.Add ("Jh");
- Cards.Add ("Jd");
- Cards.Add ("Jc");
- Cards.Add ("Qs");
- Cards.Add ("Qh");
- Cards.Add ("Qd");
- Cards.Add ("Qc");
- Cards.Add ("Ks");
- Cards.Add ("Kh");
- Cards.Add ("Kd");
- Cards.Add ("Kc");
- Cards.Add ("As");
- Cards.Add ("Ah");
- Cards.Add ("Ad");
- Cards.Add ("Ac");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment