我的代码有问题。
我正在尝试在菜单屏幕上的选项两侧设置闪烁的图标,以表示用户当前的选择。问题是我希望能够同时闪烁光标并读取用户输入移动光标位置的键。有没有办法可以做到这一点,或者比我目前拥有的设置更简单。
非常感谢任何帮助,因为我仍在学习,谢谢。
Sub Main()
Dim KeyPressed As String
Dim Pos As Integer
Dim MenuSelection As Integer = 1
PreStuff()
DisplayMenu()
Cursor(MenuSelection, False)
Do
KeyPressed = GetKeyPressed()
If KeyPressed = "ConsoleKey.DownArrow" And Pos = 1 Then
MenuSelection = 2
ElseIf KeyPressed = "ConsoleKey.DownArrow" And Pos = 2 Then
MenuSelection = 1
ElseIf KeyPressed = "ConsoleKey.UpArrow" And Pos = 1 Then
MenuSelection = 2
ElseIf KeyPressed = "ConsoleKey.UpArrow" And Pos = 2 Then
MenuSelection = 1
End If
Loop Until KeyPressed = "ConsoleKey.Enter"
Cursor(0, True)
End Sub
Sub PreStuff()
Console.Title = "Populatio - Pre Alpha"
Console.SetWindowSize(80, 25)
Console.CursorVisible = False
End Sub
Function GetKeyPressed()
Dim KeyChoice As String
KeyChoice = Console.ReadKey().ToString
Return KeyChoice
End Function
Sub Cursor(ByVal Op As Integer, ByVal State As Boolean)
Do
Select Case Op
Case 1 And State = False
Console.SetCursorPosition(32, 5)
Console.Write("►")
Console.SetCursorPosition(43, 5)
Console.Write("◄")
State = True
Case 1 And State = True
Console.SetCursorPosition(32, 5)
Console.Write(" ")
Console.SetCursorPosition(43, 5)
Console.Write(" ")
State = False
Case 2 And State = False
Console.SetCursorPosition(34, 7)
Console.Write("►")
Console.SetCursorPosition(41, 7)
Console.Write("◄")
State = True
Case 2 And State = True
Console.SetCursorPosition(34, 7)
Console.Write(" ")
Console.SetCursorPosition(41, 7)
Console.Write(" ")
State = False
End Select
System.Threading.Thread.Sleep(500)
Loop Until Op = 0
Console.SetCursorPosition(32, 5)
Console.Write(" ")
Console.SetCursorPosition(43, 5)
Console.Write(" ")
Console.SetCursorPosition(34, 7)
Console.Write(" ")
Console.SetCursorPosition(41, 7)
Console.Write(" ")
End Sub
Sub DisplayMenu()
Console.WriteLine("╔═════════════════════════════════════════════════════════════════════════════╗")
Console.WriteLine("║ Populatio! By Alx ║")
Console.WriteLine("╠═════════════════════════════════════════════════════════════════════════════╣")
Console.WriteLine("║ ║")
Console.WriteLine("║ New Game ║")
Console.WriteLine("║ ║")
Console.WriteLine("║ Exit ║")
Console.WriteLine("║ ║")
Console.WriteLine("║ ║")
Console.WriteLine("║ ║")
Console.WriteLine("║ ║")
Console.WriteLine("║ ║")
Console.WriteLine("║ ║")
Console.WriteLine("║ ║")
Console.WriteLine("║ ║")
Console.WriteLine("║ ║")
Console.WriteLine("║ ║")
Console.WriteLine("║ ║")
Console.WriteLine("║ ║")
Console.WriteLine("║ ║")
Console.WriteLine("║ ║")
Console.WriteLine("║ ║")
Console.WriteLine("║ ║")
Console.WriteLine("║ ║")
Console.Write("╚═════════════════════════════════════════════════════════════════════════════╝")
End Sub