基本信息
源码名称:微信小程序,猜拳游戏
源码大小:0.04M
文件格式:.zip
开发语言:js
更新时间:2019-02-22
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
微信小程序,猜拳游戏

//index.js
//获取应用实例
let timer;
let numAi = 0;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    btnState: false,
    winNum: 0,
    imageAiScr: '',
    imageUserScr: '/pages/image/wenhao.png',
    gameResult: '',
    srcs: [
      '/pages/image/shitou.png',
      '/pages/image/jiandao.png',
      '/pages/image/bu.png'
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let oldWinNum = wx.getStorageSync('winNum')
    if (oldWinNum != null && oldWinNum != '') {
      this.setData({
        winNum: oldWinNum
      })
    }
    this.timerGo();
  },
  changeForChoose(e) {
    if (this.data.btnState) {
      return;
    }
    this.setData({
      imageUserScr: this.data.srcs[e.currentTarget.id]
    })
    clearInterval(timer);
    let user = this.data.imageUserScr;
    let ai = this.data.imageAiScr;
    let num = this.data.winNum;
    let str = '你输了';
    if (user == '/pages/image/shitou.png' && ai == '/pages/image/jiandao.png') {
      num  ;
      str = '你赢了';
      wx.setStorageSync('winNum', num)
    }
    if (user == '/pages/image/bu.png' && ai == '/pages/image/shitou.png') {
      num  ;
      str = '你赢了';
      wx.setStorageSync('winNum', num)
    }
    if (user == '/pages/image/jiandao.png' && ai == '/pages/image/bu.png') {
      num  ;
      str = '你赢了';
      wx.setStorageSync('winNum', num)
    }
    if (user == ai) {
      str = '打平了';
    }
    this.setData({
      winNum: num,
      gameResult: str,
      btnState: true
    })
  },
  timerGo() {
    timer = setInterval(this.move, 100)
  },
  move() {
    if (numAi >= 3) {
      numAi = 0
    }
    numAi = parseInt(Math.floor(Math.random() * 3));
    this.setData({
      imageAiScr: this.data.srcs[numAi]
    })
    numAi  ;
  },
  again() {
    if (this.data.btnState == false) {
      return;
    }
    this.timerGo();
    this.setData({
      btnState: false,
      gameResult: '',
      imageUserScr: '/pages/image/wenhao.png'
    })
  }
})