台灣最大程式設計社群網站
線上人數
558
 
會員總數:246038
討論主題:189625
歡迎您免費加入會員
討論區列表 >> 專欄文章 >> 九宮格遊戲source Code
[]  
[我要回覆]
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
九宮格遊戲source Code
價值 : 0 QP  點閱數:385 回應數:0
樓主

站務人員 站長
門外漢
0 1580
542 9
發送站內信

捐贈 VP 給 站務人員

<% '九宮格遊戲 BY CarHow.%>
<body onload="GameStart()">
<form name=form1>
<table align=center border=5 cellspacing=0 cellpadding=0 bordercolorlight=red>
<%
s1=split("one,two,three,four,five,six,seven,eight,nine",",")
for i=1 to 3 %>
<TR>
<% for j=1 to 3 %>
<td align=center><input style = "font-size:20pt;text-align:center;border: 0px solid #FFFFFF;font-family: arial" type=text name=<%=s1(j+3*(i-1)-1)%> size=2 readonly></td>
<% next %>
</TR>
<% next %>
</table>

<table width="28%" align=center border=3 cellspacing=0 cellpadding=0 bordercolorlight=green>
<tr><td align=left colspan=3>移動次數:<input style = "font-size:12pt;text-align:right;border: 0px solid #FFFFFF;font-family: arial" type=text value=0 name=movetimes size=3 readonly></td></tr>
<tr><td align=center colspan=3><input type=button value="重玩一次" onclick="GameStart()"></td></tr>
</table></br>
<center>※ 用鍵盤的上、下、左、右鍵移動 ※</center>

<script language=vbscript>
//上:38 下:40 左:37 右:39

Sub document_OnKeyUp
down=0
nownum=0

if form1.one.value="" then
nownull="one"
nownum=1
end if

if form1.two.value="" then
nownull="two"
nownum=2
end if

if form1.three.value="" then
nownull="three"
nownum=3
end if

if form1.four.value="" then
nownull="four"
nownum=4
end if

if form1.five.value="" then
nownull="five"
nownum=5
end if

if form1.six.value="" then
nownull="six"
nownum=6
end if

if form1.seven.value="" then
nownull="seven"
nownum=7
end if

if form1.eight.value="" then
nownull="eight"
nownum=8
end if

if form1.nine.value="" then
nownull="nine"
nownum=9
end if

key=window.event.keyCode
select case key
//下
case 40
down=nownum-3
if down>=1 and down<=9 then
select case down
case 1
form1.four.value=form1.one.value
form1.one.value=""
form1.movetimes.value=form1.movetimes.value+1
case 2
form1.five.value=form1.two.value
form1.two.value=""
form1.movetimes.value=form1.movetimes.value+1
case 3
form1.six.value=form1.three.value
form1.three.value=""
form1.movetimes.value=form1.movetimes.value+1
case 4
form1.seven.value=form1.four.value
form1.four.value=""
form1.movetimes.value=form1.movetimes.value+1
case 5
form1.eight.value=form1.five.value
form1.five.value=""
form1.movetimes.value=form1.movetimes.value+1
case 6
form1.nine.value=form1.six.value
form1.six.value=""
form1.movetimes.value=form1.movetimes.value+1
end select
end if

//上
case 38
down=nownum+3
if down>=1 and down<=9 then
select case down
case 7
form1.four.value=form1.seven.value
form1.seven.value=""
form1.movetimes.value=form1.movetimes.value+1
case 8
form1.five.value=form1.eight.value
form1.eight.value=""
form1.movetimes.value=form1.movetimes.value+1
case 9
form1.six.value=form1.nine.value
form1.nine.value=""
form1.movetimes.value=form1.movetimes.value+1
case 4
form1.one.value=form1.four.value
form1.four.value=""
form1.movetimes.value=form1.movetimes.value+1
case 5
form1.two.value=form1.five.value
form1.five.value=""
form1.movetimes.value=form1.movetimes.value+1
case 6
form1.three.value=form1.six.value
form1.six.value=""
form1.movetimes.value=form1.movetimes.value+1
end select
end if

//左
case 37
down=nownum+1
if down>=1 and down<=9 then
select case down
case 2
form1.one.value=form1.two.value
form1.two.value=""
form1.movetimes.value=form1.movetimes.value+1
case 5
form1.four.value=form1.five.value
form1.five.value=""
form1.movetimes.value=form1.movetimes.value+1
case 8
form1.seven.value=form1.eight.value
form1.eight.value=""
form1.movetimes.value=form1.movetimes.value+1
case 3
form1.two.value=form1.three.value
form1.three.value=""
form1.movetimes.value=form1.movetimes.value+1
case 6
form1.five.value=form1.six.value
form1.six.value=""
form1.movetimes.value=form1.movetimes.value+1
case 9
form1.eight.value=form1.nine.value
form1.nine.value=""
form1.movetimes.value=form1.movetimes.value+1
end select
end if

//右
case 39
down=nownum-1
if down>=1 and down<=9 then
select case down
case 2
form1.three.value=form1.two.value
form1.two.value=""
form1.movetimes.value=form1.movetimes.value+1
case 5
form1.six.value=form1.five.value
form1.five.value=""
form1.movetimes.value=form1.movetimes.value+1
case 8
form1.nine.value=form1.eight.value
form1.eight.value=""
form1.movetimes.value=form1.movetimes.value+1
case 1
form1.two.value=form1.one.value
form1.one.value=""
form1.movetimes.value=form1.movetimes.value+1
case 4
form1.five.value=form1.four.value
form1.four.value=""
form1.movetimes.value=form1.movetimes.value+1
case 7
form1.eight.value=form1.seven.value
form1.seven.value=""
form1.movetimes.value=form1.movetimes.value+1
end select
end if
end select

isyes=0
if form1.one.value="1" then
isyes=isyes+1
end if
if form1.two.value="2" then
isyes=isyes+1
end if
if form1.three.value="3" then
isyes=isyes+1
end if
if form1.four.value="4" then
isyes=isyes+1
end if
if form1.five.value="5" then
isyes=isyes+1
end if
if form1.six.value="6" then
isyes=isyes+1
end if
if form1.seven.value="7" then
isyes=isyes+1
end if
if form1.eight.value="8" then
isyes=isyes+1
end if
if form1.nine.value="" then
isyes=isyes+1
end if

if isyes=9 then
alert "恭喜過關~~~~~"
end if
End Sub

Sub GameStart()
numstr=""

i=0
while i<>8
g=(int(rnd()*37*second(time)*rnd()*13+1+rnd())*11 mod 8)+1
if instr(numstr,g)=0 then
i=i+1
numstr=numstr&g&","
end if
wend

numstr=mid(numstr,1,len(numstr)-1)
numstr=split(numstr,",")

form1.one.value=numstr(0)
form1.two.value=numstr(1)
form1.three.value=numstr(2)
form1.four.value=numstr(3)
form1.five.value=numstr(4)
form1.six.value=numstr(5)
form1.seven.value=numstr(6)
form1.eight.value=numstr(7)
form1.nine.value=""
form1.movetimes.value=0
End Sub
</script>
</form>

本篇文章發表於2002-08-20 00:00
目前尚無任何回覆
   

回覆
如要回應,請先登入.