图片不知道怎么的,一直转换不了,所以就直接用text来显示了。用的是社区里提供的示例模板以及HTML的模拟器,我直接在模板上加了些代码。
但我的手环还在快递的路上,也还不会打包。
有兴趣的可以试一下能不能在手环上运行,虽然写的很烂。
但我的手环还在快递的路上,也还不会打包。
有兴趣的可以试一下能不能在手环上运行,虽然写的很烂。
JavaScript:
//挖矿小游戏
var HP = 100;
var GOLD = 0;
let txtHP = txtGroup.createWidget(hmUI.widget.TEXT, { // HP文本
x: 6,
y: 100,
w: 180,
h: 20,
color: "0x000000",
text_size: 20,
text_style: hmUI.text_style.WRAP,
text: 'HP:' + HP
})
let txtGOLD = txtGroup.createWidget(hmUI.widget.TEXT, { // GOLD文本
x: 6,
y: 130,
w: 180,
h: 20,
color: "0x000000",
text_size: 20,
text_style: hmUI.text_style.WRAP,
text: "GOLD:" + GOLD
})
const randButton = txtGroup.createWidget(hmUI.widget.BUTTON, { //随机按钮
x: 0,
y: 360,
w: 192,
h: 50,
press_color: 0xC3C3C3,
normal_color: 0xEFEFEF,
text: '挖矿',
color: 0x000000,
click_func: function(button) {
randButton.setProperty(hmUI.prop.VISIBLE, false);
txtWd.setProperty(hmUI.prop.MORE, {
text: "......"
})
sleep(game(), 500)
}
})
const restartButton = txtGroup.createWidget(hmUI.widget.BUTTON, {
x: 0,
y: 420,
w: 192,
h: 50,
press_color: 0xC3C3C3,
normal_color: 0xEFEFEF,
text: '大侠,请重新来过',
color: 0x000000,
click_func: function(button) {
HP = 100;
GOLD = 0;
show()
restartButton.setProperty(hmUI.prop.VISIBLE, false);
}
})
restartButton.setProperty(hmUI.prop.VISIBLE, false);
function sleep(text, time) {
const timer1 = timer.createTimer(0, time, function() {
txtWd.setProperty(hmUI.prop.MORE, {
text: text
})
show()
timer.stopTimer(timer1)
randButton.setProperty(hmUI.prop.VISIBLE, true);
})
}
function show() {
txtHP.setProperty(hmUI.prop.MORE, {
text: 'HP:' + HP
})
txtGOLD.setProperty(hmUI.prop.MORE, {
text: 'GOLD:' + GOLD
})
}
function game() {
let a = Math.random()
let rtext
if (HP <= 0) {
restartButton.setProperty(hmUI.prop.VISIBLE, true);
return "别挖了,血都没了"
}
switch (true) {
case a == 0:
rtext = "什么!居然挖穿了地球!";
GOLD += 9999
break;
case a > 0 && a <= 0.05:
rtext = "挖到金矿!增加100 GOLD!";
GOLD += 100
break;
case a > 0.05 && a <= 0.2:
rtext = "挖到铁矿!增加20 GOLD!";
GOLD += 20
break;
case a > 0.2 && a <= 0.4:
rtext = "挖到石头!增加5 GOLD!";
GOLD += 5
break;
case a > 0.4 && a <= 0.5:
rtext = "砸到了脚!减少5 HP";
HP -= 5
break;
case a > 0.5 && a <= 0.55:
rtext = "砸到毒蛇!减少20 HP";
HP -= 20
break;
case a > 0.55 && a <= 0.57:
rtext = "砸到了火药,炸了!减少50 HP";
HP -= 50
break;
case a > 0.57 && a <= 0.65:
rtext = "挖到了火药!增加30 GOLD";
GOLD += 30
break;
case a > 0.57 && a <= 0.65:
rtext = "挖到了水源!增加30 HP";
HP += 30
break;
default:
rtext = "啥都没有挖到。。。";
}
if (HP > 100) {
HP = 100
}
return rtext
}
由版主最后编辑: