东风启辰小程序端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 5 Jahren
vor 5 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. // pages/luckyStar/luckyStar.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. ruleShow: false,//是否显示游戏玩法
  10. ruleCloseShow: false,//是否显示游戏玩法关闭按钮
  11. clawTop:95,//爪子的top值
  12. clawLeft: 293,//爪子的left值
  13. clawScale: 1,//爪子的scale值
  14. downNum:30,//倒计时时间
  15. setInt:null,//倒计时元素
  16. pizeTip:1,//抓奖提示框
  17. setGroup:{
  18. left:null,
  19. right: null,
  20. top: null,
  21. bottom: null,
  22. },
  23. gameSign: null, //游戏结束时需要
  24. startType:1,//开始类型:1通过游戏玩法里的开始按钮,2:通过抓取按钮
  25. gameState:false,//游戏状态
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. app.globalData.nowPage = 3;
  32. },
  33. /**
  34. * 生命周期函数--监听页面初次渲染完成
  35. */
  36. onReady: function () {
  37. },
  38. /**
  39. * 生命周期函数--监听页面显示
  40. */
  41. onShow: function () {
  42. },
  43. /**
  44. * 生命周期函数--监听页面隐藏
  45. */
  46. onHide: function () {
  47. },
  48. /**
  49. * 生命周期函数--监听页面卸载
  50. */
  51. onUnload: function () {
  52. },
  53. /**
  54. * 页面相关事件处理函数--监听用户下拉动作
  55. */
  56. onPullDownRefresh: function () {
  57. },
  58. /**
  59. * 页面上拉触底事件的处理函数
  60. */
  61. onReachBottom: function () {
  62. },
  63. /**
  64. * 用户点击右上角分享
  65. */
  66. onShareAppMessage: function () {
  67. return app.sharePack();
  68. },
  69. closeRule:function(){//关闭游戏玩法
  70. this.setData({
  71. ruleShow:false
  72. })
  73. },
  74. openGameRule: function () {//打开游戏玩法
  75. if(!this.data.gameState){
  76. this.setData({
  77. ruleShow: true
  78. })
  79. }
  80. },
  81. gameStart: function () {//开始游戏按钮
  82. if(this.data.startType==1){
  83. this.data.startType = 2;
  84. this.setData({
  85. ruleShow: false,
  86. ruleCloseShow: true
  87. })
  88. this.beginGame();
  89. }
  90. },
  91. beginGame: function () {//开始游戏
  92. app.wxRequest(app.globalData.urlRoot + "dollGame/beginGame", {}, res => {
  93. console.log(res);
  94. if(res.code==200){
  95. this.data.gameSign = res.data.sign;
  96. this.endGame();
  97. if (this.data.gameSign) {
  98. this.downTimeFun();
  99. }
  100. }else{
  101. wx.showToast({
  102. title: res.msg,
  103. icon:"none"
  104. })
  105. }
  106. },this)
  107. },
  108. endGame:function(){//结束游戏
  109. app.wxRequest(app.globalData.urlRoot + "dollGame/endGame", { sign:this.data.gameSign}, res => {
  110. console.log(res);
  111. if(res.code=200){
  112. }else{
  113. console.log(res);
  114. }
  115. }, this,"POST")
  116. },
  117. startClaw:function(e){//开始控制爪子方向
  118. let direction = e.currentTarget.dataset.direction;
  119. if (direction == "L") {//向左
  120. if (this.data.clawLeft <= 130) {
  121. return;
  122. }
  123. this.data.setGroup.left = setInterval(() => {
  124. this.setData({
  125. clawLeft: this.data.clawLeft-=2
  126. })
  127. if (this.data.clawLeft <= 130) {
  128. clearInterval(this.data.setGroup.left);
  129. }
  130. },20);
  131. } else if (direction == "R") {//向右
  132. if (this.data.clawLeft >= 445) {
  133. return;
  134. }
  135. this.data.setGroup.right = setInterval(() => {
  136. this.setData({
  137. clawLeft: this.data.clawLeft += 2
  138. })
  139. if (this.data.clawLeft >= 445) {
  140. clearInterval(this.data.setGroup.right);
  141. }
  142. }, 20);
  143. } else if (direction == "T") {//向后
  144. if (this.data.clawScale <= 0.5) {
  145. return;
  146. }
  147. this.data.setGroup.top = setInterval(() => {
  148. this.setData({
  149. clawScale: this.data.clawScale -= 0.01
  150. })
  151. if (this.data.clawScale <= 0.5) {
  152. clearInterval(this.data.setGroup.top);
  153. }
  154. }, 20);
  155. } else if (direction == "B") {//向前
  156. if (this.data.clawScale >= 1.5) {
  157. return;
  158. }
  159. this.data.setGroup.bottom = setInterval(() => {
  160. this.setData({
  161. clawScale: this.data.clawScale += 0.01
  162. })
  163. if (this.data.clawScale >= 1.5) {
  164. clearInterval(this.data.setGroup.bottom);
  165. }
  166. }, 20);
  167. }
  168. },
  169. endClaw:function(e){//结束爪子动作
  170. let direction = e.currentTarget.dataset.direction;
  171. if (direction == "L") {//向左
  172. clearInterval(this.data.setGroup.left);
  173. } else if (direction == "R") {//向右
  174. clearInterval(this.data.setGroup.right);
  175. } else if (direction == "T") {//向后
  176. clearInterval(this.data.setGroup.top);
  177. } else if (direction == "B") {//向前
  178. clearInterval(this.data.setGroup.bottom);
  179. }
  180. },
  181. getClaw:function(){//抓取
  182. this.setData({
  183. clawTop: this.data.clawScale > 1 ? 490 - (2 * (this.data.clawScale-1) * 90) : 490 + (2 * (1 - this.data.clawScale) * 90 )
  184. })
  185. this.closeSetInt();
  186. },
  187. downTimeFun:function(){//游戏倒计时
  188. this.data.gameState = true;
  189. this.data.setInt = setInterval(()=>{
  190. this.data.downNum -= 1;
  191. if (this.data.downNum<10){
  192. this.data.downNum = '0' + this.data.downNum;
  193. }
  194. this.setData({
  195. downNum: this.data.downNum
  196. })
  197. if (this.data.downNum < 1) {
  198. this.closeSetInt();
  199. }
  200. },1000);
  201. },
  202. closeSetInt: function () {//关闭倒计时
  203. this.data.gameState = false;
  204. clearInterval(this.data.setInt);
  205. this.setData({
  206. downNum: 30,
  207. clawTop: this.data.clawScale > 1 ? 455 - (2 * (this.data.clawScale - 1) * 90) : 455 + (2 * (1 - this.data.clawScale) * 90)
  208. })
  209. setTimeout(()=>{
  210. this.setData({
  211. downNum: 30,
  212. clawTop: 95,
  213. clawLeft: 293,
  214. clawScale:1
  215. })
  216. }, 1200);
  217. },
  218. prizeLook:function(){//活动奖品
  219. if(!this.data.gameState){
  220. wx.navigateTo({
  221. url: '../prizes/prizes'
  222. })
  223. }
  224. }
  225. })