(這是vb在一個控制檯應用程序btw表達)我是編程新手,所以忍受我 - 我試圖做一個小口袋妖怪的戰鬥(俗氣,我知道),除了事實上敵人在一回閤中攻擊了3次,這是一種複雜的事實,它工作得很好。這是我的代碼 - 我該如何解決這個問題?小寵物小精靈之戰 - 敵人一擊三次攻擊
Module Module1
Sub Main()
Dim num As Integer
Dim num1 As Integer
Dim num2 As Integer
Dim num3 As Integer
num = 0
Console.WriteLine("select the wild zigzagoon's health.")
num3 = Console.ReadLine
Console.WriteLine("select charmander's health.")
num2 = Console.ReadLine
Console.WriteLine("a wild zigzagoon appeared! go, charmander!")
While num3 > 0 And num2 > 0
Console.WriteLine("what will charmander do? use tackle(1), burn(2), smack(3) or ember(4)?")
num1 = Console.ReadLine
If num1 > 0 And num1 < 2 Then
num3 = num3 - 15
Console.WriteLine("charmander used tackle! zigzagoon took 15 damage! zigzagoon is on " & num3)
num = num + 1
ElseIf num = 1 Then
num2 = num2 - 10
Console.WriteLine("zigzagoon used tackle! charmander took 10 damage! charmander is now on " & num2)
ElseIf num = 2 Then
num2 = num2 - 20
Console.WriteLine("zigzagoon used quick attack! charmander took 15 damage! charmander is now on" & num2)
ElseIf num = 3 Then
num2 = num2 - 25
Console.WriteLine("zigzagoon used headbutt! charmander took 25 damage! charmander is now on" & num2)
ElseIf num = 4 Then
num2 = num2 - 40
Console.WriteLine("zigzagoon used take down! charmander took 40 damage! charmander is now on " & num2)
End If
If num1 > 1 And num1 < 3 Then
num3 = num3 - 20
Console.WriteLine("charmander used burn! zigzagoon took 20 damage! zigzagoon is now on " & num3)
num = num + 1
ElseIf num = 1 Then
num2 = num2 - 10
Console.WriteLine("zigzagoon used tackle! charmander took 10 damage! charmander is now on " & num2)
ElseIf num = 2 Then
num2 = num2 - 20
Console.WriteLine("zigzagoon used quick attack! charmander took 15 damage! charmander is now on" & num2)
ElseIf num = 3 Then
num2 = num2 - 25
Console.WriteLine("zigzagoon used headbutt! charmander took 25 damage! charmander is now on" & num2)
ElseIf num = 4 Then
num2 = num2 - 40
Console.WriteLine("zigzagoon used take down! charmander took 40 damage! charmander is now on " & num2)
num = num - 4
End If
If num1 > 2 And num1 < 4 Then
num3 = num3 - 30
Console.WriteLine("charmander used smack! zigzagoon took 30 damage! zigzagoon is now on " & num3)
num = num + 1
ElseIf num = 1 Then
num2 = num2 - 10
Console.WriteLine("zigzagoon used tackle! charmander took 10 damage! charmander is now on " & num2)
ElseIf num = 2 Then
num2 = num2 - 20
Console.WriteLine("zigzagoon used quick attack! charmander took 15 damage! charmander is now on" & num2)
ElseIf num = 3 Then
num2 = num2 - 25
Console.WriteLine("zigzagoon used headbutt! charmander took 25 damage! charmander is now on" & num2)
ElseIf num = 4 Then
num2 = num2 - 40
Console.WriteLine("zigzagoon used take down! charmander took 40 damage! charmander is now on " & num2)
num = num - 4
End If
If num1 > 3 And num1 < 5 Then
num3 = num3 - 40
Console.WriteLine("charmander used ember! zigzagoon took 30 damage! zigzagoon is now on " & num3)
ElseIf num = 1 Then
num2 = num2 - 10
Console.WriteLine("zigzagoon used tackle! charmander took 10 damage! charmander is now on " & num2)
ElseIf num = 2 Then
num2 = num2 - 20
Console.WriteLine("zigzagoon used quick attack! charmander took 15 damage! charmander is now on" & num2)
ElseIf num = 3 Then
num2 = num2 - 25
Console.WriteLine("zigzagoon used headbutt! charmander took 25 damage! charmander is now on" & num2)
ElseIf num = 4 Then
num2 = num2 - 40
Console.WriteLine("zigzagoon used take down! charmander took 40 damage! charmander is now on " & num2)
num = num - 4
End If
End While
If num3 <= 0 Then
Console.WriteLine("the wild zigzagoon fainted! charmander gained 30 xp!. charmander leveled up to level 6!")
End If
End Sub
End Module
對於初學者改變你的變量爲特定的東西。例如:CharmanderCommand,CharmanderHealth,ZigazoonHealth分別爲num1,num2,num3。這將幫助您閱讀代碼。至於你提到的問題,也許而不是一個while循環,它應該是一個簡單的if語句。 –
也使用Select Case語句代替elseif –