用VB写一个和电脑猜石头剪刀布的小游戏(要代码)!

2024-11-25 16:31:23
推荐回答(3个)
回答1:

Dim com, you
do Until b=7
com=Int(3 * Rnd)+1
you=inputbox("1代表剪刀,2代表石头,3代表布","请输入一个1-3的数字")
if you = "" then
you=inputbox("1代表剪刀,2代表石头,3代表布","请重新输入一个1-3的数字")
else
if you = false then
exit do
Else
a ="":c=""
coms(com)
yous(int(you))
if int(you) = com then
msgbox "平局!你出的是:"&c&"电脑出的是:"&a
elseif int(you) - com = 1 or int(you) - com = -2 then
msgbox "恭喜,你赢了!你出的是:"&c&"电脑出的是:"&a
elseif int(you) - com = -1 or int(you) - com = 2 then
msgbox "真遗憾,你输了!你出的是:"&c&"电脑出的是:"&a
else
msgbox "请输入1-3的数字!"
end if
end if
b=MsgBox ("是否再来一次? ", 4+4096,"系统提示:")
end if
Loop
Function coms(num)
Select Case num
Case "1" a = "剪刀"
Case "2" a = "石头"
Case "3" a = "布"
End Select
End Function

Function yous(num)
Select Case num
Case "1" c = "剪刀"
Case "2" c = "石头"
Case "3" c = "布"
End Select
c=c&"--"
End Function
我给你代码,你百度HI我(我怕代码泄露!!!)

回答2:

Dim com, you
do Until b=7
com=Int(3 * Rnd)+1
you=inputbox("1代表剪刀,2代表石头,3代表布","请输入一个1-3的数字")
if you = "" then
you=inputbox("1代表剪刀,2代表石头,3代表布","请重新输入一个1-3的数字")
else
if you = false then
exit do
Else
a ="":c=""
coms(com)
yous(int(you))
if int(you) = com then
msgbox "平局!你出的是:"&c&"电脑出的是:"&a
elseif int(you) - com = 1 or int(you) - com = -2 then
msgbox "恭喜,你赢了!你出的是:"&c&"电脑出的是:"&a
elseif int(you) - com = -1 or int(you) - com = 2 then
msgbox "真遗憾,你输了!你出的是:"&c&"电脑出的是:"&a
else
msgbox "请输入1-3的数字!"
end if
end if
b=MsgBox ("是否再来一次? ", 4+4096,"系统提示:")
end if
Loop
Function coms(num)
Select Case num
Case "1" a = "剪刀"
Case "2" a = "石头"
Case "3" a = "布"
End Select
End Function

Function yous(num)
Select Case num
Case "1" c = "剪刀"
Case "2" c = "石头"
Case "3" c = "布"
End Select
c=c&"--"
End Function

回答3:

我给你代码,你百度HI我(我怕代码泄露!!!)