using UnityEngine; using UnityEngine.UI; using UnityEngine.Serialization; using System; using System.Collections; using System.Collections.Generic; using Random = UnityEngine.Random; public class ManaMiniGame : MonoBehaviour { #region 变量 #region Game public static int Score { get { return _Score; } set { _Score = value; ScoreLab.text = _Score.ToString(); } } public static float Timer { get { return _Timer; } set { _Timer = value; TimerBk.fillAmount = _Timer / GameTime; TimerLab.text = _Timer.ToString("0.0"); } } public static bool Game { get { return _Game; } set { _Game = value; if (_Game) { StatusLab.text = Language.GetStr("UI", "D_StatusLab1"); } else { StatusLab.text = Language.GetStr("UI", "D_StatusLab0"); } } } public static bool Pause { get { return _Pause; } set { _Pause = value; if (Game) { if (_Pause) { StatusLab.text = Language.GetStr("UI", "D_StatusLab2"); } else { StatusLab.text = Language.GetStr("UI", "D_StatusLab1"); } } } } public static bool Panalty { get { return _Panalty; } set { _Panalty = value; if (_Panalty) { StatusLab.text = Language.GetStr("UI", "D_StatusLab3"); } else { StatusLab.text = Language.GetStr("UI", "D_StatusLab1"); } } } private static int _Score; private static float _Timer; private static bool _Game; private static bool _Pause; private static bool _Panalty; public static List OpList; public static List IdleList; private static float OpTime; private static float GameTime; private static float PenaltyTime; private static float OpTimer; private static float PenaltyTimer; private static Text ScoreLab; private static Text TimerLab; private static Text StatusLab; private static Image TimerBk; #endregion #endregion private void Awake() { Initializer.RegistValue += RegistValue; Initializer.RegistReference += RegistReference; } private void FixedUpdate() { #region 小游戏A if (!Game || Pause) { return; } Timer -= Time.fixedDeltaTime; //小游戏计时 if (Timer <= 0) { GameOver(); return; //小游戏结束 } if (PenaltyTimer > 0) //冻结时间计时 { PenaltyTimer -= Time.fixedDeltaTime; if (PenaltyTimer <= 0) { Panalty = false; } } OpTimer -= Time.fixedDeltaTime; //生成操作计时 if (OpTimer <= 0) { if (IdleList.Count > 0) { OpTimer = OpTime; Flower flower = IdleList[Random.Range(0, IdleList.Count)]; flower.CreateOp(OpList.Count); IdleList.Remove(flower); OpList.Add(flower); } } #endregion } private static void RegistValue() { OpTime = 1.5f; GameTime = 30; PenaltyTime = 1; Timer = GameTime; OpTimer = OpTime; } private static void RegistReference() { TimerBk = ManaReso.Get("D_TimerIcon"); TimerLab = ManaReso.Get("D_TimerLab"); ScoreLab = ManaReso.Get("D_ScoreLab"); StatusLab = ManaReso.Get("D_StatusLab"); } #region 小游戏A public static void Rip() { if (PenaltyTimer > 0) //冻结操作 { return; } if (OpList.Count > 0) { if (OpList[0].Operate(OpType.Rip)) //操作正确 { IdleList.Add(OpList[0]); OpList.Remove(OpList[0]); SetOpStatus(); } else //操作错误 { Panalty = true; PenaltyTimer = PenaltyTime; ManaLog.Log(string.Format("惩罚{0:0}秒", PenaltyTime)); } } } public static void Water() { if (PenaltyTimer > 0) //冻结操作 { return; } if (OpList.Count > 0) { if (OpList[0].Operate(OpType.Water)) //操作正确 { IdleList.Add(OpList[0]); OpList.Remove(OpList[0]); SetOpStatus(); } else //操作错误 { Panalty = true; PenaltyTimer = PenaltyTime; ManaLog.Log(string.Format("惩罚{0:0}秒", PenaltyTime)); } } } public static void Fertilize() { if (PenaltyTimer > 0) //冻结操作 { return; } if (OpList.Count > 0) { if (OpList[0].Operate(OpType.Fertilize)) //操作正确 { IdleList.Add(OpList[0]); OpList.Remove(OpList[0]); SetOpStatus(); } else //操作错误 { Panalty = true; PenaltyTimer = PenaltyTime; ManaLog.Log(string.Format("惩罚{0:0}秒", PenaltyTime)); } } } public static void GameBegin() { ManaReso.Get("D_Rip1").SetActive(true); ManaReso.Get("D_Water1").SetActive(true); ManaReso.Get("D_Fertilize1").SetActive(true); ManaReso.Get("D_Begin").SetActive(false); Score = 0; Game = true; Pause = false; Timer = GameTime; for (int i = 0; i < IdleList.Count; i++) { IdleList[i].GameBegin(); } OpList = new List(); } public static void GameAbort() { ManaReso.Get("D_Rip1").SetActive(false); ManaReso.Get("D_Water1").SetActive(false); ManaReso.Get("D_Fertilize1").SetActive(false); ManaReso.Get("D_Begin").SetActive(true); Score = 0; Game = false; Pause = false; Timer = GameTime; OpTimer = OpTime; for (int i = 0; i < IdleList.Count; i++) { IdleList[i].GameOver(); } for (int i = 0; i < OpList.Count; i++) { OpList[i].GameOver(); } } public static void GamePrepare() { IdleList = new List(); OpList = new List(); IdleList.Add(ManaReso.GetFlower(1, false, ManaReso.Get("MiniTra1"))); IdleList.Add(ManaReso.GetFlower(2, false, ManaReso.Get("MiniTra2"))); IdleList.Add(ManaReso.GetFlower(3, false, ManaReso.Get("MiniTra3"))); IdleList.Add(ManaReso.GetFlower(4, false, ManaReso.Get("MiniTra4"))); IdleList.Add(ManaReso.GetFlower(5, false, ManaReso.Get("MiniTra5"))); IdleList.Add(ManaReso.GetFlower(6, false, ManaReso.Get("MiniTra6"))); IdleList.Add(ManaReso.GetFlower(7, false, ManaReso.Get("MiniTra7"))); IdleList.Add(ManaReso.GetFlower(8, false, ManaReso.Get("MiniTra8"))); IdleList.Add(ManaReso.GetFlower(9, false, ManaReso.Get("MiniTra9"))); } private static void GameOver() { ManaReso.SetActive("D_Rip1", false); ManaReso.SetActive("D_Water1",false); ManaReso.SetActive("D_Fertilize1",false); ManaReso.SetActive("D_Begin",true); ManaReso.SetText("Da_Tit", "游戏结束"); ManaReso.SetText("Da_Lab", "得分 : " + Score); ManaReso.SetActive("Da_Quit", false); ManaReso.SetActive("Da_Cancel", false); ManaReso.SetActive("Da_Info", true); ManaReso.SetActive("Da_GetAward", true); Score = 0; Game = false; Pause = false; Timer = GameTime; OpTimer = OpTime; for (int i = 0; i < IdleList.Count; i++) { IdleList[i].GameOver(); } for (int i = 0; i < OpList.Count; i++) { OpList[i].GameOver(); } IdleList.AddRange(OpList); } private static void SetOpStatus() { if (OpList.Count >= 2) { OpList[0].SetFirstOp(); OpList[1].SetSecondOp(); } else if (OpList.Count >= 1) { OpList[0].SetFirstOp(); } } #endregion }