我的脑袋现在在转,可能是因为我漏掉了一些基本的逻辑。
我在vb.net中有一个“石头、纸、剪刀”程序,它为每个单独的游戏/回合提供正确的结果。我遇到的问题是,当我试图确定一场比赛的结果时,这场比赛也可能是一场“赢、输、平”的比赛比赛分为3强(先到2强)和5强(先到3强)。由于匹配的结果可以是平局,因此有各种组合/排列,例如:
宽,长,深
长、宽、深
左,右,西
D、L、W
W,D,L,…等。。。
到目前为止,我有以下代码:

    Public Class GameForm
    Private humanScore As Integer = 0
    Private compScore As Integer = 0
    Private drawScore As Integer = 0
    Private totalGames As Integer = 0
    Private totalGamesForWin As Integer = 0
    Private totalGamesPlayed As Integer = 0
    Private player1 = New PlayerHumanPlayer()
    Private player2 = New PlayerComputerRandom()


    Private Sub GameForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If GameTypeForm.cmboMatchDuration.SelectedItem = 0 Then
            totalGames = 3
            totalGamesForWin = 2
            lblMatchInfor.Text = GlobalVariables.MatchTypeBestOf3Message
        ElseIf (GameTypeForm.cmboMatchDuration.SelectedItem = 1) Then
            totalGames = 5
            totalGamesForWin = 3
            lblMatchInfor.Text = GlobalVariables.MatchTypeBestOf5Message
        End If

    End Sub

    Private Sub btnRock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRock.Click
        findGameWinner("HumanPlayer", "Rock", "RandomComputer")
    End Sub

    Private Sub btnPaper_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPaper.Click
        findGameWinner("HumanPlayer", "Paper", "RandomComputer")
    End Sub


    Private Sub btnScissors_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnScissors.Click
        findGameWinner("HumanPlayer", "Scissors", "RandomComputer")
    End Sub

    Public Sub findGameWinner(ByVal p1name As String, ByVal p1WeaponSelected As String, ByVal p2Name As String)

        player1.Name = p1name
        player1.pickWeapon(p1WeaponSelected)  ' Should I be using the Rock Class???

        player2.Name = p2Name
        player2.pickWeapon()

        Dim winner As Integer = player1.getWeapon().compareTo(player2.getWeapon())

        Select Case winner
            Case 1
                updateScores(True, False)
                findMatchWinner()
            Case -1
                updateScores(False, True)
                findMatchWinner()
            Case 0
                updateScores(False, False)
                findMatchWinner()
        End Select
    End Sub

    Public Function updateScores(ByVal humanWon As Boolean, ByVal compWon As Boolean) As Integer

        If humanWon = True Then
            humanScore = humanScore + 1

            'Update Human labels
            lblPlayerScore.Text = humanScore.ToString()
            'txtCompChoice.Text = txtCompChoice.Text + Environment.NewLine + Type.GetType(player2.pWeapon.ToString()).ToString()
            txtCompChoice.Text = txtCompChoice.Text + Environment.NewLine + player2.pWeapon.ToString()
            txtGameStatus.Text = txtGameStatus.Text + Environment.NewLine + player1.Name() + " wins!"

        ElseIf compWon = True Then
            compScore = compScore + 1

            'Update Computer labels
            lblCompScore.Text = compScore.ToString()
            'txtCompChoice.Text = txtCompChoice.Text + Environment.NewLine + Type.GetType(player2.pWeapon.ToString()).ToString()
            txtCompChoice.Text = txtCompChoice.Text + Environment.NewLine + player2.pWeapon.ToString()
            txtGameStatus.Text = txtGameStatus.Text + Environment.NewLine + player2.Name() + " wins!"

        Else
            drawScore = drawScore + 1

            'Update Draw labels
            lblDrawGame.Text = drawScore.ToString()
            'txtCompChoice.Text = txtCompChoice.Text + Environment.NewLine + Type.GetType(player2.pWeapon.ToString()).ToString()
            txtCompChoice.Text = txtCompChoice.Text + Environment.NewLine + player2.pWeapon.ToString()
            txtGameStatus.Text = txtGameStatus.Text + Environment.NewLine + "Draw!"

        End If

        totalGamesPlayed = totalGamesPlayed + 1

        Return totalGamesPlayed
    End Function


    Public Function findMatchWinner() As String

        If totalGamesPlayed <> totalGames Then
            If humanScore = totalGamesForWin Then
                lblMatchInfor.Text = GlobalVariables.HumanMacthWinMessage
                clearForm()
            ElseIf compScore = totalGamesForWin Then
                lblMatchInfor.Text = GlobalVariables.CompMacthWinMessage
                clearForm()
            ElseIf totalGamesPlayed = totalGames - 1 Then
                lblMatchInfor.Text = GlobalVariables.DeciderGameMessage
            End If
        ElseIf humanScore = totalGamesForWin Then
            lblMatchInfor.Text = GlobalVariables.HumanMacthWinMessage
            clearForm()
        ElseIf compScore = totalGamesForWin Then
            lblMatchInfor.Text = GlobalVariables.CompMacthWinMessage
            clearForm()
        ElseIf (drawScore = totalGamesPlayed) Then
            lblMatchInfor.Text = GlobalVariables.DrawMacthWinMessage
            clearForm()
        End If

        Return "Human OR Computer"
    End Function

    Public Sub clearForm()

    End Sub

End Class

我以为我做得很好,直到我记起我完全忘记了平局。从那以后,我的脑子一直在循环,所以有人能不能告诉我如何让findMatchWinner()函数正常工作?
任何帮助都将不胜感激。
曼尼提前谢谢

最佳答案

我建议你不要检查一个玩家赢了多少,看看这是否是预期的回合数,你可以只记录两个付款人的赢数,并在最后进行比较。
如果球员a>球员b,那么球员a获胜,如果他们是相同的,那就是平局。另外,记住一场3回合的比赛不需要2胜一方,因为球员A可以赢一次,然后所有其他比赛都可以平局。

10-04 10:00