在战斗模拟器上的Microsoft.VisualBasic.dll中发生了'System.InvalidCastException'类型的第一次机会异常

时间:2013-11-01 22:55:56

标签: vb.net

我有一个问题,试图为我和另一个人正在进行的项目编写简单的战斗模拟。

模块模块1

Dim Player_Vitality As Integer



Dim PlayerReiatsu As Integer
Dim PlayerZanjustu As Integer
Dim PlayerHakuda As Integer
Dim PlayerHoho As Integer
Dim PlayerKido As Integer
Dim PlayerAbility As Integer



Dim Player_Physical_Damage As Integer
Dim Player_Spirit_Damage As Integer
Dim Player_Critical_Chance As Integer
Dim Player_Critical_Damage As Integer





Sub Main()



    Call Shuhei()



End Sub





Sub Shuhei()

    Dim Shuhei_reiatsu As Integer
    Dim Shuhei_Vitality_TurnStart As Integer
    Dim Shuhei_Vitality_TurnEnd As Integer
    Dim Attack As String
    Dim Kido As Integer
    Dim Sword As Integer
    Dim Shuhei_Temp As Integer






    PlayerZanjustu = 40
    PlayerHakuda = 50
    PlayerKido = 50
    PlayerAbility = 75
    Shuhei_reiatsu = 80

    Kido = Player_Spirit_Damage
    Sword = Player_Physical_Damage

    'Player_Vitality = 100
    Shuhei_Vitality_TurnStart = 1000



    Console.WriteLine("FIGHT 1")
    Console.ReadLine()

    Do While Shuhei_Vitality_TurnStart > 0



        Player_Physical_Damage = ((PlayerZanjustu + PlayerHakuda) - Shuhei_reiatsu)
        Player_Spirit_Damage = ((PlayerKido + PlayerAbility) - Shuhei_reiatsu)
        'Player_Critical_Chance = ((PlayerZanjustu + PlayerHoho) - Shuhei_reiatsu) / 100
        'Player_Critical_Damage = (PlayerZanjustu + PlayerHakuda) * 10

        Shuhei_Temp = Shuhei_Vitality_TurnStart

        Console.WriteLine("Shuhei has " & Shuhei_Temp & "Hp")
        Console.WriteLine("Which attack do you want to use?")
        Attack = Console.ReadLine




        If Attack = "Kido" Or Kido Then

            Shuhei_Vitality_TurnEnd = ((Shuhei_Temp) - Player_Spirit_Damage)
        ElseIf Attack = "Sword" Or Sword Then

            Shuhei_Vitality_TurnEnd = Shuhei_Temp - Player_Physical_Damage

        Else
            Console.WriteLine("Please choose an attack")

        End If

        Shuhei_Vitality_TurnEnd = Shuhei_Vitality_TurnStart
        If Shuhei_Vitality_TurnStart <= 0 Then
            Call FightEnd()
        End If
    Loop

    Console.ReadKey()
End Sub

Sub FightEnd()
    Console.WriteLine("Shuhei has been defeated")
    Console.ReadKey()
End Sub

这一切都被复制到了一个新的子点,其中有一个没有用途的去激活垃圾,所以我怀疑这是问题,它只是战斗代码的骨架,但是'在前面禁用它。然后在底部的End Module命令

1 个答案:

答案 0 :(得分:0)

IF声明中Attack绝不可能是"Kido"Kido。您正在将字符串与字符串或字符串与整数进行比较,这可能是您的问题。尝试将Kido变量转换为字符串,这可能会导致错误。

伪代码:

If Attack = "Kido" Or Kido.ToString