📄 htmlgame.htm
字号:
<html>
<head>
<title>射击游戏</title>
</head>
<body>
<!--第一个DIV块存放“兔子”0002.gif,并设置其ID为imgt,便于在VBScript中引用它-->
<div id=imgt style="position: absolute; left: 300; top: 0; visibility: visible; width: 55; height: 40"><img src="0002.gif" width="50" height="40"></div>
<!--下面这个DIV块存放玩者的射击结果-->
<div id=txt style="position: absolute; left: 250; top:150; visibility: visible">
<font color=blue>击中次数:</font><span id=txtfs style="position: absolute"> <font color=red>0</font> </span><br>
<font color=blue>开枪次数:</font><span id=txtkqs style="position: absolute"> <font color=red>0</font></span><br>
<font color=blue>击中率 %:</font><span id=txtjzl style="position: absolute"> <font color=red>0</font></span><br>
<font color=blue>射击水平:</font><span id=txtsjsp style="position: absolute"> <font color=red>0</font></span>
</div>
<!--下面的两个DIV块分别存放“子弹”point02.gif和“手枪”a_10.gif-->
<div id=imgzd style="position:absolute;left:0;top:340"><img src="point02.gif">
</div>
<div id=imgq style="position:absolute;left:0;top:350"><img src="a_10.gif" width="28" height="40">
</div>
<!--以下是脚本程序-->
<script language="vbScript">
<!--
dim fs '声明三个全局变量,fs记录击中次数,kqs记录开枪次数,jzl记录击中率
dim kqs
dim jzl
sub window_onload()
domove 'domove为处理“兔子”移动和闪烁的子程序
imgq.style.left=window.event.x '让“手枪”和“子弹”一起跟踪鼠标的移动
imgzd.style.left=window.event.x
end sub
sub document_onmousemove()
imgq.style.left=window.event.x '鼠标在页面上移动时,“手枪”始终随鼠标左右移动
zdnewy=int(imgzd.style.postop)
if zdnewy=340 then '在“子弹”未射出前才随鼠标左右移动,射出后直线上升
imgzd.style.left=window.event.x
end if
end sub
sub document_onclick()
kqs=kqs+1 '单击一次,射击次数加一
txtkqs.innertext=kqs '在页面上显示出射击次数
dokq 'dokq为处理“开枪”后事件的子函数
end sub
sub domove '这是处理“兔子移动的子函数
newx=int(imgt.style.posleft+10) '每次向右移动10
imgt.style.left=newx
if newx>document.body.clientwidth then '若“兔子”移出了页面边界,则重新在左边出现
imgt.style.left=0
end if
if imgt.style.visibility="visible" then '此IF块使“兔子”移动的同时闪烁
imgt.style.visibility="hidden"
else
imgt.style.visibility="visible"
end if
tid=settimeout("domove",200) '(关键语句)设置一个定时器,每200毫秒执行一次domove,出现动画效果
end sub
sub dokq '处理开枪后事件的子函数
newy=int(imgzd.style.postop-20) '子弹在开枪后每次向上移动20
imgzd.style.top=newy
zdtime=settimeout("dokq",5) '(关键语句)设置一个定时器,每5毫秒执行一次dokq,出现子弹飞出效果
if newy<50 then '此IF块检查“子弹”是否击中“兔子”
zdx=int(imgzd.style.posleft)
tx=int(imgt.style.posleft)
if imgt.style.visibility="visible" then
if zdx>tx and zdx<(tx+50) then
msgbox"哇!你打中它了,OK!" '击中后显示消息,且使击中记录数加1
fs=fs+1
txtfs.innertext=fs '在页面上显示击中次数
cleartimeout(zdtime) '关闭定时器,使子弹停止飞行
imgt.style.left=0 '击中后“兔子”从新在页面左边出现
imgzd.style.top=340 '子弹从新出现在“手枪”上
else
msgbox"哎呀!你的枪法好臭啊!"
cleartimeout(zdtime) '关闭定时器,使子弹停止飞行
imgzd.style.top=340 '子弹从新出现在“手枪”上
end if
else
msgbox"哎呀!你的枪法好臭啊!"
cleartimeout(zdtime)
imgzd.style.top=340
end if
end if
jzl=int((fs/kqs)*100) '统计玩者的射击水平,并给出评价
txtjzl.innertext=jzl & "%"
if jzl<=30 then txtsjsp.innertext="很差!"
if jzl>30 and jzl<=60 then txtsjsp.innertext="一般!"
if jzl>60 and jzl<=80 then txtsjsp.innertext="较好!"
if jzl>80 and jzl<=90 then txtsjsp.innertext="高手!"
if jzl>90 then txtsjsp.innertext="神枪手!"
end sub
-->
</script>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -