【发布时间】:2021-06-05 16:44:11
【问题描述】:
我正在开发一款文字冒险游戏。该程序的目标是显示三个选项和一个文本框。用户可以通过在文本框中输入相应的数字来选择其中一个选项,然后该文本框应该将用户导航到下一个区域,向用户显示另外 3 个选项。
我目前遇到的问题是在区域游戏区域中导航。
Sub gameOver(ByVal DeathMessage)
lblTitle.Text = "Game Over!"
lblMain.Text = DeathMessage
End Sub
Sub pgMain()
lblMain.Text = $"Enter 1 to start the game{vbCrLf}Enter 2 to quit the game"
If aryInput(0) = "1" Then
pg1()
ElseIf aryInput(0) = "2" Then
Me.Close()
End If
End Sub
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
aryInput(0) = tbxInput.Text
End Sub
Sub pg1() ' User picks a starting option
lblTitle.Text = "You spot a secret magical lair do you"
lblMain.Text = $"1. Enter the lair through the front door{vbCrLf}2. Enter the lair through the back door{vbCrLf}3. Wait untill midnight to enter the lair."
If aryInput(0) = "1" Then
MsgBox("Front door") 'pg2()
ElseIf aryInput(0) = "2" Then
MsgBox("backdoor")
pg3()
ElseIf aryInput(0) = "3" Then
gameOver("You were mauled by wolves")
End If
End Sub
'Sub pg2() ' User entered through the front door.
' lblMain.Text = $"1. Go to the chest{vbCrLf}2. Go to the bookshelf{vbCr}3. Go to the cauldron"
' If tbxInput.Text = "1" Then
' pg5() ' They went to the chest
' ElseIf tbxInput.Text = "2" Then
' pg6() ' User went to the bookshelf
' ElseIf tbxInput.Text = "3" Then
' pg7() ' User went to the cauldron
' End If
'End Sub
Sub pg3()
tbxInput.Text = Nothing
lblTitle.Text = "You were splashed with a poison spell do you"
lblMain.Text = $"1. Cut off the infected part{vbCrLf}2. Drink a bucket of milk{vbCrLf}3. Inject yourself with some sort of medical syringe"
If tbxInput.Text = "1" Then
MsgBox("Infected Part") 'pg8()
ElseIf tbxInput.Text = "2" Then
MsgBox("Milk") 'pg9()
ElseIf tbxInput.Text = "3" Then
gameOver("You injected yourself with viper venom.")
End If
End Sub
您可能会说我在获取文本框的内容以决定用户下一步将去哪里时遇到问题。我尝试过使用输入框,是的,它可以工作,但是它们有字符限制,我更愿意找到一种方法来使用文本框来做到这一点。我还在考虑使用按键而不是单击按钮的方法。对于初学者的问题,我很抱歉,我仍在学习有关 Visual Basic 的方法。提前谢谢!
【问题讨论】:
-
aryInpur 在哪里声明?
-
如果您使用单选按钮,用户输入会更可靠。只需更改单选按钮上的文本即可。
-
您没有让用户有机会在文本框中输入内容。
-
你被一个 WinForms 应用程序访问,就好像它是一个控制台应用程序一样。 WinForms 是事件驱动的。触发这些潜艇的事件在哪里?
-
为什么事件使用数组?看来您只使用了第一个元素。