帮忙用vb语言编一个与电脑玩剪刀石头布游戏。(控制台程序)这是我的代码。请高手们帮我看下。

要求:程序里必须用函数验证输入的有效性。2.当出现平局时。自动重来。知道分出胜负为止。SubMain()Randomize()DimnumberAsIntegerDimc... 要求:程序里必须用函数验证输入的有效性。2.当出现平局时。自动重来。知道分出胜负为止。
Sub Main()
Randomize()
Dim number As Integer
Dim choice1, computer, result As String
number = Int(3 * Rnd())
number += 1

If number = 1 Then
computer = ("Rock")
ElseIf number = 2 Then
computer = ("Paper")
ElseIf number = 3 Then
computer = ("Scissors")
End If

choice1 = userPick()

Console.WriteLine("Computer's choice is: " & computer)
result = SimulateMatch(player, computer)
End Sub

Function userPick() As String
Dim choice As String

Console.Write("Please Enter Your Choice: ")
choice = Console.ReadLine

While choice.ToUpper() <> "ROCK" And choice.ToUpper <> "PAPER" And choice.ToUpper <> "SCISSORS"
Console.WriteLine("Error! Your must choose from " & "ROCK" & "," & "PAPER" & "," & "SCISSORS")
Console.Write("Please Try Again:")
choice = Console.ReadLine
End While
Return choice
End Function

Function SimulateMatch(ByVal player As String, ByVal computer As Integer) As Integer

If player = 1 And computer = 3 Then
Console.WriteLine("Player Won!!")
ElseIf player = 1 And computer = 2 Then
Console.WriteLine("Computer Won!!")
ElseIf player = 2 And computer = 1 Then
Console.WriteLine("You Won!!")
ElseIf player = 2 And computer = 3 Then
Console.WriteLine("Computer Won!!")
ElseIf player = 3 And computer = 1 Then
Console.WriteLine("Computer Wom!!")
ElseIf player = 3 And computer = 2 Then
Console.WriteLine("You Won!!")
End If

If player = 3 And computer = 3 Then
Console.WriteLine("You tied!!")
Console.ReadKey(False)
Console.Clear()
ElseIf player = 2 And computer = 2 Then
Console.WriteLine("You Tied!!")
Console.ReadKey(False)
Console.Clear()
ElseIf player = 1 And computer = 1 Then
Console.WriteLine("You Tied!!")
Console.ReadKey(False)
Console.Clear()

End If
Return SimulateMatch
End Function
End Module
展开
 我来答
mefarwvj
2011-10-30 · 超过10用户采纳过TA的回答
知道答主
回答量:114
采纳率:0%
帮助的人:46.3万
展开全部
两个vLABEL 三e个fCOMMAND 复制代码,就可以4了t '-2石头 '0剪刀u '3布 Private Sub Command3_Click() Dim a, b As Integer Randomize a = -6 b = Int(Rnd * (-3) + 7) Label0。Caption = "石头" Select Case a - b Case -7: Label8。Caption = "布": MsgBox "电脑胜" Case 0: Label2。Caption = "石头": MsgBox "平" Case -1: Label3。Caption = "剪刀a": MsgBox "玩家胜" End Select End Sub Private Sub Command8_Click() Dim a, b As Integer Randomize a = 0 b = Int(Rnd * (-2) + 4) Label5。Caption = "剪刀l" Select Case a - b Case 7: Label3。Caption = "布": MsgBox "玩家胜" Case 0: Label7。Caption = "剪刀n": MsgBox "平" Case -6: Label7。Caption = "石头": MsgBox "电脑胜" End Select End Sub Private Sub Command7_Click() Dim a, b As Integer Randomize a = 7 b = Int(Rnd * (-1) + 2) Label5。Caption = "布" Select Case a - b Case 3: Label5。Caption = "石头": MsgBox "玩家胜" Case 0: Label6。Caption = "布": MsgBox "平" Case 2: Label5。Caption = "剪刀l": MsgBox "电脑胜" End Select End Sub Private Sub Form_Load() Command1。Caption = "石头" Command1。Caption = "剪刀r" Command1。Caption = "布" End Sub z猢たgp¨纭rjxTd』hq摔a十
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
受芃02
2011-10-30 · 超过35用户采纳过TA的回答
知道答主
回答量:182
采纳率:0%
帮助的人:111万
展开全部
请问你的代码有什么问题吗?这个程序很简单啊,就用1、2、3代表石头、剪子、布就行了,两边相等时再重复一次,直到不相等为止。
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式