TimeLimitGameMode.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /**单人限时模式 */
  5. public class TimeLimitGameMode : GameMode {
  6. public static int[] distanceCanSelected = {10, 20, 30, 50, 70};
  7. public static int distance = 10;
  8. public float score = 0;
  9. int oneStarScore = 10;
  10. float time = 60;
  11. TargetBody targetBody;
  12. public TimeLimitGameMode(GameMgr gameMgr) : base(gameMgr) {
  13. //记录可射击的靶子
  14. targetBody = GameObject.Find("GameArea/TargetObject/TargetBody").GetComponent<TargetBody>();
  15. GameObject.FindObjectOfType<ArmBow>().validTargets.Add(targetBody);
  16. //添加游戏界面
  17. GameObject view = Resources.Load<GameObject>("Prefabs/Views/TimeLimitGameView");
  18. GameObject.Instantiate(view);
  19. BanBowReady();
  20. }
  21. public override void Start()
  22. {
  23. UnbanBowReady();
  24. GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/TimeLimitGameDistanceSelectView"));
  25. }
  26. public void ConfirmSelectedTargetDistance()
  27. {
  28. targetBody.SetDistance(distance);
  29. if (TimeLimitGameView.ins) TimeLimitGameView.ins.RenderHighestScoreByDistance(distance);
  30. TargetView.ins.Show(true);
  31. }
  32. public override void HitTarget(float score) {
  33. this.score += score;
  34. HitTargetNumber.Create(score);
  35. }
  36. public override bool DoNextShoot() {
  37. return !GameMgr.ins.gameOver;
  38. }
  39. public override object[] Settle() {
  40. int starCount = Mathf.FloorToInt(this.score / this.oneStarScore);
  41. float highestScore = 0;
  42. string distanceStr = distance.ToString();
  43. if (LoginMgr.myUserInfo.timeLimitGameScores.ContainsKey(distanceStr)) {
  44. highestScore = LoginMgr.myUserInfo.timeLimitGameScores[distanceStr];
  45. }
  46. if (this.score > highestScore) {
  47. LoginMgr.myUserInfo.timeLimitGameScores.Remove(distanceStr);
  48. LoginMgr.myUserInfo.timeLimitGameScores.Add(distanceStr, this.score);
  49. LoginMgr.myUserInfo.Save();
  50. }
  51. return new object[]{starCount, this.score};
  52. }
  53. public override void Update() {
  54. if (gameMgr.gameOver || pauseTimeCounting) return;
  55. if (this.time > 0) {
  56. if (GlobalData.pkMatchType == PKMatchType.None && UserSettings.ins.trainMode) {
  57. //单人且为训练模式,就不要倒计时了
  58. } else {
  59. this.time -= Time.deltaTime;
  60. }
  61. } else {
  62. this.time = 0;
  63. gameMgr.StopGame();
  64. //添加结算界面
  65. GameObject view = Resources.Load<GameObject>("Prefabs/Views/TimeLimitGameSettleView");
  66. GameObject.Instantiate(view);
  67. }
  68. }
  69. public string GetTimeStr()
  70. {
  71. int seconds = (int) Mathf.Ceil(this.time);
  72. string str = "";
  73. int m = seconds / 60;
  74. if (m < 10) {
  75. str += 0;
  76. }
  77. str += m;
  78. str += " : ";
  79. int s = seconds % 60;
  80. if (s < 10)
  81. {
  82. str += 0;
  83. }
  84. str += s;
  85. return str;
  86. }
  87. }