东风启辰小程序端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

299 lines
7.0KB

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