ManaMiniGame.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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 = Language.GetStr("UI", "D_StatusLab1");
  40. }
  41. else
  42. {
  43. StatusLab.text = Language.GetStr("UI", "D_StatusLab0");
  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 = Language.GetStr("UI", "D_StatusLab2");
  58. }
  59. else
  60. {
  61. StatusLab.text = Language.GetStr("UI", "D_StatusLab1");
  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 = Language.GetStr("UI", "D_StatusLab3");
  75. }
  76. else
  77. {
  78. StatusLab.text = Language.GetStr("UI", "D_StatusLab1");
  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. if (PenaltyTimer <= 0)
  122. {
  123. Panalty = false;
  124. }
  125. }
  126. OpTimer -= Time.fixedDeltaTime; //生成操作计时
  127. if (OpTimer <= 0)
  128. {
  129. if (IdleList.Count > 0)
  130. {
  131. OpTimer = OpTime;
  132. Flower flower = IdleList[Random.Range(0, IdleList.Count)];
  133. flower.CreateOp(OpList.Count);
  134. IdleList.Remove(flower);
  135. OpList.Add(flower);
  136. }
  137. }
  138. #endregion
  139. }
  140. private static void RegistValue()
  141. {
  142. OpTime = 1.5f;
  143. GameTime = 30;
  144. PenaltyTime = 1;
  145. Timer = GameTime;
  146. OpTimer = OpTime;
  147. }
  148. private static void RegistReference()
  149. {
  150. TimerBk = ManaReso.Get<Image>("D_TimerIcon");
  151. TimerLab = ManaReso.Get<Text>("D_TimerLab");
  152. ScoreLab = ManaReso.Get<Text>("D_ScoreLab");
  153. StatusLab = ManaReso.Get<Text>("D_StatusLab");
  154. }
  155. #region 小游戏A
  156. public static void Rip()
  157. {
  158. if (PenaltyTimer > 0) //冻结操作
  159. {
  160. return;
  161. }
  162. if (OpList.Count > 0)
  163. {
  164. if (OpList[0].Operate(OpType.Rip)) //操作正确
  165. {
  166. IdleList.Add(OpList[0]);
  167. OpList.Remove(OpList[0]);
  168. SetOpStatus();
  169. }
  170. else //操作错误
  171. {
  172. Panalty = true;
  173. PenaltyTimer = PenaltyTime;
  174. ManaLog.Log(string.Format("惩罚<color=red>{0:0}</color>秒", PenaltyTime));
  175. }
  176. }
  177. }
  178. public static void Water()
  179. {
  180. if (PenaltyTimer > 0) //冻结操作
  181. {
  182. return;
  183. }
  184. if (OpList.Count > 0)
  185. {
  186. if (OpList[0].Operate(OpType.Water)) //操作正确
  187. {
  188. IdleList.Add(OpList[0]);
  189. OpList.Remove(OpList[0]);
  190. SetOpStatus();
  191. }
  192. else //操作错误
  193. {
  194. Panalty = true;
  195. PenaltyTimer = PenaltyTime;
  196. ManaLog.Log(string.Format("惩罚<color=red>{0:0}</color>秒", PenaltyTime));
  197. }
  198. }
  199. }
  200. public static void Fertilize()
  201. {
  202. if (PenaltyTimer > 0) //冻结操作
  203. {
  204. return;
  205. }
  206. if (OpList.Count > 0)
  207. {
  208. if (OpList[0].Operate(OpType.Fertilize)) //操作正确
  209. {
  210. IdleList.Add(OpList[0]);
  211. OpList.Remove(OpList[0]);
  212. SetOpStatus();
  213. }
  214. else //操作错误
  215. {
  216. Panalty = true;
  217. PenaltyTimer = PenaltyTime;
  218. ManaLog.Log(string.Format("惩罚<color=red>{0:0}</color>秒", PenaltyTime));
  219. }
  220. }
  221. }
  222. public static void GameBegin()
  223. {
  224. ManaReso.Get("D_Rip1").SetActive(true);
  225. ManaReso.Get("D_Water1").SetActive(true);
  226. ManaReso.Get("D_Fertilize1").SetActive(true);
  227. ManaReso.Get("D_Begin").SetActive(false);
  228. Score = 0;
  229. Game = true;
  230. Pause = false;
  231. Timer = GameTime;
  232. for (int i = 0; i < IdleList.Count; i++)
  233. {
  234. IdleList[i].GameBegin();
  235. }
  236. OpList = new List<Flower>();
  237. }
  238. public static void GameAbort()
  239. {
  240. ManaReso.Get("D_Rip1").SetActive(false);
  241. ManaReso.Get("D_Water1").SetActive(false);
  242. ManaReso.Get("D_Fertilize1").SetActive(false);
  243. ManaReso.Get("D_Begin").SetActive(true);
  244. Score = 0;
  245. Game = false;
  246. Pause = false;
  247. Timer = GameTime;
  248. OpTimer = OpTime;
  249. for (int i = 0; i < IdleList.Count; i++)
  250. {
  251. IdleList[i].GameOver();
  252. }
  253. for (int i = 0; i < OpList.Count; i++)
  254. {
  255. OpList[i].GameOver();
  256. }
  257. }
  258. public static void GamePrepare()
  259. {
  260. IdleList = new List<Flower>();
  261. OpList = new List<Flower>();
  262. IdleList.Add(ManaReso.GetFlower(1, false, ManaReso.Get("MiniTra1")));
  263. IdleList.Add(ManaReso.GetFlower(2, false, ManaReso.Get("MiniTra2")));
  264. IdleList.Add(ManaReso.GetFlower(3, false, ManaReso.Get("MiniTra3")));
  265. IdleList.Add(ManaReso.GetFlower(4, false, ManaReso.Get("MiniTra4")));
  266. IdleList.Add(ManaReso.GetFlower(5, false, ManaReso.Get("MiniTra5")));
  267. IdleList.Add(ManaReso.GetFlower(6, false, ManaReso.Get("MiniTra6")));
  268. IdleList.Add(ManaReso.GetFlower(7, false, ManaReso.Get("MiniTra7")));
  269. IdleList.Add(ManaReso.GetFlower(8, false, ManaReso.Get("MiniTra8")));
  270. IdleList.Add(ManaReso.GetFlower(9, false, ManaReso.Get("MiniTra9")));
  271. }
  272. private static void GameOver()
  273. {
  274. ManaReso.SetActive("D_Rip1", false);
  275. ManaReso.SetActive("D_Water1",false);
  276. ManaReso.SetActive("D_Fertilize1",false);
  277. ManaReso.SetActive("D_Begin",true);
  278. ManaReso.SetText("Da_Tit", "游戏结束");
  279. ManaReso.SetText("Da_Lab", "得分 : " + Score);
  280. ManaReso.SetActive("Da_Quit", false);
  281. ManaReso.SetActive("Da_Cancel", false);
  282. ManaReso.SetActive("Da_Info", true);
  283. ManaReso.SetActive("Da_GetAward", true);
  284. Score = 0;
  285. Game = false;
  286. Pause = false;
  287. Timer = GameTime;
  288. OpTimer = OpTime;
  289. for (int i = 0; i < IdleList.Count; i++)
  290. {
  291. IdleList[i].GameOver();
  292. }
  293. for (int i = 0; i < OpList.Count; i++)
  294. {
  295. OpList[i].GameOver();
  296. }
  297. IdleList.AddRange(OpList);
  298. }
  299. private static void SetOpStatus()
  300. {
  301. if (OpList.Count >= 2)
  302. {
  303. OpList[0].SetFirstOp();
  304. OpList[1].SetSecondOp();
  305. }
  306. else if (OpList.Count >= 1)
  307. {
  308. OpList[0].SetFirstOp();
  309. }
  310. }
  311. #endregion
  312. }