微信小程序开发猜数字小游戏
(1) 游戏初始化
游戏初始化时需要规定以下内容,顺序不限:正确答案answer:随机生成一个0-100之间的数字;回合数count:0;提示语句tip:空字符串‘’;用户猜的数字x:-1;游戏状态isGameStart:true。
(2)获取用户输入的数字为输入框添加bindinput事件。
<input bindinput=’getNumber’ type=’number’ placeholder=’请输入0-100之间的数字’></input>
(3)游戏过程 为按钮添加bindtap事件。
<button type=’primary’ form-type=’reset’ bindtap=’guess’>提交</button>
(4)游戏结束 当游戏结束时隐藏输入框和“提交”按钮,只显示“重新开始”按钮。
<block wx:if='{{isGameStart}}’>
<input bindinput=’getNumber’ type=’number’ placeholder=’请输入0-100之间的数字’></input>
<button type=’primary’ form-type=’reset’ bindtap=’guess’>提交</button>
</block>
<block wx:else>
<button type=’primary’ bindtap=’restartGame’>重新开始</button>
</block>
(4)首页逻辑
现在将app.json中页面的路径位置重新调整,使得index为第一个显示的页面。
然后为3个按钮分别添加bindTap事件。
<view class=’container’>
<button bindtap=’goToGame’ type=’primary’>开始游戏</button>
<button bindtap=’goToRules’ type=’primary’>游戏规则</button>
<button bindtap=’goToAbout’ type=’primary’>关于我们</button>
</view>
#小程序开发 #前端 #小程序制作
游戏初始化时需要规定以下内容,顺序不限:正确答案answer:随机生成一个0-100之间的数字;回合数count:0;提示语句tip:空字符串‘’;用户猜的数字x:-1;游戏状态isGameStart:true。
(2)获取用户输入的数字为输入框添加bindinput事件。
<input bindinput=’getNumber’ type=’number’ placeholder=’请输入0-100之间的数字’></input>
(3)游戏过程 为按钮添加bindtap事件。
<button type=’primary’ form-type=’reset’ bindtap=’guess’>提交</button>
(4)游戏结束 当游戏结束时隐藏输入框和“提交”按钮,只显示“重新开始”按钮。
<block wx:if='{{isGameStart}}’>
<input bindinput=’getNumber’ type=’number’ placeholder=’请输入0-100之间的数字’></input>
<button type=’primary’ form-type=’reset’ bindtap=’guess’>提交</button>
</block>
<block wx:else>
<button type=’primary’ bindtap=’restartGame’>重新开始</button>
</block>
(4)首页逻辑
现在将app.json中页面的路径位置重新调整,使得index为第一个显示的页面。
然后为3个按钮分别添加bindTap事件。
<view class=’container’>
<button bindtap=’goToGame’ type=’primary’>开始游戏</button>
<button bindtap=’goToRules’ type=’primary’>游戏规则</button>
<button bindtap=’goToAbout’ type=’primary’>关于我们</button>
</view>
#小程序开发 #前端 #小程序制作