-1
我正在嘗試製作先生和女士風格的遊戲,其中一位用戶輸入答案,另一位用戶試圖猜測其他人說的話。一切工作到比較用戶答案的部分,以查看誰是正確的。我不確定究竟是什麼錯誤。任何幫助是非常讚賞的。需要幫助爲先生和夫人遊戲製作分數理論
Module Module1
Sub Main()
Dim Question(4) As String
Dim P1Answer(4) As String
Dim P2Answer(4) As String
Dim P1Name As String = ""
Dim P2Name As String = ""
Dim Count As Integer = 0
Dim UserScore As Integer = 0
Const ArraySize As Integer = 5
While Count <> 4
Question(Count) = ""
Count = Count + 1
End While
Count = 0
Question(0) = " favourite colour?"
Question(1) = " age?"
Question(2) = " best friends name?"
Question(3) = " favourite food?"
Question(4) = " first pet's name?"
Console.WriteLine("Enter the name of player 1")
P1Name = Console.ReadLine
Console.WriteLine("Enter the name of player 2")
P2Name = Console.ReadLine
Console.WriteLine(P1Name & ". Please get ready to enter your answers.")
Console.WriteLine("Tell " & P2Name & " to go away while you answer the questions")
Console.WriteLine("Press enter when you are ready to begin.")
Console.ReadLine()
While ArraySize <> Count
Console.WriteLine("What is your" & Question(Count))
P1Answer(Count) = Console.ReadLine
Count = Count + 1
End While
Count = 0
Console.Clear()
Console.WriteLine("Tell " & P2Name & " to come back now.")
Console.WriteLine(P2Name & ". Please get ready to enter your answers.")
Console.WriteLine("Press enter when you are ready to begin.")
Console.ReadLine()
While ArraySize <> Count
Console.WriteLine("What is " & P1Name & "'s" & Question(Count))
P2Answer(Count) = Console.ReadLine
Count = Count + 1
End While
Count = 0
**While Count <> 5
If P1Answer(Count) = P2Answer(Count) Then
UserScore = UserScore + 1
Else
UserScore = UserScore
End If
Question(Count) = Question(Count + 1)
End While**
Console.WriteLine("Your total score is " & UserScore)
Console.ReadLine()
End Sub
前端模塊
在該循環的開始處設置斷點,然後觀察代碼執行;您可以使用鼠標查看每個答案陣列中的內容並進行比較以確定問題。它似乎沒有考慮大小寫(「藍色」<>「藍色」),而「Else」也沒有意義。 – Plutonix 2014-10-09 15:02:19
當我輸入玩家2的回答後運行程序時,循環似乎停滯不前。 – JeffCottonBWFC 2014-10-09 15:13:23