这是我对阵列的第二次尝试。在我的代码中,我使用了For-Next循环,数组,select case和嵌套的If-Else语句的组合。我的特殊问题是,当我运行我的代码来检查是否首先,我是否在战斗中,如果没有,那么检查战斗之外的愈合,如果玩家完全健康,则显示一条说明健康状况的消息已满了。
我不得不改变一些东西,在这里的其他帖子的帮助下,其余的显示器工作正常,我只是看到了Full Health Display的问题。相关代码如下:
按钮用于计算攻击名称:
Private Sub btnAtkOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAtkOne.Click
SelectedButton = 1
CheckAttack()
End Sub
Private Sub btnAtkTwo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAtkTwo.Click
SelectedButton = 2
CheckAttack()
End Sub
Private Sub btnAtkThree_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAtkThree.Click
SelectedButton = 3
CheckAttack()
End Sub
接下来是检查攻击的Sub:
Private Sub CheckAttack()
Select Case SelectedButton
Case 1
If Battle = False Then
SelectedAtk = lblAtkOne.Text
LocateValue()
If Heals > 0 Then
If PlayerCurHP < PlayerMaxHP Then
For i = 1 To Heals
If PlayerCurHP < PlayerMaxHP Then
PlayerCurHP += 1
End If
Next
If Heals > 0 Then
Heals = 0
UpdateLabels()
Else
MessageBox.Show("HP is Full!", "Full HP!", MessageBoxButtons.OK)
End If
End If
End If
End If
Case 2
If Battle = False Then
SelectedAtk = lblAtkTwo.Text
LocateValue()
If Heals > 0 Then
If PlayerCurHP < PlayerMaxHP Then
For i = 1 To Heals
If PlayerCurHP < PlayerMaxHP Then
PlayerCurHP += 1
End If
Next
If Heals > 0 Then
Heals = 0
UpdateLabels()
Else
MessageBox.Show("HP is Full!", "Full HP!", MessageBoxButtons.OK)
End If
End If
End If
End If
Case 3
If Battle = False Then
SelectedAtk = lblAtkThree.Text
LocateValue()
If Heals > 0 Then
If PlayerCurHP < PlayerMaxHP Then
For i = 1 To Heals
If PlayerCurHP < PlayerMaxHP Then
PlayerCurHP += 1
End If
Next
If Heals > 0 Then
Heals = 0
UpdateLabels()
Else
MessageBox.Show("HP is Full!", "Full HP!", MessageBoxButtons.OK)
End If
End If
End If
End If
Case Else
MessageBox.Show("Not a Valid Selection", "Error Selecting Attack", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Select
SelectedButton = 0
End Sub
最后是用于确定所选攻击的治疗价值的代码:
Private Sub LocateValue()
For Row = 1 To 4
If SelectedAtk = PlayerClass(Row - 1, 0) Then
If PlayerClass(Row - 1, 3) = "True" Then
Heals = Convert.ToInt32(PlayerClass(Row, 4))
Exit For
If Heals <= 0 Then
MessageBox.Show("Cannot Use Outside of Battle", "Battle Move Only", MessageBoxButtons.OK)
Heals = 0
Exit For
End If
End If
Else
MessageBox.Show("Could Not Find Attack", "Sorry", MessageBoxButtons.OK)
Exit For
End If
Next
End Sub