123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- 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 = "进行中";
- }
- else
- {
- StatusLab.text = "未开始";
- }
- }
- }
- public static bool Pause
- {
- get { return _Pause; }
- set
- {
- _Pause = value;
- if (Game)
- {
- if (_Pause)
- {
- StatusLab.text = "已暂停";
- }
- else
- {
- StatusLab.text = "进行中";
- }
- }
- }
- }
- public static bool Panalty
- {
- get { return _Panalty; }
- set
- {
- _Panalty = value;
- if (_Panalty)
- {
- StatusLab.text = "操作被冻结";
- }
- else
- {
- StatusLab.text = "进行中";
- }
- }
- }
- private static int _Score;
- private static float _Timer;
- private static bool _Game;
- private static bool _Pause;
- private static bool _Panalty;
- public static List<Flower> OpList;
- public static List<Flower> 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;
- }
- 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;
- ManaReso.Get("Game").CreateTweenCG(0f, 1f, 0.5f, false, true, Curve.EaseOutQuad);
- }
- private static void RegistReference()
- {
- TimerBk = ManaReso.Get<Image>("D_TimerBk2");
- TimerLab = ManaReso.Get<Text>("D_TimerLab");
- ScoreLab = ManaReso.Get<Text>("D_ScoreLab");
- StatusLab = ManaReso.Get<Text>("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 //操作错误
- {
- PenaltyTimer = PenaltyTime;
- ManaMessage.Show("惩罚" + PenaltyTime + "秒", 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 //操作错误
- {
- PenaltyTimer = PenaltyTime;
- ManaMessage.Show("惩罚" + PenaltyTime + "秒", 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 //操作错误
- {
- PenaltyTimer = PenaltyTime;
- ManaMessage.Show("惩罚" + PenaltyTime + "秒", 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<Flower>();
- }
- 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<Flower>();
- IdleList.Add(ManaReso.GetFlower(1, false, ManaReso.Get("FlowerGameTra1")));
- IdleList.Add(ManaReso.GetFlower(2, false, ManaReso.Get("FlowerGameTra2")));
- IdleList.Add(ManaReso.GetFlower(3, false, ManaReso.Get("FlowerGameTra3")));
- IdleList.Add(ManaReso.GetFlower(4, false, ManaReso.Get("FlowerGameTra4")));
- IdleList.Add(ManaReso.GetFlower(5, false, ManaReso.Get("FlowerGameTra5")));
- IdleList.Add(ManaReso.GetFlower(6, false, ManaReso.Get("FlowerGameTra6")));
- IdleList.Add(ManaReso.GetFlower(7, false, ManaReso.Get("FlowerGameTra7")));
- IdleList.Add(ManaReso.GetFlower(8, false, ManaReso.Get("FlowerGameTra8")));
- IdleList.Add(ManaReso.GetFlower(9, false, ManaReso.Get("FlowerGameTra9")));
- }
- 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
- }
|