As a project over the summer I am making a little game in which you have to battle an enemy, but there is something wrong with the code:
Dim X
Dim Power
Dim EPower
Dim EHP
Dim HP
Private Sub bite1_Click()
Power = Power + 1
End Sub
Private Sub cmdGo_Click()
Attack
EAttack
If optHeal.Value = True Then
Heal
optHeal.Enabled = False
End If
Reload
End Sub
Public Sub Attack()
EHP = EHP - Power
lblHP.Caption = "HP: " + Str(EHP) + "/10"
If Power < 1 Then
MsgBox "You must select something", vbOKOnly, "Error"
End If
If HP < 1 Then
MsgBox "Winner: The Knight || Loser: " + frmCreate.txtName.Text, vbOKOnly, "End Battle"
Unload frmCastleB
frmBattle.Show
End If
If HP < 0 Then
HP = 0
End If
lblDamage.Caption = "Damage Potential: " + Str(Power)
End Sub
Private Sub Form_Load()
HP = 10
EHP = 10
Power = 0
EPower = 0
If HP < 1 And EHP < 1 Then
MsgBox "No Winner", vbOKOnly, "End Battle"
End If
End Sub
Public Sub EAttack()
Dim X
upperbound = 3
lowerbound = 1
X = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
EPower = X
HP = HP - EPower
lblHP2.Caption = "HP: " + Str(HP) + "/10"
If HP < 0 Then
PutRight
End If
If EHP < 1 Then
MsgBox "Winner: " + frmCreate.txtName.Text + " || Loser: The Knight", vbOKOnly, "End Battle"
Unload frmCastleB
frmBattle.Show
frmBattle.optCastle.Enabled = False
End If
End Sub
Private Sub hsbPower_Change()
lblPower.Caption = "Ability Power: " + Str(hsbPower.Value)
End Sub
Private Sub uab_Click()
Power = Power + hsbPower.Value
End Sub
Public Sub Heal()
HP = HP + 2
End Sub
Public Sub Reload()
Power = Power - Power
EPower = EPower - EPower
uab.Value = 0
bite1.Value = False
optHeal.Value = False
hsbPower.Value = 0
End Sub
Public Sub PutRight()
Dim Q
Q = 0 - HP - Q
End Sub
--------------
The thing that is wrong is when on one turn you use your ability (by selecting a power level with hsbPower, selecting the 'uab' check box and hitting 'Go') the turn after that, if you hit 'Go' without selecting anything, 4 damage is done to the opponent. I don't know what part of the code this error was in, so I had to post the whole thing. In case there is anyone who doesn't play many games like this, HP means Hit Points (or Health Points) and when you get to zero, you die.
Dim X
Dim Power
Dim EPower
Dim EHP
Dim HP
Private Sub bite1_Click()
Power = Power + 1
End Sub
Private Sub cmdGo_Click()
Attack
EAttack
If optHeal.Value = True Then
Heal
optHeal.Enabled = False
End If
Reload
End Sub
Public Sub Attack()
EHP = EHP - Power
lblHP.Caption = "HP: " + Str(EHP) + "/10"
If Power < 1 Then
MsgBox "You must select something", vbOKOnly, "Error"
End If
If HP < 1 Then
MsgBox "Winner: The Knight || Loser: " + frmCreate.txtName.Text, vbOKOnly, "End Battle"
Unload frmCastleB
frmBattle.Show
End If
If HP < 0 Then
HP = 0
End If
lblDamage.Caption = "Damage Potential: " + Str(Power)
End Sub
Private Sub Form_Load()
HP = 10
EHP = 10
Power = 0
EPower = 0
If HP < 1 And EHP < 1 Then
MsgBox "No Winner", vbOKOnly, "End Battle"
End If
End Sub
Public Sub EAttack()
Dim X
upperbound = 3
lowerbound = 1
X = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
EPower = X
HP = HP - EPower
lblHP2.Caption = "HP: " + Str(HP) + "/10"
If HP < 0 Then
PutRight
End If
If EHP < 1 Then
MsgBox "Winner: " + frmCreate.txtName.Text + " || Loser: The Knight", vbOKOnly, "End Battle"
Unload frmCastleB
frmBattle.Show
frmBattle.optCastle.Enabled = False
End If
End Sub
Private Sub hsbPower_Change()
lblPower.Caption = "Ability Power: " + Str(hsbPower.Value)
End Sub
Private Sub uab_Click()
Power = Power + hsbPower.Value
End Sub
Public Sub Heal()
HP = HP + 2
End Sub
Public Sub Reload()
Power = Power - Power
EPower = EPower - EPower
uab.Value = 0
bite1.Value = False
optHeal.Value = False
hsbPower.Value = 0
End Sub
Public Sub PutRight()
Dim Q
Q = 0 - HP - Q
End Sub
--------------
The thing that is wrong is when on one turn you use your ability (by selecting a power level with hsbPower, selecting the 'uab' check box and hitting 'Go') the turn after that, if you hit 'Go' without selecting anything, 4 damage is done to the opponent. I don't know what part of the code this error was in, so I had to post the whole thing. In case there is anyone who doesn't play many games like this, HP means Hit Points (or Health Points) and when you get to zero, you die.