今天就跟大家聊聊有關(guān)使用vbs怎么制作一個(gè)數(shù)字益智游戲,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
創(chuàng)新互聯(lián)是專業(yè)的網(wǎng)站建設(shè)公司,提供網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)站設(shè)計(jì)等網(wǎng)站開發(fā)一體化解決方案;包括成都h5網(wǎng)站建設(shè),小程序開發(fā),網(wǎng)站定制,企業(yè)網(wǎng)站建設(shè),成都商城網(wǎng)站開發(fā),成都響應(yīng)式網(wǎng)站建設(shè),建網(wǎng)站,PHP網(wǎng)站建設(shè),軟件開發(fā),軟文發(fā)稿,網(wǎng)站營(yíng)銷。歡迎做網(wǎng)站的企業(yè)前來合作洽談,創(chuàng)新互聯(lián)將竭誠為您服務(wù)!1. 選擇操作: 游戲開始時(shí)會(huì)提示選擇注冊(cè), 登錄, 退出三種選項(xiàng),
2.注冊(cè): 注冊(cè)成功會(huì)將用戶賬戶與密碼存入用戶數(shù)據(jù)txt文檔中,連續(xù)三次輸入 空值會(huì)直接退出游戲;
3. 登錄: 登錄時(shí)會(huì)將輸入數(shù)據(jù)與用戶數(shù)據(jù)文檔內(nèi)容進(jìn)行比對(duì), 存在該用戶則登 錄成功, 同樣失敗三次后退出游戲;
4. 開始游戲: 登錄成功后,會(huì)直接進(jìn)入游戲,游戲暫定為三個(gè)關(guān)卡, 每個(gè)關(guān)卡三 個(gè)小節(jié),游戲通過規(guī)則為以關(guān)卡作為二維數(shù)組的二維數(shù)組下標(biāo)(下標(biāo)),小 節(jié)作為 一位數(shù)組下標(biāo)(下標(biāo)+4)...文件里有具體實(shí)現(xiàn),不啰嗦額;
5. 用戶登錄,通關(guān)每關(guān)游戲都會(huì)寫入游戲日志文檔game _log.txt ,記錄用戶,操 作,通關(guān)進(jìn)度, 通關(guān)時(shí)間等
ps: 文件下載后,雙擊即可運(yùn)行, 游戲的用戶文檔game_user.txt和日志文檔game_log.txt是按照我桌面路徑創(chuàng)建的,如果不喜歡可以直接修改為d:\game\game_user.txt等等,游戲不在乎多好玩, 希望能給想學(xué)習(xí)vbs的童鞋一些幫助
完整代碼
Dim game(3,2),i,j,result,num '定義二維數(shù)組 二維長(zhǎng)度3, 一維長(zhǎng)度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\測(cè)試\game_log.txt") Then Else Set f = fso.createtextfile("C:\Users\18190\Desktop\vbs\測(cè)試\game_log.txt",true) 'If fso.fileexists("C:\Users\18190\Desktop\vbs\測(cè)試\game_log.txt") Then ' Set logFileWrite = fso.OpenTextFile("C:\Users\18190\Desktop\vbs\測(cè)試\game_log.txt",8,true) ' logFileWrite.writeLine "數(shù)字猜猜猜小游戲-游戲日志" ' end if End If For i=0 To 2 ' 關(guān)卡賦值 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 "您有連續(xù)三次操作失誤,系統(tǒng)將直接退出..." Exit do end if cnum = InputBox( "歡迎來到 數(shù)字猜猜猜小游戲 請(qǐng)選擇操作:"&chr(10)&" 1.注冊(cè) 2.登錄 3.退出","數(shù)字猜猜猜小游戲") If cnum ="" Then cnum = "-1" End if Select Case cnum Case 1 ' 賬戶注冊(cè) Dim juname, upwd,regStr regStr = "" do while regStr = "" uname = InputBox("請(qǐng)輸入注冊(cè)賬號(hào): ","數(shù)字猜猜猜小游戲-注冊(cè)") upwd = InputBox("請(qǐng)輸入注冊(cè)密碼: ","數(shù)字猜猜猜小游戲-注冊(cè)") If uname <> "" Then If upwd <> "" Then regStr = uname&"#"&upwd Else regStr ="" MsgBox "您輸入的注冊(cè)賬號(hào)密碼有誤,請(qǐng)重新輸入" End If Else regStr ="" MsgBox "您輸入的注冊(cè)賬號(hào)密碼有誤,請(qǐng)重新輸入" End If If regStr <>"" Then If fso.fileexists("C:\Users\18190\Desktop\vbs\測(cè)試\game_user.txt") Then Set logFileWrite = fso.OpenTextFile("C:\Users\18190\Desktop\vbs\測(cè)試\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 "注冊(cè)成功!" exit do else Set f = fso.createtextfile("C:\Users\18190\Desktop\vbs\測(cè)試\game_user.txt",true) If fso.fileexists("C:\Users\18190\Desktop\vbs\測(cè)試\game_user.txt") Then Set logFileWrite = fso.OpenTextFile("C:\Users\18190\Desktop\vbs\測(cè)試\game_user.txt",8,true) logFileWrite.writeLine "數(shù)字猜猜猜小游戲-用戶數(shù)據(jù)" logFileWrite.writeLine regStr logFileWrite.close MsgBox "注冊(cè)成功!" 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\測(cè)試\game_user.txt",1) fileStr = logFileRead.ReadAll logFileRead.close str = InputBox("請(qǐng)輸入您的賬戶名與密碼,中間以#鍵隔開: "," 數(shù)字猜猜猜小游戲-登錄") 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 "抱歉, 您已連續(xù)失敗3次,系統(tǒng)退出" wscript.sleep 5000 ' 就這樣退出吧 -- 缺少wscript 對(duì)象 flagFailNum =0 end if MsgBox "您的賬戶與密碼輸入有誤,請(qǐng)查證后再試試...." str = InputBox("請(qǐng)輸入您的賬戶名與密碼,中間以#鍵隔開: "," 數(shù)字猜猜猜小游戲-登錄") 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 "抱歉, 您已連續(xù)失敗3次,系統(tǒng)退出" wscript.sleep 5000 ' 就這樣退出吧 -- 缺少wscript 對(duì)象 flagFailNum =0 end if MsgBox "您的賬戶與密碼輸入有誤,請(qǐng)查證后再試試...." str = InputBox("請(qǐng)輸入您的賬戶名與密碼,中間以#鍵隔開: "," 數(shù)字猜猜猜小游戲-登錄") if str <> "" then flagIndex = InStr(fileStr,str) end if loop flag = 1 end if ' 通過登錄驗(yàn)證 if flag =1 then Set logFileWrite = fso.OpenTextFile("C:\Users\18190\Desktop\vbs\測(cè)試\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 "恭喜您成功登錄 數(shù)字猜猜猜小游戲! 接下來進(jìn)入游戲正題: " num =0 for i=0 to 2 For j=0 To 1 result = InputBox("現(xiàn)在是游戲第"&(i+1)&"關(guān)第"&(j+1)&"小節(jié)"&chr(10)&" 請(qǐng)輸入游戲結(jié)果(i*3+j+4): "&chr(10)&"退出按-5","益智小游戲-數(shù)字猜猜猜: ") 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)&"關(guān)第"&(j+1)&"小節(jié),繼續(xù)加油哦..." End if Do While cint(result) <> i*3+j+4 num =num+1 If num =3 Then MsgBox "抱歉, 您已連續(xù)失敗3次,通關(guān)失敗!"&chr(10)&" 游戲進(jìn)度截止為第"&(i+1)&"關(guān)第"&(j+1)&"小節(jié),下次努力哦..." exit Do End if MsgBox "抱歉,您猜錯(cuò)了!請(qǐng)查證后再試...." result = InputBox("現(xiàn)在是游戲第"&(i+1)&"關(guān)第"&(j+1)&"小節(jié), 請(qǐng)輸入游戲結(jié)果(i*3+j+4): ","答案: ") If result ="" Then result = "-1" end if If cint(result) = i*3+j+4 then MsgBox "恭喜您,成功通過第"&(i+1)&"關(guān)第"&(j+1)&"小節(jié),繼續(xù)加油哦..." 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 = "聰明的勇士,恭喜您成功通關(guān)本游戲!么么噠..." MsgBox msg t= Year(now)&"-"&month(now)&"-"&day(now)&" "& Hour(now)&":"&minute(now)&":"&second(now) logFileWrite.writeLine "用戶: "&str&"游戲進(jìn)度: "&msg &" "&t sucFlag =1 exit for End If msg = "恭喜您成功通關(guān)第"&(i+1)&"關(guān)卡, 接下來進(jìn)入第"&(i+2)&"關(guān)...祝您好運(yùn)!" MsgBox msg t= Year(now)&"-"&month(now)&"-"&day(now)&" "& Hour(now)&":"&minute(now)&":"&second(now) logFileWrite.writeLine "用戶: "&str&"游戲進(jìn)度: "&msg &" "&t Next end if Case 3 MsgBox "系統(tǒng)即將退出..." exit do case Else MsgBox "您的選擇有誤,請(qǐng)重新選擇..." failNum = failNum +1 End select loop
看完上述內(nèi)容,你們對(duì)使用vbs怎么制作一個(gè)數(shù)字益智游戲有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。