Page({
data: {
show:false,
gamename:['石头','剪刀','布'],
count:0,
wincount:0
},
btnclick:function(e){
this.setData({show:true})
var gamename =this.data.gamename
var count = this.data.count
var wincount = this.data.wincount
var random = Math.round(Math.random() * 2)
var my = e.target.dataset.choose
this.setData({
count:count+1,
computername:gamename[random],
myname:gamename[my],
myid:my
})
if(my==random){
wx.showToast({
title: '平局啦',
duration:3000
})
}
else if((my==1&&random==0)||(my==2&&random==1)||(my==0&&random==2)){
wx.showToast({
title: '计算机赢啦',
image:'cry.jpg',
duration: 3000
})
}
else{
wx.showToast({
title: '太好啦您赢啦',
image: 'laugh.jpg',
duration: 3000
})
this.setData({wincount:wincount+1})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
评论0