ManaMiniGame.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Serialization;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using Random = UnityEngine.Random;
  8. public class ManaMiniGame : MonoBehaviour
  9. {
  10. #region 变量
  11. #region Game
  12. public static int Score
  13. {
  14. get { return _Score; }
  15. set
  16. {
  17. _Score = value;
  18. ScoreLab.text = _Score.ToString();
  19. }
  20. }
  21. public static float Timer
  22. {
  23. get { return _Timer; }
  24. set
  25. {
  26. _Timer = value;
  27. TimerBk.fillAmount = _Timer / GameTime;
  28. TimerLab.text = _Timer.ToString("0.0");
  29. }
  30. }
  31. public static bool Game
  32. {
  33. get { return _Game; }
  34. set
  35. {
  36. _Game = value;
  37. if (_Game)
  38. {
  39. StatusLab.text = "进行中";
  40. }
  41. else
  42. {
  43. StatusLab.text = "未开始";
  44. }
  45. }
  46. }
  47. public static bool Pause
  48. {
  49. get { return _Pause; }
  50. set
  51. {
  52. _Pause = value;
  53. if (Game)
  54. {
  55. if (_Pause)
  56. {
  57. StatusLab.text = "已暂停";
  58. }
  59. else
  60. {
  61. StatusLab.text = "进行中";
  62. }
  63. }
  64. }
  65. }
  66. public static bool Panalty
  67. {
  68. get { return _Panalty; }
  69. set
  70. {
  71. _Panalty = value;
  72. if (_Panalty)
  73. {
  74. StatusLab.text = "操作被冻结";
  75. }
  76. else
  77. {
  78. StatusLab.text = "进行中";
  79. }
  80. }
  81. }
  82. private static int _Score;
  83. private static float _Timer;
  84. private static bool _Game;
  85. private static bool _Pause;
  86. private static bool _Panalty;
  87. public static List<Flower> OpList;
  88. public static List<Flower> IdleList;
  89. private static float OpTime;
  90. private static float GameTime;
  91. private static float PenaltyTime;
  92. private static float OpTimer;
  93. private static float PenaltyTimer;
  94. private static Text ScoreLab;
  95. private static Text TimerLab;
  96. private static Text StatusLab;
  97. private static Image TimerBk;
  98. #endregion
  99. #endregion
  100. private void Awake()
  101. {
  102. Initializer.RegistValue += RegistValue;
  103. Initializer.RegistReference += RegistReference;
  104. }
  105. private void FixedUpdate()
  106. {
  107. #region 小游戏A
  108. if (!Game || Pause)
  109. {
  110. return;
  111. }
  112. Timer -= Time.fixedDeltaTime; //小游戏计时
  113. if (Timer <= 0)
  114. {
  115. GameOver();
  116. return; //小游戏结束
  117. }
  118. if (PenaltyTimer > 0) //冻结时间计时
  119. {
  120. PenaltyTimer -= Time.fixedDeltaTime;
  121. }
  122. OpTimer -= Time.fixedDeltaTime; //生成操作计时
  123. if (OpTimer <= 0)
  124. {
  125. if (IdleList.Count > 0)
  126. {
  127. OpTimer = OpTime;
  128. Flower flower = IdleList[Random.Range(0, IdleList.Count)];
  129. flower.CreateOp(OpList.Count);
  130. IdleList.Remove(flower);
  131. OpList.Add(flower);
  132. }
  133. }
  134. #endregion
  135. }
  136. private static void RegistValue()
  137. {
  138. OpTime = 1.5f;
  139. GameTime = 30;
  140. PenaltyTime = 1;
  141. Timer = GameTime;
  142. OpTimer = OpTime;
  143. ManaReso.Get("Game").CreateTweenCG(0f, 1f, 0.5f, false, true, Curve.EaseOutQuad);
  144. }
  145. private static void RegistReference()
  146. {
  147. TimerBk = ManaReso.Get<Image>("D_TimerBk2");
  148. TimerLab = ManaReso.Get<Text>("D_TimerLab");
  149. ScoreLab = ManaReso.Get<Text>("D_ScoreLab");
  150. StatusLab = ManaReso.Get<Text>("D_StatusLab");
  151. }
  152. #region 小游戏A
  153. public static void Rip()
  154. {
  155. if (PenaltyTimer > 0) //冻结操作
  156. {
  157. return;
  158. }
  159. if (OpList.Count > 0)
  160. {
  161. if (OpList[0].Operate(OpType.Rip)) //操作正确
  162. {
  163. IdleList.Add(OpList[0]);
  164. OpList.Remove(OpList[0]);
  165. SetOpStatus();
  166. }
  167. else //操作错误
  168. {
  169. PenaltyTimer = PenaltyTime;
  170. ManaMessage.Show("惩罚" + PenaltyTime + "秒", PenaltyTime);
  171. }
  172. }
  173. }
  174. public static void Water()
  175. {
  176. if (PenaltyTimer > 0) //冻结操作
  177. {
  178. return;
  179. }
  180. if (OpList.Count > 0)
  181. {
  182. if (OpList[0].Operate(OpType.Water)) //操作正确
  183. {
  184. IdleList.Add(OpList[0]);
  185. OpList.Remove(OpList[0]);
  186. SetOpStatus();
  187. }
  188. else //操作错误
  189. {
  190. PenaltyTimer = PenaltyTime;
  191. ManaMessage.Show("惩罚" + PenaltyTime + "秒", PenaltyTime);
  192. }
  193. }
  194. }
  195. public static void Fertilize()
  196. {
  197. if (PenaltyTimer > 0) //冻结操作
  198. {
  199. return;
  200. }
  201. if (OpList.Count > 0)
  202. {
  203. if (OpList[0].Operate(OpType.Fertilize)) //操作正确
  204. {
  205. IdleList.Add(OpList[0]);
  206. OpList.Remove(OpList[0]);
  207. SetOpStatus();
  208. }
  209. else //操作错误
  210. {
  211. PenaltyTimer = PenaltyTime;
  212. ManaMessage.Show("惩罚" + PenaltyTime + "秒", PenaltyTime);
  213. }
  214. }
  215. }
  216. public static void GameBegin()
  217. {
  218. ManaReso.Get("D_Rip1").SetActive(true);
  219. ManaReso.Get("D_Water1").SetActive(true);
  220. ManaReso.Get("D_Fertilize1").SetActive(true);
  221. ManaReso.Get("D_Begin").SetActive(false);
  222. Score = 0;
  223. Game = true;
  224. Pause = false;
  225. Timer = GameTime;
  226. for (int i = 0; i < IdleList.Count; i++)
  227. {
  228. IdleList[i].GameBegin();
  229. }
  230. OpList = new List<Flower>();
  231. }
  232. public static void GameAbort()
  233. {
  234. ManaReso.Get("D_Rip1").SetActive(false);
  235. ManaReso.Get("D_Water1").SetActive(false);
  236. ManaReso.Get("D_Fertilize1").SetActive(false);
  237. ManaReso.Get("D_Begin").SetActive(true);
  238. Score = 0;
  239. Game = false;
  240. Pause = false;
  241. Timer = GameTime;
  242. OpTimer = OpTime;
  243. for (int i = 0; i < IdleList.Count; i++)
  244. {
  245. IdleList[i].GameOver();
  246. }
  247. for (int i = 0; i < OpList.Count; i++)
  248. {
  249. OpList[i].GameOver();
  250. }
  251. }
  252. public static void GamePrepare()
  253. {
  254. IdleList = new List<Flower>();
  255. IdleList.Add(ManaReso.GetFlower(1, false, ManaReso.Get("FlowerGameTra1")));
  256. IdleList.Add(ManaReso.GetFlower(2, false, ManaReso.Get("FlowerGameTra2")));
  257. IdleList.Add(ManaReso.GetFlower(3, false, ManaReso.Get("FlowerGameTra3")));
  258. IdleList.Add(ManaReso.GetFlower(4, false, ManaReso.Get("FlowerGameTra4")));
  259. IdleList.Add(ManaReso.GetFlower(5, false, ManaReso.Get("FlowerGameTra5")));
  260. IdleList.Add(ManaReso.GetFlower(6, false, ManaReso.Get("FlowerGameTra6")));
  261. IdleList.Add(ManaReso.GetFlower(7, false, ManaReso.Get("FlowerGameTra7")));
  262. IdleList.Add(ManaReso.GetFlower(8, false, ManaReso.Get("FlowerGameTra8")));
  263. IdleList.Add(ManaReso.GetFlower(9, false, ManaReso.Get("FlowerGameTra9")));
  264. }
  265. private static void GameOver()
  266. {
  267. ManaReso.SetActive("D_Rip1", false);
  268. ManaReso.SetActive("D_Water1",false);
  269. ManaReso.SetActive("D_Fertilize1",false);
  270. ManaReso.SetActive("D_Begin",true);
  271. ManaReso.SetText("Da_Tit", "游戏结束");
  272. ManaReso.SetText("Da_Lab", "得分 : " + Score);
  273. ManaReso.SetActive("Da_Quit", false);
  274. ManaReso.SetActive("Da_Cancel", false);
  275. ManaReso.SetActive("Da_Info", true);
  276. ManaReso.SetActive("Da_GetAward", true);
  277. Score = 0;
  278. Game = false;
  279. Pause = false;
  280. Timer = GameTime;
  281. OpTimer = OpTime;
  282. for (int i = 0; i < IdleList.Count; i++)
  283. {
  284. IdleList[i].GameOver();
  285. }
  286. for (int i = 0; i < OpList.Count; i++)
  287. {
  288. OpList[i].GameOver();
  289. }
  290. IdleList.AddRange(OpList);
  291. }
  292. private static void SetOpStatus()
  293. {
  294. if (OpList.Count >= 2)
  295. {
  296. OpList[0].SetFirstOp();
  297. OpList[1].SetSecondOp();
  298. }
  299. else if (OpList.Count >= 1)
  300. {
  301. OpList[0].SetFirstOp();
  302. }
  303. }
  304. #endregion
  305. }