Visual Basic跳过If语句

时间:2018-08-02 01:33:39

标签: .net vb.net

请不要将此标记为重复,因为我只能在c ++和c#上找到我需要的线程。

我很高兴地报告我的游戏几乎可以完全正常运行,但是我已经设置了它,因此当玩家得分值为10时,它会弹出一个胜利对话框,询问您是否要再次玩,并且计算机分数是否达到10还是一样除了失败

跳过播放器的if语句,因为当计算机达到10时,它将弹出一个失败对话框,但是当播放器达到10时,不会触发if语句

帮助?

Public Class gameForm
    Dim playerscore As Integer = 0
    Dim comscore As Integer = 0



    Private Sub btnPlay_Click(sender As Object, e As EventArgs) Handles btnPlay.Click
        Try

            Dim rock = 3
            Dim paper = 2
            Dim scissors = 1
            Dim num As Integer = CInt(Int((3 * Rnd()) + 1))
            Randomize()


            ' IF PLAYER CHOOSES ROCK
            If rbRock.Checked And num = rock Then
                lblPlayerChoice.Text = "You Chose Rock"
                lblComChoice.Text = "Computer Chose Rock"
                lblOutcome.Text = "DRAW"
            ElseIf rbRock.Checked And num = paper Then
                lblPlayerChoice.Text = "You Chose Rock"
                lblComChoice.Text = "Computer Chose Paper"
                lblOutcome.Text = "YOU LOSE"
                comscore = comscore + 1
                lblComScoreVal.Text = CStr(comscore)
            ElseIf rbRock.Checked And num = scissors Then
                lblPlayerChoice.Text = "You Chose Rock"
                lblComChoice.Text = "Computer Chose Scissors"
                lblOutcome.Text = "YOU WIN"
                playerscore = playerscore + 1
                lblPlayerScoreVal.Text = CStr(playerscore)
            End If

            ' IF PLAYER CHOOSES PAPER
            If rbPaper.Checked And num = rock Then
                lblPlayerChoice.Text = "You Chose Paper"
                lblComChoice.Text = "Computer Chose Rock"
                lblOutcome.Text = "YOU WIN"
                playerscore = playerscore + 1
                lblPlayerScoreVal.Text = CStr(playerscore)
            ElseIf rbPaper.Checked And num = paper Then
                lblPlayerChoice.Text = "You Chose Paper"
                lblComChoice.Text = "Computer Chose Paper"
                lblOutcome.Text = "DRAW"
            ElseIf rbPaper.Checked And num = scissors Then
                lblPlayerChoice.Text = "You Chose Paper"
                lblComChoice.Text = "Computer Chose Scissors"
                lblOutcome.Text = "YOU LOSE"
                comscore = comscore + 1
                lblComScoreVal.Text = CStr(comscore)

            End If

            ' IF PLAYER CHOOSES SCISSORS

            If rbScissors.Checked And num = rock Then
                lblPlayerChoice.Text = "You Chose Scissors"
                lblComChoice.Text = "Computer Chose Rock"
                lblOutcome.Text = "YOU LOSE"
                comscore = comscore + 1
                lblComScoreVal.Text = CStr(comscore)
            ElseIf rbScissors.Checked And num = paper Then
                lblPlayerChoice.Text = "You Chose Scissors"
                lblComChoice.Text = "Computer Chose Paper"
                lblOutcome.Text = "YOU WIN"
                playerscore = playerscore + 1
                lblPlayerScore.Text = CStr(playerscore)
            ElseIf rbScissors.Checked And num = scissors Then
                lblPlayerChoice.Text = "You Chose Scissors"
                lblComChoice.Text = "Computer Chose Scissors"
                lblOutcome.Text = "DRAW"


            End If

            If playerscore = 10 Then
                Dim victory As MsgBoxResult = MsgBox("You Won, Congratulations!" & vbCrLf & "Would You Like To Play Again?", "VICTORY", MessageBoxButtons.YesNo)
                If victory = MsgBoxResult.Yes Then
                    playerscore = 0
                    comscore = 0
                    lblPlayerScoreVal.Text = CStr(playerscore)
                    lblComScoreVal.Text = CStr(comscore)
                    lblPlayerChoice.Text = Nothing
                    lblComChoice.Text = Nothing
                    lblOutcome.Text = Nothing
                Else
                    Me.Close()
                End If
            End If

            If comscore = 10 Then
                Dim defeat As MsgBoxResult = MsgBox("You Were Defeated, Unlucky!" & vbCrLf & "Would You Like To Play Again?", MessageBoxButtons.YesNo)
                If defeat = MsgBoxResult.Yes Then
                    playerscore = 0
                    comscore = 0
                    lblPlayerScoreVal.Text = CStr(playerscore)
                    lblComScoreVal.Text = CStr(comscore)
                    lblPlayerChoice.Text = Nothing
                    lblComChoice.Text = Nothing
                    lblOutcome.Text = Nothing
                Else
                    Me.Close()
                End If
            End If


        Catch ex As Exception

        End Try

    End Sub
End Class

1 个答案:

答案 0 :(得分:0)

当我将MsgBox(“胜利的东西放在这里”,“胜利”,messageboxbuttons.yesno)上时 我是gettign语法错误,它将显示窗口标题是您在消息框中输入的最后一句话