制作基于文本的游戏。我有一个命令提示符,它由richtextbox 作为输出框和输入文本框的文本框组成。我需要做一些命令,比如“cls”“dir”“config”。我的列表中有更多命令。我只是坚持如何做到这一点以及如何解决问题。这是我的代码,我用选择案例方法累了一些,但它太原始了。
Private Sub Output(s As String)
If s <> "" Then
nCounter = nCounter + 1
sCounter = Convert.ToString(nCounter)
consoleoutputbox.AppendText(vbCrLf & sCounter & " " & s)
End If
End Sub
Private Sub consoleinputbox_KeyDown(sender As Object, e As KeyEventArgs) Handles consoleinputbox.KeyDown
Dim Command As String = consoleinputbox.Text
If e.KeyCode = Keys.Enter Then
If Command <> "" Then
Select Case Command
Case "cls"
consoleoutputbox.Clear()
consoleinputbox.Clear()
consoleinputbox.Focus()
nCounter = 0
Case "help"
Output("Welcome to help section. Avaliable commands:")
Output("help, cls")
Case Else
Output(Command)
consoleinputbox.Clear()
consoleinputbox.Focus()
End Select
End If
End If
End Sub