dimanche 8 décembre 2019

Visual Basics-when if statement is done, it seems repeat itself and say that the other player won. This makes the other players health 30-points less

I am new at coding and have a problem that I have not been able to solve. I am making a Pokemon battle scene and after you defeat the other player you the game will reset. For some reason if the opponent has 59 health and a move that takes out 30 health is used it says that you won because the value is now bellow 30.

Here is a part of my code

`lblComputerHealth.Text = prgcomputer.Value & "/ " & prgcomputer.Maximum
        If btnPlayerChoice.Text = "blastoise" Then
            If prgPlayer.Value <= 262 And prgPlayer.Value >= 183 Then
                prgPlayer.ForeColor = Color.Green
            ElseIf prgPlayer.Value <= 182 And prgPlayer.Value >= 131 Then
                prgPlayer.ForeColor = Color.Yellow
            ElseIf prgPlayer.Value <= 130 And prgPlayer.Value >= 66 Then
                prgPlayer.ForeColor = Color.Orange
            ElseIf prgPlayer.Value <= 65 Then
                prgPlayer.ForeColor = Color.Red
            End If

            If frmSplash.btnComputer.Text = "blastoise" Then
                If prgcomputer.Value <= 262 And prgcomputer.Value >= 183 Then
                    prgcomputer.ForeColor = Color.Green
                ElseIf prgcomputer.Value <= 182 And prgcomputer.Value >= 131 Then
                    prgcomputer.ForeColor = Color.Yellow
                ElseIf prgcomputer.Value <= 130 And prgcomputer.Value >= 66 Then
                    prgcomputer.ForeColor = Color.Orange
                ElseIf prgcomputer.Value <= 65 Then
                    prgcomputer.ForeColor = Color.Red
                End If
            End If

            If prgcomputer.Value <= 30 Then
                'ADD A DO YOU WISH TO PLAY AGAIN BUTTON
                MessageBox.Show("YOU WON")
                intWins += 1
                frmSplash.btnPlayerChoiceone.Text = ""
                intwhy = 1
                strplayerchoice = ""
                intCompAttack = 0
                intwhyone = 0
                strcool = ""
                frmSplash.btnComputer.Text = ""
                frmSplash.btnPlayerChoiceone.Text = ""
                picPlayer.Image = Nothing
                picComputer.Image = Nothing
                btnChoosePlayer.Visible = True
                btnMoveOne.Visible = False
                btnMoveTwo.Visible = False
                btnMoveThree.Visible = False
                btnMoveFour.Visible = False
                prgPlayer.Value = 262
                prgcomputer.Value = 262
                lblWins.Text = intWins
                prgcomputer.ForeColor = Color.ForestGreen
                prgPlayer.ForeColor = Color.Green
            Else
                prgcomputer.Value = prgcomputer.Value - 30
            End If

        End If
            If frmSplash.btnComputer.Text = "blastoise" Then
                MessageBox.Show("Oponent thinking of move")

                Threading.Thread.Sleep(1000)

                intCompAttack = rand.Next(2) 'you will have to make this 3 some day
                Select Case intCompAttack
                    Case 0
                        prgPlayer.Value -= 20
                        lblPlayerHealth.Text = prgPlayer.Value & "/ " & prgPlayer.Maximum
                        MessageBox.Show("Opponent used Tackle and delt 20 damage")
                            'use a loop in the animation
                    Case 1
                        prgPlayer.Value -= 30
                        lblPlayerHealth.Text = prgPlayer.Value & "/ " & prgPlayer.Maximum
                        MessageBox.Show("opponent used Water Gun and delt 30 damage")
                End Select

            End If'

here is the part that I think is not working

'If prgcomputer.Value <= 30 Then
                'ADD A DO YOU WISH TO PLAY AGAIN BUTTON
                MessageBox.Show("YOU WON")
                intWins += 1
                frmSplash.btnPlayerChoiceone.Text = ""
                intwhy = 1
                strplayerchoice = ""
                intCompAttack = 0
                intwhyone = 0
                strcool = ""
                frmSplash.btnComputer.Text = ""
                frmSplash.btnPlayerChoiceone.Text = ""
                picPlayer.Image = Nothing
                picComputer.Image = Nothing
                btnChoosePlayer.Visible = True
                btnMoveOne.Visible = False
                btnMoveTwo.Visible = False
                btnMoveThree.Visible = False
                btnMoveFour.Visible = False
                prgPlayer.Value = 262
                prgcomputer.Value = 262
                lblWins.Text = intWins
                prgcomputer.ForeColor = Color.ForestGreen
                prgPlayer.ForeColor = Color.Green
            Else
                prgcomputer.Value = prgcomputer.Value - 30
            End If    `

Aucun commentaire:

Enregistrer un commentaire