TeHArGiS10

Untitled

Apr 10th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.55 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5.  
  6. public class CardSystem : MonoBehaviour {
  7.  
  8. public List<string> Cards = new List<string>();
  9. public int CardsCount;
  10. public int DiscardedCardsCount;
  11. public int timesLeft;
  12.  
  13. public bool isEmpty = false;
  14. public bool isEmpty1 = false;
  15. public bool isEmpty2 = false;
  16. public bool isEmpty3 = false;
  17. public bool isEmpty4 = false;
  18.  
  19. public GameObject TotalCards;
  20. public GameObject DiscardedCards;
  21. public GameObject NewHandButton;
  22. public GameObject TakeCardsButton;
  23. public GameObject CardBox;
  24. public GameObject CardBox1;
  25. public GameObject CardBox2;
  26. public GameObject CardBox3;
  27. public GameObject CardBox4;
  28. public GameObject DiscardButton;
  29. public GameObject DiscardButton1;
  30. public GameObject DiscardButton2;
  31. public GameObject DiscardButton3;
  32. public GameObject DiscardButton4;
  33.  
  34. void Start ()
  35. {
  36. CardsCount = 52;
  37. DiscardedCardsCount = 0;
  38. timesLeft = 0;
  39. NewList();
  40.  
  41. DiscardButton.gameObject.SetActive(false);
  42. DiscardButton1.gameObject.SetActive(false);
  43. DiscardButton2.gameObject.SetActive(false);
  44. DiscardButton3.gameObject.SetActive(false);
  45. DiscardButton4.gameObject.SetActive(false);
  46.  
  47. TakeCardsButton.GetComponent<Button>().interactable = false;
  48.  
  49. isEmpty = true;
  50. isEmpty1 = true;
  51. isEmpty2 = true;
  52. isEmpty3 = true;
  53. isEmpty4 = true;
  54. }
  55.  
  56. void Update ()
  57. {
  58. TotalCards.GetComponent<InputField>().text = CardsCount.ToString();
  59. DiscardedCards.GetComponent<InputField>().text = DiscardedCardsCount.ToString();
  60. }
  61.  
  62. public void NewHand ()
  63. {
  64. StartCoroutine(GiveCardsNew());
  65. NewHandButton.GetComponent<Button>().interactable = false;
  66. isEmpty = false;
  67. isEmpty1 = false;
  68. isEmpty2 = false;
  69. isEmpty3 = false;
  70. isEmpty4 = false;
  71. }
  72.  
  73. public IEnumerator GiveCardsNew()
  74. {
  75. CardBox.GetComponent<InputField>().text = "";
  76. CardBox1.GetComponent<InputField>().text = "";
  77. CardBox2.GetComponent<InputField>().text = "";
  78. CardBox3.GetComponent<InputField>().text = "";
  79. CardBox4.GetComponent<InputField>().text = "";
  80. yield return new WaitForSeconds(0.5f);
  81.  
  82. int newRandom1 = Random.Range(0, Cards.Count);
  83. CardBox.GetComponent<InputField>().text = Cards[newRandom1];
  84. Cards.RemoveAt(newRandom1);
  85. CardsCount -= 1;
  86. yield return new WaitForSeconds(0.5f);
  87.  
  88. int newRandom2 = Random.Range(0, Cards.Count);
  89. CardBox1.GetComponent<InputField>().text = Cards[newRandom2];
  90. Cards.RemoveAt(newRandom2);
  91. CardsCount -= 1;
  92. yield return new WaitForSeconds(0.5f);
  93.  
  94. int newRandom3 = Random.Range(0, Cards.Count);
  95. CardBox2.GetComponent<InputField>().text = Cards[newRandom3];
  96. Cards.RemoveAt(newRandom3);
  97. CardsCount -= 1;
  98. yield return new WaitForSeconds(0.5f);
  99.  
  100. int newRandom4 = Random.Range(0, Cards.Count);
  101. CardBox3.GetComponent<InputField>().text = Cards[newRandom4];
  102. Cards.RemoveAt(newRandom4);
  103. CardsCount -= 1;
  104. yield return new WaitForSeconds(0.5f);
  105.  
  106. int newRandom5 = Random.Range(0, Cards.Count);
  107. CardBox4.GetComponent<InputField>().text = Cards[newRandom5];
  108. Cards.RemoveAt(newRandom5);
  109. CardsCount -= 1;
  110. yield return new WaitForSeconds(0.5f);
  111.  
  112. if (timesLeft < 2)
  113. {
  114. DiscardButton.gameObject.SetActive(true);
  115. DiscardButton1.gameObject.SetActive(true);
  116. DiscardButton2.gameObject.SetActive(true);
  117. DiscardButton3.gameObject.SetActive(true);
  118. DiscardButton4.gameObject.SetActive(true);
  119. } else if (timesLeft >= 2)
  120. {
  121. DiscardButton.gameObject.SetActive(false);
  122. DiscardButton1.gameObject.SetActive(false);
  123. DiscardButton2.gameObject.SetActive(false);
  124. DiscardButton3.gameObject.SetActive(false);
  125. DiscardButton4.gameObject.SetActive(false);
  126. }
  127. }
  128.  
  129. public IEnumerator GiveCardsTake()
  130. {
  131. TakeCardsButton.GetComponent<Button>().interactable = false;
  132. yield return new WaitForSeconds(0.5f);
  133.  
  134. if (isEmpty)
  135. {
  136. int newRandom1 = Random.Range(0, Cards.Count);
  137. CardBox.GetComponent<InputField>().text = Cards[newRandom1];
  138. Cards.RemoveAt(newRandom1);
  139. isEmpty = false;
  140. CardsCount -= 1;
  141. yield return new WaitForSeconds(0.5f);
  142. }
  143. if (isEmpty1)
  144. {
  145. int newRandom1 = Random.Range(0, Cards.Count);
  146. CardBox1.GetComponent<InputField>().text = Cards[newRandom1];
  147. Cards.RemoveAt(newRandom1);
  148. isEmpty1 = false;
  149. CardsCount -= 1;
  150. yield return new WaitForSeconds(0.5f);
  151. }
  152. if (isEmpty2)
  153. {
  154. int newRandom1 = Random.Range(0, Cards.Count);
  155. CardBox2.GetComponent<InputField>().text = Cards[newRandom1];
  156. Cards.RemoveAt(newRandom1);
  157. isEmpty2 = false;
  158. CardsCount -= 1;
  159. yield return new WaitForSeconds(0.5f);
  160. }
  161. if (isEmpty3)
  162. {
  163. int newRandom1 = Random.Range(0, Cards.Count);
  164. CardBox3.GetComponent<InputField>().text = Cards[newRandom1];
  165. Cards.RemoveAt(newRandom1);
  166. isEmpty3 = false;
  167. CardsCount -= 1;
  168. yield return new WaitForSeconds(0.5f);
  169. }
  170. if (isEmpty4)
  171. {
  172. int newRandom1 = Random.Range(0, Cards.Count);
  173. CardBox4.GetComponent<InputField>().text = Cards[newRandom1];
  174. Cards.RemoveAt(newRandom1);
  175. isEmpty4 = false;
  176. CardsCount -= 1;
  177. yield return new WaitForSeconds(0.5f);
  178. }
  179.  
  180. if (timesLeft < 2)
  181. {
  182. DiscardButton.gameObject.SetActive(true);
  183. DiscardButton1.gameObject.SetActive(true);
  184. DiscardButton2.gameObject.SetActive(true);
  185. DiscardButton3.gameObject.SetActive(true);
  186. DiscardButton4.gameObject.SetActive(true);
  187. }
  188. else if (timesLeft >= 2)
  189. {
  190. DiscardButton.gameObject.SetActive(false);
  191. DiscardButton1.gameObject.SetActive(false);
  192. DiscardButton2.gameObject.SetActive(false);
  193. DiscardButton3.gameObject.SetActive(false);
  194. DiscardButton4.gameObject.SetActive(false);
  195. }
  196. }
  197.  
  198. public void Reset ()
  199. {
  200. CardsCount = 52;
  201. DiscardedCardsCount = 0;
  202. NewList();
  203. NewHandButton.GetComponent<Button>().interactable = true;
  204. TakeCardsButton.GetComponent<Button>().interactable = false;
  205.  
  206. CardBox.GetComponent<InputField>().text = "";
  207. CardBox1.GetComponent<InputField>().text = "";
  208. CardBox2.GetComponent<InputField>().text = "";
  209. CardBox3.GetComponent<InputField>().text = "";
  210. CardBox4.GetComponent<InputField>().text = "";
  211.  
  212. DiscardButton.gameObject.SetActive(false);
  213. DiscardButton1.gameObject.SetActive(false);
  214. DiscardButton2.gameObject.SetActive(false);
  215. DiscardButton3.gameObject.SetActive(false);
  216. DiscardButton4.gameObject.SetActive(false);
  217.  
  218. isEmpty = true;
  219. isEmpty1 = true;
  220. isEmpty2 = true;
  221. isEmpty3 = true;
  222. isEmpty4 = true;
  223.  
  224. timesLeft = 0;
  225. }
  226.  
  227. public void TakeCards ()
  228. {
  229. StartCoroutine(GiveCardsTake());
  230. timesLeft += 1;
  231. }
  232.  
  233. public void Discard ()
  234. {
  235. CardBox.GetComponent<InputField>().text = "";
  236. DiscardButton.gameObject.SetActive(false);
  237. DiscardedCardsCount += 1;
  238. isEmpty = true;
  239. TakeCardsButton.GetComponent<Button>().interactable = true;
  240. }
  241.  
  242. public void Discard1()
  243. {
  244. CardBox1.GetComponent<InputField>().text = "";
  245. DiscardButton1.gameObject.SetActive(false);
  246. DiscardedCardsCount += 1;
  247. isEmpty1 = true;
  248. TakeCardsButton.GetComponent<Button>().interactable = true;
  249. }
  250.  
  251. public void Discard2()
  252. {
  253. CardBox2.GetComponent<InputField>().text = "";
  254. DiscardButton2.gameObject.SetActive(false);
  255. DiscardedCardsCount += 1;
  256. isEmpty2 = true;
  257. TakeCardsButton.GetComponent<Button>().interactable = true;
  258. }
  259.  
  260. public void Discard3()
  261. {
  262. CardBox3.GetComponent<InputField>().text = "";
  263. DiscardButton3.gameObject.SetActive(false);
  264. DiscardedCardsCount += 1;
  265. isEmpty3 = true;
  266. TakeCardsButton.GetComponent<Button>().interactable = true;
  267. }
  268.  
  269. public void Discard4()
  270. {
  271. CardBox4.GetComponent<InputField>().text = "";
  272. DiscardButton4.gameObject.SetActive(false);
  273. DiscardedCardsCount += 1;
  274. isEmpty4 = true;
  275. TakeCardsButton.GetComponent<Button>().interactable = true;
  276. }
  277.  
  278. void NewList()
  279. {
  280. Cards.Add ("2s");
  281. Cards.Add ("2h");
  282. Cards.Add ("2d");
  283. Cards.Add ("2c");
  284.  
  285. Cards.Add ("3s");
  286. Cards.Add ("3h");
  287. Cards.Add ("3d");
  288. Cards.Add ("3c");
  289.  
  290. Cards.Add ("4s");
  291. Cards.Add ("4h");
  292. Cards.Add ("4d");
  293. Cards.Add ("4c");
  294.  
  295. Cards.Add ("5s");
  296. Cards.Add ("5h");
  297. Cards.Add ("5d");
  298. Cards.Add ("5c");
  299.  
  300. Cards.Add ("6s");
  301. Cards.Add ("6h");
  302. Cards.Add ("6d");
  303. Cards.Add ("6c");
  304.  
  305. Cards.Add ("7s");
  306. Cards.Add ("7h");
  307. Cards.Add ("7d");
  308. Cards.Add ("7c");
  309.  
  310. Cards.Add ("8s");
  311. Cards.Add ("8h");
  312. Cards.Add ("8d");
  313. Cards.Add ("8c");
  314.  
  315. Cards.Add ("9s");
  316. Cards.Add ("9h");
  317. Cards.Add ("9d");
  318. Cards.Add ("9c");
  319.  
  320. Cards.Add ("10s");
  321. Cards.Add ("10h");
  322. Cards.Add ("10d");
  323. Cards.Add ("10c");
  324.  
  325. Cards.Add ("Js");
  326. Cards.Add ("Jh");
  327. Cards.Add ("Jd");
  328. Cards.Add ("Jc");
  329.  
  330. Cards.Add ("Qs");
  331. Cards.Add ("Qh");
  332. Cards.Add ("Qd");
  333. Cards.Add ("Qc");
  334.  
  335. Cards.Add ("Ks");
  336. Cards.Add ("Kh");
  337. Cards.Add ("Kd");
  338. Cards.Add ("Kc");
  339.  
  340. Cards.Add ("As");
  341. Cards.Add ("Ah");
  342. Cards.Add ("Ad");
  343. Cards.Add ("Ac");
  344. }
  345.  
  346. }
Advertisement
Add Comment
Please, Sign In to add comment