|
|
@@ -2,9 +2,8 @@
|
|
|
|
|
|
public class GameMgr : MonoBehaviour
|
|
|
{
|
|
|
- public static int gameMode = 1;
|
|
|
- public GameMode1 gameMode1;
|
|
|
- public GameMode2 gameMode2;
|
|
|
+ public static int gameType = 0;
|
|
|
+ public GameMode gameMode;
|
|
|
public bool gameOver = false;
|
|
|
|
|
|
public static GameMgr ins;
|
|
|
@@ -12,75 +11,18 @@ public class GameMgr : MonoBehaviour
|
|
|
void Start()
|
|
|
{
|
|
|
ins = this;
|
|
|
-
|
|
|
AudioMgr.init();
|
|
|
-
|
|
|
- this.initGameMode();
|
|
|
+ this.InitGameMode();
|
|
|
}
|
|
|
|
|
|
void FixedUpdate()
|
|
|
{
|
|
|
- if (this.gameMode2 != null)
|
|
|
- {
|
|
|
- this.gameMode2.UpdateTime(this);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- void initGameMode() {
|
|
|
- if (gameMode == 1)
|
|
|
- {
|
|
|
- this.gameMode1 = new GameMode1();
|
|
|
- this.gameMode1.init(this);
|
|
|
- }
|
|
|
- else if (gameMode == 2)
|
|
|
- {
|
|
|
- this.gameMode2 = new GameMode2();
|
|
|
- this.gameMode2.init(this);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void hitTarget(int score) {
|
|
|
- if (gameMode == 1)
|
|
|
- {
|
|
|
- this.gameMode1.hitTarget(this, score);
|
|
|
- }
|
|
|
- else if (gameMode == 2)
|
|
|
- {
|
|
|
- this.gameMode2.hitTarget(this, score);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public bool checkFinish() {
|
|
|
- if (gameMode == 1)
|
|
|
- {
|
|
|
- return this.gameMode1.checkFinish(this);
|
|
|
- }
|
|
|
- else if (gameMode == 2)
|
|
|
- {
|
|
|
- return this.gameMode2.checkFinish(this);
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- public GameWinResult GetGameWinResult()
|
|
|
- {
|
|
|
- if (gameMode == 1)
|
|
|
- {
|
|
|
- return gameMode1.getWinResult();
|
|
|
- }
|
|
|
- else if (gameMode == 2)
|
|
|
- {
|
|
|
- return gameMode2.getWinResult();
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- public void Pause() {
|
|
|
- Time.timeScale = 0;
|
|
|
+ gameMode.Update();
|
|
|
}
|
|
|
|
|
|
- public void Resume() {
|
|
|
- Time.timeScale = 1;
|
|
|
+ void InitGameMode() {
|
|
|
+ if (gameType == 0) gameMode = new GameModeTest(this);
|
|
|
+ if (gameType == 1) gameMode = new GameMode1(this);
|
|
|
}
|
|
|
|
|
|
public void StopGame() {
|
|
|
@@ -97,137 +39,74 @@ public class GameMgr : MonoBehaviour
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/**闯关模式 */
|
|
|
-public class GameMode1 {
|
|
|
- public static int level;
|
|
|
- public int arrowCount = 3;
|
|
|
- public int arrowCountMax = 3;
|
|
|
- public int score = 0;
|
|
|
- public int oneStarScore = 8;
|
|
|
- public bool finish;
|
|
|
-
|
|
|
- public void init(GameMgr gameMgr) {
|
|
|
- GameObject gv1 = Resources.Load<GameObject>("Prefabs/Views/ChallengeGameView");
|
|
|
- GameObject.Instantiate(gv1, Vector3.zero, new Quaternion());
|
|
|
-
|
|
|
- //debug
|
|
|
- TargetBody tb = GameObject.Find("GameArea/010/TargetBody").GetComponent<TargetBody>();
|
|
|
- // TargetBody tb1 = GameObject.Find("GameArea/010 (1)/TargetBody").GetComponent<TargetBody>();
|
|
|
- // TargetBody tb2 = GameObject.Find("GameArea/010 (2)/TargetBody").GetComponent<TargetBody>();
|
|
|
- GameObject.Find("Main Camera/ArmBow").GetComponent<ArmBow>().validTargets.Add(tb);
|
|
|
- // GameObject.Find("Main Camera/ArmBow").GetComponent<ArmBow>().validTargets.Add(tb1);
|
|
|
- // GameObject.Find("Main Camera/ArmBow").GetComponent<ArmBow>().validTargets.Add(tb2);
|
|
|
- }
|
|
|
-
|
|
|
- public void hitTarget(GameMgr gameMgr, int score) {
|
|
|
- // this.score += score;
|
|
|
- // this.arrowCount -= 1;
|
|
|
- }
|
|
|
-
|
|
|
- public bool checkFinish(GameMgr gameMgr) {
|
|
|
- if (this.finish) return true;
|
|
|
- if (this.arrowCount <= 0) {
|
|
|
- this.finish = true;
|
|
|
- gameMgr.gameOver = true;
|
|
|
- gameMgr.StopGame();
|
|
|
- GameObject gwv1 = Resources.Load<GameObject>("Prefabs/Views/GameResultView");
|
|
|
- GameObject.Instantiate(gwv1, Vector3.zero, new Quaternion());
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
+public abstract class GameMode
|
|
|
+{
|
|
|
+ public GameMgr gameMgr;
|
|
|
+ public GameMode(GameMgr gameMgr) {
|
|
|
+ this.gameMgr = gameMgr;
|
|
|
}
|
|
|
+ public abstract void HitTarget(int score);
|
|
|
+ public abstract object[] Settle();
|
|
|
+ public virtual void Update() {}
|
|
|
+}
|
|
|
|
|
|
- public GameWinResult getWinResult() {
|
|
|
- GameWinResult result = new GameWinResult();
|
|
|
- result.starCount = this.score / this.oneStarScore;
|
|
|
- result.score = this.score;
|
|
|
- string key = "Challenge_Star_";
|
|
|
- int star = PlayerPrefs.GetInt(key + level, 0);
|
|
|
- if (result.starCount > star)
|
|
|
- {
|
|
|
- PlayerPrefs.SetInt(key + level, result.starCount);
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
+public class GameModeTest : GameMode {
|
|
|
+ public GameModeTest(GameMgr gameMgr) : base(gameMgr) {}
|
|
|
+ public override void HitTarget(int score) {}
|
|
|
+ public override object[] Settle() { return null; }
|
|
|
}
|
|
|
|
|
|
-/**限时模式 */
|
|
|
-public class GameMode2 {
|
|
|
- public int hitCount = 0;
|
|
|
+/**单人限时模式 */
|
|
|
+public class GameMode1 : GameMode {
|
|
|
public int score = 0;
|
|
|
- public int oneStarScore = 10;
|
|
|
- public float time = 60;
|
|
|
- public bool finish;
|
|
|
-
|
|
|
- public void init(GameMgr gameMgr) {
|
|
|
- GameObject gv1 = Resources.Load<GameObject>("Prefabs/Views/TimeLimitGameView");
|
|
|
- GameObject.Instantiate(gv1, Vector3.zero, new Quaternion());
|
|
|
+ int oneStarScore = 10;
|
|
|
+ float time = 60;
|
|
|
|
|
|
- TargetBody tb = GameObject.Find("GameArea/010/TargetBody").GetComponent<TargetBody>();
|
|
|
- GameObject.Find("Main Camera/ArmBow").GetComponent<ArmBow>().validTargets.Add(tb);
|
|
|
+ public GameMode1(GameMgr gameMgr) : base(gameMgr)
|
|
|
+ {
|
|
|
+ //添加游戏界面
|
|
|
+ GameObject view = Resources.Load<GameObject>("Prefabs/Views/TimeLimitGameView");
|
|
|
+ GameObject.Instantiate(view);
|
|
|
+ //记录可射击的靶子
|
|
|
+ TargetBody targetBody = GameObject.Find("GameArea/010/TargetBody").GetComponent<TargetBody>();
|
|
|
+ GameObject.Find("Main Camera/ArmBow").GetComponent<ArmBow>().validTargets.Add(targetBody);
|
|
|
}
|
|
|
|
|
|
- public void hitTarget(GameMgr gameMgr, int score) {
|
|
|
+ public override void HitTarget(int score) {
|
|
|
this.score += score;
|
|
|
- this.hitCount++;
|
|
|
- }
|
|
|
-
|
|
|
- public bool checkFinish(GameMgr gameMgr) {
|
|
|
- return this.finish;
|
|
|
}
|
|
|
|
|
|
- public GameWinResult getWinResult() {
|
|
|
- GameWinResult result = new GameWinResult();
|
|
|
- result.starCount = this.score / this.oneStarScore;
|
|
|
- result.score = this.score;
|
|
|
- string keyLowest = "TimeLimitGameLowestScore";
|
|
|
- string keyHighest = "TimeLimitGameHighestScore";
|
|
|
- string keyLowestHitCount = "TimeLimitGameLowestHitCount";
|
|
|
- string keyHighestHitCount = "TimeLimitGameHighestHitCount";
|
|
|
- int lowestScore = PlayerPrefs.GetInt(keyLowest, -1);
|
|
|
- int highestScore = PlayerPrefs.GetInt(keyHighest, -1);
|
|
|
- if (lowestScore == -1 || result.score < lowestScore) {
|
|
|
- PlayerPrefs.SetInt(keyLowest, result.score);
|
|
|
- PlayerPrefs.SetInt(keyLowestHitCount, hitCount);
|
|
|
- }
|
|
|
- if (highestScore == -1 || result.score > highestScore) {
|
|
|
- PlayerPrefs.SetInt(keyHighest, result.score);
|
|
|
- PlayerPrefs.SetInt(keyHighestHitCount, hitCount);
|
|
|
+ public override object[] Settle() {
|
|
|
+ int starCount = this.score / this.oneStarScore;
|
|
|
+ string highestScoreKey = "TimeLimitGameHighestScore";
|
|
|
+ int highestScore = PlayerPrefs.GetInt(highestScoreKey, 0);
|
|
|
+ if (this.score > highestScore) {
|
|
|
+ PlayerPrefs.SetInt(highestScoreKey, this.score);
|
|
|
}
|
|
|
- return result;
|
|
|
+ return new object[]{starCount, this.score};
|
|
|
}
|
|
|
|
|
|
- public int[] GetScores()
|
|
|
- {
|
|
|
- int[] scores = new int[4];
|
|
|
- string keyLowest = "TimeLimitGameLowestScore";
|
|
|
- string keyHighest = "TimeLimitGameHighestScore";
|
|
|
- string keyLowestHitCount = "TimeLimitGameLowestHitCount";
|
|
|
- string keyHighestHitCount = "TimeLimitGameHighestHitCount";
|
|
|
- scores[0] = PlayerPrefs.GetInt(keyHighestHitCount, 0);
|
|
|
- scores[1] = PlayerPrefs.GetInt(keyHighest, 0);
|
|
|
- scores[2] = PlayerPrefs.GetInt(keyLowestHitCount, 0);
|
|
|
- scores[3] = PlayerPrefs.GetInt(keyLowest, 0);
|
|
|
- return scores;
|
|
|
- }
|
|
|
-
|
|
|
- public void UpdateTime(GameMgr gameMgr) {
|
|
|
- if (this.finish) return;
|
|
|
+ public override void Update() {
|
|
|
+ if (gameMgr.gameOver) return;
|
|
|
if (this.time > 0) {
|
|
|
this.time -= Time.deltaTime;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
this.time = 0;
|
|
|
- this.finish = true;
|
|
|
gameMgr.gameOver = true;
|
|
|
gameMgr.StopGame();
|
|
|
- GameObject gwv1 = Resources.Load<GameObject>("Prefabs/Views/GameResultView");
|
|
|
- GameObject.Instantiate(gwv1, Vector3.zero, new Quaternion());
|
|
|
+ //添加结算界面
|
|
|
+ GameObject view = Resources.Load<GameObject>("Prefabs/Views/GameSettleView1");
|
|
|
+ GameObject.Instantiate(view);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public string getTimeStr()
|
|
|
+ public int GetHighestScore()
|
|
|
+ {
|
|
|
+ string highestScoreKey = "TimeLimitGameHighestScore";
|
|
|
+ return PlayerPrefs.GetInt(highestScoreKey, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ public string GetTimeStr()
|
|
|
{
|
|
|
int seconds = Mathf.FloorToInt(this.time);
|
|
|
string str = "";
|
|
|
@@ -245,10 +124,4 @@ public class GameMode2 {
|
|
|
str += s;
|
|
|
return str;
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-public class GameWinResult {
|
|
|
- public int starCount;
|
|
|
- public int score;
|
|
|
}
|