我在完成 RPS 游戏的代码时遇到了一些困难。说明如下: c.主按钮单击代码。一世。您需要像我们之前所做的那样使用输入框提示用户输入三个字母之一。ii. 从您的自定义方法中获取随机字母。iii. 将用户的信件和随机的计算机信件都传递给您的其他方法。iv. 如果返回 true,则告诉用户他们在您添加到表单的标签中获胜,否则告诉他们他们在该标签中失败。
我认为我正确地执行了 1 和 2,但我遇到了 3 和 4 的问题。有人可以帮忙!
到目前为止,这是我的代码
Public Class Form1
Dim randomObject As New Random()
Private Property user As String
Private Property computer As Random
Function GetRandomRPSLetter() As String
randomObject.Next(1, 4)
Dim computer As Integer = randomObject.Next(1, 4)
If computer = 1 Then
Return "r"
ElseIf computer = 2 Then
Return "p"
Else
Return "s"
End If
End Function
Function GetRPSRoundWinner(ByVal user As String, ByVal computer As String) As String
If user = "r" Then
If computer = "r" Then
Return False
ElseIf computer = "p" Then
Return False
Else
Return True
End If
ElseIf user = "p" Then
If computer = "r" Then
Return True
ElseIf computer = "p" Then
Return False
Else
Return False
End If
Else
If computer = "r" Then
Return False
ElseIf computer = "p" Then
Return True
Else
Return False
End If
End If
End Function
Private Sub Button1_click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
user = InputBox("Please input r, p, or s to play")
GetRandomRPSLetter()
End Sub
Sub GetRPSRoundWinner()
If GetRPSRoundWinner(True) Then Return
Label1.Text = "You win"
End Sub
Private Function GetRPSRoundWinner(p1 As Boolean) As Boolean
Throw New NotImplementedException
End Function
End Class
现在我打电话给 GetRPSRoundWinner
Private Sub Button1_click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
user = InputBox("Please input r, p, or s to play")
GetRandomRPSLetter()
GetRPSRoundWinner()
End Sub
谁能帮助我如何比较它们?
非常感谢大家!