Dim game(3,2),i,j,result,num ‘定义二维数组 二维长度3, 一维长度2
Dim fso ,ws,f ,logFileWrite,logFileRead, fileStr,flag,flagFailNum, flagIndex ‘ 定义日志文件
set ws=CreateObject(“wscript.shell”)
Set fso=CreateObject(“scripting.filesystemobject”)
If fso.fileexists(“C:\Users\18190\Desktop\vbs\测试\game_log.txt”) Then
Else
Set f=fso.createtextfile(“C:\Users\18190\Desktop\vbs\测试\game_log.txt”,true)
‘If fso.fileexists(“C:\Users\18190\Desktop\vbs\测试\game_log.txt”) Then
‘ Set logFileWrite=fso.OpenTextFile(“C:\Users\18190\Desktop\vbs\测试\game_log.txt”,8,true)
‘ logFileWrite.writeLine “数字猜猜猜小游戏-游戏日志”
‘ end if
End If
For i=0 To 2 ‘ 关卡赋值
For j=4 To 5
game(i,j-4)=i*3+j
Next
Next
‘For i=0 To 2
‘ For j=0 To 1
‘MsgBox “game(“&i&”,”&j&”): “& game(i,j)
‘Next
‘Next
‘ 选择操作
Dim cnum, failNum, sucFlag,t
failNum=0
sucFlag=0
Do While 1=1
If sucFlag=1 Then
Exit Do
End if
If failNum=3 Then
MsgBox “您有连续三次操作失误,系统将直接退出…”
Exit do
end if
cnum=InputBox( “欢迎来到 数字猜猜猜小游戏 请选择操作:”&chr(10)&” 1.注册 2.登录 3.退出”,”数字猜猜猜小游戏”)
If cnum=”” Then
cnum=”-1″
End if
Select Case cnum
Case 1
‘ 账户注册
Dim juname, upwd,regStr
regStr=””
do while regStr=””
uname=InputBox(“请输入注册账号: “,”数字猜猜猜小游戏-注册”)
upwd=InputBox(“请输入注册密码: “,”数字猜猜猜小游戏-注册”)
If uname <> “” Then
If upwd <> “” Then
regStr=uname&”#”&upwd
Else
regStr=””
MsgBox “您输入的注册账号密码有误,请重新输入”
End If
Else
regStr=””
MsgBox “您输入的注册账号密码有误,请重新输入”
End If
If regStr <>”” Then
If fso.fileexists(“C:\Users\18190\Desktop\vbs\测试\game_user.txt”) Then
Set logFileWrite=fso.OpenTextFile(“C:\Users\18190\Desktop\vbs\测试\game_user.txt”,8,true)
t=Year(now)&”-“&month(now)&”-“&day(now)&” “& Hour(now)&”:”&minute(now)&”:”&second(now)
‘logFileWrite.WriteBlankLines 1
logFileWrite.writeLine regStr &” “&t
logFileWrite.close
MsgBox “注册成功!”
exit do
else
Set f=fso.createtextfile(“C:\Users\18190\Desktop\vbs\测试\game_user.txt”,true)
If fso.fileexists(“C:\Users\18190\Desktop\vbs\测试\game_user.txt”) Then
Set logFileWrite=fso.OpenTextFile(“C:\Users\18190\Desktop\vbs\测试\game_user.txt”,8,true)
logFileWrite.writeLine “数字猜猜猜小游戏-用户数据”
logFileWrite.writeLine regStr
logFileWrite.close
MsgBox “注册成功!”
exit do
end if
End If
end if
loop
‘wscript.sleep 1000
case 2
‘ 账户登录
Dim str
Set logFileRead=fso.OpenTextFile(“C:\Users\18190\Desktop\vbs\测试\game_user.txt”,1)
fileStr=logFileRead.ReadAll
logFileRead.close
str=InputBox(“请输入您的账户名与密码,中间以#键隔开: “,” 数字猜猜猜小游戏-登录”)
if str <> “” then
flagIndex=InStr(fileStr,str)
If flagIndex>0 Then
flag=1
Else
flag=0
Do While flagIndex=0
flagFailNum=flagFailNum +1
If flagFailNum=3 Then
MsgBox “抱歉, 您已连续失败3次,系统退出”
wscript.sleep 5000 ‘ 就这样退出吧 — 缺少wscript 对象
flagFailNum=0
end if
MsgBox “您的账户与密码输入有误,请查证后再试试….”
str=InputBox(“请输入您的账户名与密码,中间以#键隔开: “,” 数字猜猜猜小游戏-登录”)
if str <> “” then
flagIndex=InStr(fileStr,str)
end if
loop
flag=1
End If
Else
flag=0
Do While flagIndex=0
flagFailNum=flagFailNum +1
If flagFailNum=3 Then
MsgBox “抱歉, 您已连续失败3次,系统退出”
wscript.sleep 5000 ‘ 就这样退出吧 — 缺少wscript 对象
flagFailNum=0
end if
MsgBox “您的账户与密码输入有误,请查证后再试试….”
str=InputBox(“请输入您的账户名与密码,中间以#键隔开: “,” 数字猜猜猜小游戏-登录”)
if str <> “” then
flagIndex=InStr(fileStr,str)
end if
loop
flag=1
end if
‘ 通过登录验证
if flag=1 then
Set logFileWrite=fso.OpenTextFile(“C:\Users\18190\Desktop\vbs\测试\game_log.txt”,8,true)
t=Year(now)&”-“&month(now)&”-“&day(now)&” “& Hour(now)&”:”&minute(now)&”:”&second(now)
‘logFileWrite.WriteBlankLines 1
logFileWrite.writeLine “用户登录: “&str &” “&t
MsgBox “恭喜您成功登录 数字猜猜猜小游戏! 接下来进入游戏正题: ”
num=0
for i=0 to 2
For j=0 To 1
result=InputBox(“现在是游戏第”&(i+1)&”关第”&(j+1)&”小节”&chr(10)&” 请输入游戏结果(i*3+j+4): “&chr(10)&”退出按-5”,”益智小游戏-数字猜猜猜: “)
If result=”-5″ Then
exit for
end if
If result=”” Then
result=”-1″
end if
If cint(result)=i*3+j+4 then
MsgBox “恭喜您,成功通过第”&(i+1)&”关第”&(j+1)&”小节,继续加油哦…”
End if
Do While cint(result) <> i*3+j+4
num=num+1
If num=3 Then
MsgBox “抱歉, 您已连续失败3次,通关失败!”&chr(10)&” 游戏进度截止为第”&(i+1)&”关第”&(j+1)&”小节,下次努力哦…”
exit Do
End if
MsgBox “抱歉,您猜错了!请查证后再试….”
result=InputBox(“现在是游戏第”&(i+1)&”关第”&(j+1)&”小节, 请输入游戏结果(i*3+j+4): “,”答案: “)
If result=”” Then
result=”-1″
end if
If cint(result)=i*3+j+4 then
MsgBox “恭喜您,成功通过第”&(i+1)&”关第”&(j+1)&”小节,继续加油哦…”
Exit do
End if
loop
If num=3 Then
exit for
end if
Next
If result=”-5″ Then
exit for
end if
If num=3 Then
exit for
End if
If i=2 Then
msg=”聪明的勇士,恭喜您成功通关本游戏!么么哒…”
MsgBox msg
t=Year(now)&”-“&month(now)&”-“&day(now)&” “& Hour(now)&”:”&minute(now)&”:”&second(now)
logFileWrite.writeLine “用户: “&str&”游戏进度: “&msg &” “&t
sucFlag=1
exit for
End If
msg=”恭喜您成功通关第”&(i+1)&”关卡, 接下来进入第”&(i+2)&”关…祝您好运!”
MsgBox msg
t=Year(now)&”-“&month(now)&”-“&day(now)&” “& Hour(now)&”:”&minute(now)&”:”&second(now)
logFileWrite.writeLine “用户: “&str&”游戏进度: “&msg &” “&t
Next
end if
Case 3
MsgBox “系统即将退出…”
exit do
case Else
MsgBox “您的选择有误,请重新选择…”
failNum=failNum +1
End select
loop