【发布时间】:2019-06-09 19:07:01
【问题描述】:
我正在尝试制作的程序是基于文本的游戏。
玩家输入命令,输入显示在列表框中,以及不同的“房间”
有一个设置的生成点,它是一个布尔语句,在输入命令之前为真。
例如,如果输入“n”,则第二个布尔值“spawnpointN”为真,原始生成点为假。
在循环迭代一次之前,我希望它等待用户输入。
如何让循环暂停?
Public Class frmMain
Const north As String = "n"
Const east As String = "e"
Const west As String = "w"
Const south As String = "s"
Dim input As String
Dim finished As Boolean = False
Dim spawnpoint As Boolean = True
Dim spawnpointN As Boolean = False
Dim spawnpointE As Boolean = False
Dim spawnpointW As Boolean = False
Dim spawnpointS As Boolean = False
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AcceptButton = btnEnter
Do
If spawnpoint = True Then
Me.lstDisplay.Items.Add("You awake in a room of darkness.")
If Me.input = north Then
spawnpointN = True
spawnpoint = False
End If
If Me.input = east Then
spawnpointE = True
spawnpoint = False
End If
If Me.input = south Then
spawnpointS = True
spawnpoint = False
End If
If Me.input = west Then
spawnpointW = True
spawnpoint = False
End If
End If
If spawnpointN = True Then
lstDisplay.Items.Add("Test")
If Me.input = south Then
Me.spawnpoint = True
Me.spawnpointN = False
End If
End If
If input = "end" Then
finished = True
End If
Loop Until finished = True
If finished = True Then
lstDisplay.Items.Add("You have finished my game!")
End If
End Sub
Private Sub btnEnter_Click(sender As Object, e As EventArgs) Handles btnEnter.Click
Dim input As String = Me.txtInput.Text
Me.lstDisplay.Items.Add(input)
Me.txtInput.Clear()
lstDisplay.TopIndex = lstDisplay.Items.Count - 1
End Sub
End Class
现在,我的代码甚至没有运行。
【问题讨论】:
-
请始终提供错误信息。否则将很难或不可能帮助您。
-
当我按下运行时,什么也没有发生。它只是停留在这个imgur.com/yYht8GQ
-
卡在循环中; GUI 在那里时无法响应。您正在尝试将控制台样式的线性代码塞进非线性的 winforms 应用程序中;一个方形钉子插入一个圆孔。相反,将您的逻辑放入一个不同的子程序中,没有循环,从按钮处理程序调用。
标签: vb.net