您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關使用vbs怎么制作一個數字益智游戲,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
1. 選擇操作: 游戲開始時會提示選擇注冊, 登錄, 退出三種選項,
2.注冊: 注冊成功會將用戶賬戶與密碼存入用戶數據txt文檔中,連續三次輸入 空值會直接退出游戲;
3. 登錄: 登錄時會將輸入數據與用戶數據文檔內容進行比對, 存在該用戶則登 錄成功, 同樣失敗三次后退出游戲;
4. 開始游戲: 登錄成功后,會直接進入游戲,游戲暫定為三個關卡, 每個關卡三 個小節,游戲通過規則為以關卡作為二維數組的二維數組下標(下標),小 節作為 一位數組下標(下標+4)...文件里有具體實現,不啰嗦額;
5. 用戶登錄,通關每關游戲都會寫入游戲日志文檔game _log.txt ,記錄用戶,操 作,通關進度, 通關時間等
ps: 文件下載后,雙擊即可運行, 游戲的用戶文檔game_user.txt和日志文檔game_log.txt是按照我桌面路徑創建的,如果不喜歡可以直接修改為d:\game\game_user.txt等等,游戲不在乎多好玩, 希望能給想學習vbs的童鞋一些幫助
完整代碼
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
看完上述內容,你們對使用vbs怎么制作一個數字益智游戲有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。