VBS猜数游戏

VBS 猜数游戏

2018-11-09  21:19:11

by xutao

 1 msgbox "The Swami" ,,"Game"
 2 msgbox "The system will give a integer in the range of 1 to 100 randomly, and you are allowed to guess a integer one time! Less tries, more luck" , ,"Rule"
 3 while 1=1   '无限循环
 4 
 5 dim tryTime  '尝试次数
 6 tryTime = 1
 7 
 8 dim n 
 9 randomize  '初始化随机种子,不然每次都会一样
10 n = int(rnd*100)
11 
12 int input
13 input = int(inputbox("Guess it"))
14 
15 '注意:while语句的语法是: while condition  ... wend (不加then)
16 
17 while n <> input  
18 tryTime = tryTime+1
19 if input>n then
20 input = int(inputbox("Too big! Try again!"))
21 else 
22 input = int(inputbox("Too small! Try again!"))
23 end if
24 wend
25 
26 if tryTime=1 then
27 msgbox "Genius! Buy a lottery ticket quickly!"
28 elseif tryTime=2 then
29 msgbox "666"
30 elseif tryTime=3 then
31 msgbox "NB"
32 elseif tryTime=4 then
33 msgbox "Cool!"
34 elseif tryTime=5 then 
35 msgbox "Good!"
36 elseif tryTime=6 then 
37 msgbox "Not Bad!"
38 elseif tryTime=7 then
39 msgbox "Unfortuntate!"
40 elseif tryTime=8 then
41 msgbox "Idiot!"
42 else 
43 msgbox "SB!"
44 end if
45 
47 if msgbox("ReTry?",vbOK)<>1 then
48 msgbox "Bye!"
49 wscript.quit
50 end if
51 
53 wend

 

posted @ 2018-11-09 21:22  Edwin_Xu  阅读(1787)  评论(0编辑  收藏  举报