Result.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. let webView = require("../WebView");
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. progressBar: {
  6. default: null,
  7. type: cc.Node,
  8. serializable: true,
  9. },
  10. score: {
  11. default: null,
  12. type: cc.Label,
  13. serializable: true,
  14. },
  15. result: {
  16. default: null,
  17. type: cc.Label,
  18. serializable: true,
  19. },
  20. beat: {
  21. default: null,
  22. type: cc.Label,
  23. serializable: true,
  24. },
  25. playTime: {
  26. default: null,
  27. type: cc.Label,
  28. serializable: true,
  29. },
  30. calorie: {
  31. default: null,
  32. type: cc.Label,
  33. serializable: true,
  34. }
  35. },
  36. //计算成功还是失败
  37. onEnd(data) {
  38. let { hit, miss, time, kCal } = data;
  39. // console.log(hit, miss, time, kCal);
  40. this.beat.string = hit;
  41. this.playTime.string = time;
  42. this.calorie.string = kCal;
  43. let allHit = hit + miss;
  44. let score = 60;
  45. if (allHit !== 0)
  46. {
  47. score = Math.ceil((hit / allHit) * 100);
  48. this.score.string = score;
  49. // console.log("打击率:", this.score);
  50. }
  51. else {
  52. this.score.string = 0;
  53. }
  54. this.progressBar.getComponent('ProgressBar').setValue(score/100);
  55. if (score >= 90)
  56. {
  57. this.result.string = '优秀';
  58. }
  59. else if (score >= 60 && this.score < 90)
  60. {
  61. this.result.string = '合格';
  62. }
  63. else {
  64. this.result.string = '不合格';
  65. }
  66. // let updateData = {
  67. // gameScore: hit? hit : 0,//游戏得分
  68. // gameTime: time,//单位秒
  69. // calorieBurned: kCal? kCal : 0,//消耗的卡路里
  70. // };
  71. // console.log("上传结果:",updateData);
  72. // if (cc.sys.OS_WINDOWS === cc.sys.os) return;
  73. // if(cc.sys.isMobile)
  74. // {
  75. // webView.uploadInfo(hit.toString(),time.toString(), kCal.toString());
  76. // }
  77. },
  78. replay()
  79. {
  80. cc.director.loadScene('Game');
  81. }
  82. });