主頁 > 知識庫 > vbs 自制數(shù)字益智游戲?qū)崿F(xiàn)代碼

vbs 自制數(shù)字益智游戲?qū)崿F(xiàn)代碼

熱門標(biāo)簽:哪里有便宜的地圖標(biāo)注公司 東營快遞外呼系統(tǒng) 地圖標(biāo)注政府哪個部門管 神行者美術(shù)館地圖標(biāo)注 佛山真人電銷機器人廠家 除了地圖標(biāo)注還有這種生意嗎 如何用機器人進(jìn)行電銷 百度地圖標(biāo)注點距離代碼 齊齊哈爾高德地圖標(biāo)注店

在看vb開發(fā),看到二維數(shù)組時突發(fā)奇想用二維數(shù)組作為游戲關(guān)卡;

1. 選擇操作: 游戲開始時會提示選擇注冊, 登錄, 退出三種選項,

2.注冊: 注冊成功會將用戶賬戶與密碼存入用戶數(shù)據(jù)txt文檔中,連續(xù)三次輸入 空值會直接退出游戲;

3. 登錄: 登錄時會將輸入數(shù)據(jù)與用戶數(shù)據(jù)文檔內(nèi)容進(jìn)行比對, 存在該用戶則登 錄成功, 同樣失敗三次后退出游戲;

4. 開始游戲: 登錄成功后,會直接進(jìn)入游戲,游戲暫定為三個關(guān)卡, 每個關(guān)卡三 個小節(jié),游戲通過規(guī)則為以關(guān)卡作為二維數(shù)組的二維數(shù)組下標(biāo)(下標(biāo)),小 節(jié)作為 一位數(shù)組下標(biāo)(下標(biāo)+4)...文件里有具體實現(xiàn),不啰嗦額;

5. 用戶登錄,通關(guān)每關(guān)游戲都會寫入游戲日志文檔game _log.txt ,記錄用戶,操 作,通關(guān)進(jìn)度, 通關(guān)時間等

ps: 文件下載后,雙擊即可運行, 游戲的用戶文檔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ù)組 二維長度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 "數(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ù)字猜猜猜小游戲 請選擇操作:"chr(10)" 1.注冊  2.登錄   3.退出","數(shù)字猜猜猜小游戲")
  If cnum ="" Then
     cnum = "-1"
  End if
 Select Case cnum
 Case 1 
' 賬戶注冊
Dim juname, upwd,regStr 
  regStr = ""
 do while regStr = ""
  uname = InputBox("請輸入注冊賬號:  ","數(shù)字猜猜猜小游戲-注冊")
  upwd = InputBox("請輸入注冊密碼:  ","數(shù)字猜猜猜小游戲-注冊")
  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 "數(shù)字猜猜猜小游戲-用戶數(shù)據(jù)"
          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("請輸入您的賬戶名與密碼,中間以#鍵隔開: "," 數(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 對象
     flagFailNum =0
    end if 
      MsgBox "您的賬戶與密碼輸入有誤,請查證后再試試...."
     str = InputBox("請輸入您的賬戶名與密碼,中間以#鍵隔開: "," 數(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 對象
     flagFailNum =0
    end if 
      MsgBox "您的賬戶與密碼輸入有誤,請查證后再試試...."
     str = InputBox("請輸入您的賬戶名與密碼,中間以#鍵隔開: "," 數(shù)字猜猜猜小游戲-登錄")
     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 "恭喜您成功登錄 數(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)" 請輸入游戲結(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 "抱歉,您猜錯了!請查證后再試...."
       result = InputBox("現(xiàn)在是游戲第"(i+1)"關(guān)第"(j+1)"小節(jié), 請輸入游戲結(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)...祝您好運!"
    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 "您的選擇有誤,請重新選擇..."
 failNum = failNum +1
End select

loop
  

這篇文章就介紹到這了,希望大家以后多多支持腳本之家。

標(biāo)簽:湖州 四平 西安 鶴壁 文山 銅川 邢臺

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《vbs 自制數(shù)字益智游戲?qū)崿F(xiàn)代碼》,本文關(guān)鍵詞  vbs,自制,數(shù)字,益智游戲,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《vbs 自制數(shù)字益智游戲?qū)崿F(xiàn)代碼》相關(guān)的同類信息!
  • 本頁收集關(guān)于vbs 自制數(shù)字益智游戲?qū)崿F(xiàn)代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章