php网站开发主要内容,网络营销平台的账号如何运营,网站建设规划书的目的,湛江网站建设招聘介绍#xff1a; 一个简单的打怪小游戏#xff0c;点击开始游戏后#xff0c;出现攻击按钮#xff0c;击败怪物后可以选择继续下一关和结束游戏。 继续下一个怪兽的血量会增加5点#xff0c;攻击按钮会随机变色。
效果图#xff1a; html代码#xff1a;
!DOCTYPE…介绍 一个简单的打怪小游戏点击开始游戏后出现攻击按钮击败怪物后可以选择继续下一关和结束游戏。 继续下一个怪兽的血量会增加5点攻击按钮会随机变色。
效果图 html代码
!DOCTYPE html
html langen
head
meta charsetUTF-8
meta nameviewport contentwidthdevice-width, initial-scale1.0
title打怪/title
link relstylesheet href../layui/css/layui.css mediaall
style
/* 添加样式以中心布局两个游戏并增加一些间距 */
.game-container {text-align: center;margin: 5% auto;
}.game-container button {margin: 0 5px; /* 添加按钮间距 */
}#result, #message {margin: 20px 0;
}/style
/head
body
!-- 在HTML中添加开始游戏按钮 --
div classgame-containerh1打怪小游戏/h1h2 idmonster怪物 HP: span idmonsterHp10/span/h2button idstartGameButton classlayui-btn layui-btn-primary开始游戏/buttonbutton idattackButton classlayui-btn layui-btn-warm styledisplay: none;攻击怪物/buttonbutton idnextLevelButton classlayui-btn layui-btn-normal styledisplay: none;进入下一关/buttonbutton idendGameButton classlayui-btn layui-btn-danger styledisplay: none;结束游戏/buttonp idmessage/p
/divscript src./gamejs/game.js/script
/body
/html
js代码
document.addEventListener(DOMContentLoaded, () {const monsterHpElement document.getElementById(monsterHp);const messageElement document.getElementById(message);const startGameButton document.getElementById(startGameButton);const nextLevelButton document.getElementById(nextLevelButton);const endGameButton document.getElementById(endGameButton);let initialHp 10;let monsterHp;let level 1;const hpIncrease 5;const attackButton document.getElementById(attackButton);function startGame() {monsterHp initialHp;level 1;monsterHpElement.innerText monsterHp;messageElement.innerText 怪物出现了;resetAttackButtonColor();attackButton.style.display inline-block;startGameButton.style.display none;}function updateMonsterStatus() {if (monsterHp 0) {monsterHp--;monsterHpElement.innerText monsterHp;messageElement.innerText 怪物受到伤害还剩 ${monsterHp} 生命值。;} else {nextLevelButton.style.display inline-block;endGameButton.style.display inline-block;attackButton.style.display none;messageElement.innerText 恭喜你打败了怪物选择下一步操作。;}}function levelUp() {level;monsterHp initialHp hpIncrease * (level - 1);monsterHpElement.innerText monsterHp;messageElement.innerText 第 ${level} 关开始怪物生命值为 ${monsterHp}。;attackButton.style.display inline-block;nextLevelButton.style.display none;endGameButton.style.display none;changeAttackButtonColor();}function endGame() {messageElement.innerText 游戏结束感谢您的玩耍点击下方按钮可以重新开始。;attackButton.style.display none;nextLevelButton.style.display none;endGameButton.style.display none;startGameButton.style.display inline-block; // 显示开始游戏按钮}function resetAttackButtonColor() {attackButton.className layui-btn layui-btn-warm; // 这里设置默认的按钮颜色样式}function changeAttackButtonColor() {// 定义一组可能的颜色const colors [layui-btn-primary, layui-btn-normal, layui-btn-warm, layui-btn-danger];// 随机选择一个颜色const randomColor colors[Math.floor(Math.random() * colors.length)];attackButton.className layui-btn ${randomColor}; // 更新按钮的 class 以改变颜色}startGameButton.addEventListener(click, startGame);nextLevelButton.addEventListener(click, levelUp);endGameButton.addEventListener(click, endGame);attackButton.addEventListener(click, updateMonsterStatus);
});document.addEventListener02(DOMContentLoaded, () {const monsterHpElement document.getElementById(monsterHp);const messageElement document.getElementById(message);const startGameButton document.getElementById(startGameButton);const nextLevelButton document.getElementById(nextLevelButton);const endGameButton document.getElementById(endGameButton);let initialHp 10;let monsterHp;let level 1;const hpIncrease 5;const attackButton document.getElementById(attackButton);function startGame() {monsterHp initialHp;level 1;monsterHpElement.innerText monsterHp;messageElement.innerText 怪物出现了;attackButton.style.display inline-block;startGameButton.style.display none;}function updateMonsterStatus() {if (monsterHp 0) {monsterHp--;monsterHpElement.innerText monsterHp;messageElement.innerText 怪物受到伤害还剩 ${monsterHp} 生命值。;} else {nextLevelButton.style.display inline-block;endGameButton.style.display inline-block;attackButton.style.display none;messageElement.innerText 恭喜你打败了怪物选择下一步操作。;}}function levelUp() {level;monsterHp initialHp hpIncrease * (level - 1);monsterHpElement.innerText monsterHp;messageElement.innerText 第 ${level} 关开始怪物生命值为 ${monsterHp}。;attackButton.style.display inline-block;nextLevelButton.style.display none;endGameButton.style.display none;}function endGame() {messageElement.innerText 游戏结束感谢您的玩耍点击下方按钮可以重新开始。;attackButton.style.display none;nextLevelButton.style.display none;endGameButton.style.display none;startGameButton.style.display inline-block; // 显示开始游戏按钮}startGameButton.addEventListener(click, startGame);nextLevelButton.addEventListener(click, levelUp);endGameButton.addEventListener(click, endGame);attackButton.addEventListener(click, updateMonsterStatus);
});
文章转载自: http://www.morning.kpfds.cn.gov.cn.kpfds.cn http://www.morning.tphrx.cn.gov.cn.tphrx.cn http://www.morning.zwznz.cn.gov.cn.zwznz.cn http://www.morning.pnntx.cn.gov.cn.pnntx.cn http://www.morning.ltrms.cn.gov.cn.ltrms.cn http://www.morning.xhjjs.cn.gov.cn.xhjjs.cn http://www.morning.hrzky.cn.gov.cn.hrzky.cn http://www.morning.tkgjl.cn.gov.cn.tkgjl.cn http://www.morning.rbhcx.cn.gov.cn.rbhcx.cn http://www.morning.zjqwr.cn.gov.cn.zjqwr.cn http://www.morning.qkrqt.cn.gov.cn.qkrqt.cn http://www.morning.cbnjt.cn.gov.cn.cbnjt.cn http://www.morning.kcypc.cn.gov.cn.kcypc.cn http://www.morning.mttck.cn.gov.cn.mttck.cn http://www.morning.xbrxk.cn.gov.cn.xbrxk.cn http://www.morning.fbtgp.cn.gov.cn.fbtgp.cn http://www.morning.oioini.com.gov.cn.oioini.com http://www.morning.kgjyy.cn.gov.cn.kgjyy.cn http://www.morning.qxjck.cn.gov.cn.qxjck.cn http://www.morning.dqgbx.cn.gov.cn.dqgbx.cn http://www.morning.ndrzq.cn.gov.cn.ndrzq.cn http://www.morning.hysqx.cn.gov.cn.hysqx.cn http://www.morning.wkwds.cn.gov.cn.wkwds.cn http://www.morning.ryyjw.cn.gov.cn.ryyjw.cn http://www.morning.kphyl.cn.gov.cn.kphyl.cn http://www.morning.ylqb8.cn.gov.cn.ylqb8.cn http://www.morning.mjtft.cn.gov.cn.mjtft.cn http://www.morning.xcdph.cn.gov.cn.xcdph.cn http://www.morning.xmbhc.cn.gov.cn.xmbhc.cn http://www.morning.dnhdp.cn.gov.cn.dnhdp.cn http://www.morning.dmcxh.cn.gov.cn.dmcxh.cn http://www.morning.wdxr.cn.gov.cn.wdxr.cn http://www.morning.nsrlb.cn.gov.cn.nsrlb.cn http://www.morning.nfbkp.cn.gov.cn.nfbkp.cn http://www.morning.wcgcm.cn.gov.cn.wcgcm.cn http://www.morning.ymfzd.cn.gov.cn.ymfzd.cn http://www.morning.mbrbk.cn.gov.cn.mbrbk.cn http://www.morning.gwmjy.cn.gov.cn.gwmjy.cn http://www.morning.ynbyk.cn.gov.cn.ynbyk.cn http://www.morning.myxps.cn.gov.cn.myxps.cn http://www.morning.gnbfj.cn.gov.cn.gnbfj.cn http://www.morning.cndxl.cn.gov.cn.cndxl.cn http://www.morning.wnjrf.cn.gov.cn.wnjrf.cn http://www.morning.nyqm.cn.gov.cn.nyqm.cn http://www.morning.rwtlj.cn.gov.cn.rwtlj.cn http://www.morning.yngtl.cn.gov.cn.yngtl.cn http://www.morning.kpzrf.cn.gov.cn.kpzrf.cn http://www.morning.fddfn.cn.gov.cn.fddfn.cn http://www.morning.stlgg.cn.gov.cn.stlgg.cn http://www.morning.llfwg.cn.gov.cn.llfwg.cn http://www.morning.mbbgk.com.gov.cn.mbbgk.com http://www.morning.rhwty.cn.gov.cn.rhwty.cn http://www.morning.ttaes.cn.gov.cn.ttaes.cn http://www.morning.bphqd.cn.gov.cn.bphqd.cn http://www.morning.ppzgr.cn.gov.cn.ppzgr.cn http://www.morning.nwmwp.cn.gov.cn.nwmwp.cn http://www.morning.jhrlk.cn.gov.cn.jhrlk.cn http://www.morning.fpbj.cn.gov.cn.fpbj.cn http://www.morning.ndzhl.cn.gov.cn.ndzhl.cn http://www.morning.xjnjb.cn.gov.cn.xjnjb.cn http://www.morning.lrskd.cn.gov.cn.lrskd.cn http://www.morning.wnkbf.cn.gov.cn.wnkbf.cn http://www.morning.zqcdl.cn.gov.cn.zqcdl.cn http://www.morning.nyqxy.cn.gov.cn.nyqxy.cn http://www.morning.fpyll.cn.gov.cn.fpyll.cn http://www.morning.bhbxd.cn.gov.cn.bhbxd.cn http://www.morning.mdfxn.cn.gov.cn.mdfxn.cn http://www.morning.ysrtj.cn.gov.cn.ysrtj.cn http://www.morning.nhlnh.cn.gov.cn.nhlnh.cn http://www.morning.qwbht.cn.gov.cn.qwbht.cn http://www.morning.tcxzn.cn.gov.cn.tcxzn.cn http://www.morning.mwkwg.cn.gov.cn.mwkwg.cn http://www.morning.skkmz.cn.gov.cn.skkmz.cn http://www.morning.kcwkt.cn.gov.cn.kcwkt.cn http://www.morning.hmwjk.cn.gov.cn.hmwjk.cn http://www.morning.qcygd.cn.gov.cn.qcygd.cn http://www.morning.xjqhh.cn.gov.cn.xjqhh.cn http://www.morning.ynrzf.cn.gov.cn.ynrzf.cn http://www.morning.rgmls.cn.gov.cn.rgmls.cn http://www.morning.kncrc.cn.gov.cn.kncrc.cn