我在VB.NET中创建一个基于文本的小游戏,并希望在屏幕顶部有一个恒定的文本行。 我想要显示任何新文本,例如当您在游戏中进一步显示以显示在状态栏下方而不是从视图中删除它时。
例如
I = Inventory M = Menu E = Exit
Something to do with the game
Something else to do with the game
当你进步时,我希望状态栏保持在屏幕顶部
实施例
I = Inventory M = Menu E = Exit
Something else to do with the game
Something further to do with the game
关于如何实现这一点的任何建议?
由于
答案 0 :(得分:1)
如果仔细查看Console类,可以使用CursorTop
属性来设置要写入的行。顶行将为0,如果您不想更改它,请避免写入该行。这是我所谈论的一个快速而又肮脏的例子
Module Module1
Sub Main()
Dim x As Integer
Console.CursorTop = 0
Console.WriteLine("I = Inventory M = Menu E = Exit")
For x = 1 To 100
WriteDataToConsole("Action #" + x.ToString(), x)
Next
Console.ReadLine()
End Sub
Sub WriteDataToConsole(text As String, pos As Integer)
Dim temp As Integer
If pos > 20 Then
temp = (pos Mod 21) + 1
Console.CursorTop = temp
Else
Console.CursorTop = pos
End If
Console.WriteLine(text)
End Sub
End Module
答案 1 :(得分:0)
将您的菜单放在一个字符串中,将可滚动数据放在另一个字符串中,然后在写入屏幕时将它们连接起来。
示例:
MenuString = "I = Inventory M = Menu E = Exit"
GameString = "Something to do with the game"
GameString = GameString & vblf & "Something else to do with the game"
GameString = GameString & vblf & "Something further to do with the game"
TextBox1.Text = MenuString & vblf & GameString