diff --git a/.gitignore b/.gitignore index 88dd87a..497ea74 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,7 @@ *.user *.userosscache *.sln.docstates -.zip +*.zip # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs @@ -361,5 +361,4 @@ MigrationBackup/ .ionide/ # Fody - auto-generated XML schema -FodyWeavers.xsd -Mi.zip +FodyWeavers.xsd \ No newline at end of file diff --git a/ModelingMusic/Music.cs b/ModelingMusic/Music.cs index 2e0d51d..39d2b65 100644 --- a/ModelingMusic/Music.cs +++ b/ModelingMusic/Music.cs @@ -11,25 +11,53 @@ public class Music public Music() { Console.Clear(); + Program.printfLine("模拟音游 1.0 by "); + string[] str = ["0 退出", "1.启动", "2.测试下落", "3.指定字符串", "4.随机指定字符串下落", "5.扬声器节奏"]; + // Program.printfLine("1.启动 2.测试下落 3.指定字符串 4.随机指定字符串下落 5.扬声器节奏 0.退出"); + foreach (var aa in str) + { + Program.printfLine(aa); + } + Console.SetCursorPosition(0, mode + 1); do { - Program.printfLine("模拟音游 1.0 by "); - Program.printfLine("1.启动 2.测试下落 3.指定字符串 4.随机指定字符串下落 5.扬声器节奏 0.退出"); - var v = Console.ReadLine(); - if (int.TryParse(v, out int i)) + var v = Console.ReadKey(true); + // 检查是否为数字 + if (v.Key >= ConsoleKey.D0 && v.Key <= ConsoleKey.D9) { - mode = i; - if (i == 0) - { - //退出程序 - Environment.Exit(0); - return; - } - Init().GetAwaiter().GetResult(); // 启动 - return; + int v1 = int.Parse(v.KeyChar.ToString()); + if (v1 >= 0 && v1 < str.Length) + mode = v1; } - } while (true); + else + { + switch (v.Key) + { + case ConsoleKey.UpArrow: + mode = mode == 0 ? mode : mode - 1; + break; + case ConsoleKey.DownArrow: + mode = mode == str.Length - 1 ? mode : mode + 1; + break; + case ConsoleKey.Enter: + if (mode == 0) + { + //退出程序 + Environment.Exit(0); + return; + } + goto Start; + break; + } + } + // Console.WriteLine("无效输入,请确保您输入的是一个数字(0-9)。"); + Console.SetCursorPosition(0, mode + 1); + } while (true); + Start: + { + Init().GetAwaiter().GetResult(); // 启动 + } } private async Task Init() @@ -91,7 +119,7 @@ public class Music Console.CursorVisible = false; // 隐藏光标 new Thread(PrintCharArray).Start(); if (mode == 1) { return; } - Program.KeyEndThread(); + new Thread(Program.KeyEndThread).Start(); // 等待用户按下任意键后退出 } diff --git a/Program.cs b/Program.cs index ae99f11..e8557b3 100644 --- a/Program.cs +++ b/Program.cs @@ -51,56 +51,63 @@ public class Program Console.Clear(); int y = 0; printfLine("请选择你要执行的操作:"); - // printfLine(" 0.退出 "); - // printfLine(" 1.抽拉 "); - // printfLine(" 2.铁锈位置搜索引擎 "); - // printfLine(" 3.音乐调试 "); - // printfLine(" 4.小龙快跑 "); string[] str = ["0 退出", "1 抽卡", "2 铁锈位置搜索引擎", "3 音乐调试", "4 小龙快跑"]; for (int i = 0; i < str.Length; i++) { printfLine(str[i]); } - Console.SetCursorPosition(0, y); + Console.SetCursorPosition(0, y + 1); do { - Console.WriteLine(); var v = Console.ReadKey(true); - switch (v.Key) + if (v.Key >= ConsoleKey.D0 && v.Key <= ConsoleKey.D9) { - case ConsoleKey.UpArrow: - //设置光标位置 - y = y == 0 ? y : y - 1; - break; - case ConsoleKey.DownArrow: - y = y + 1 == str.Length ? y : y + 1; - break; - case ConsoleKey.Enter: - switch (y) - { - case 0: - Environment.Exit(0); - break; - case 1: - _ = new ChouKa(); - break; - case 2: - _ = new Mod(); - break; - case 3: - _ = new Music(); - return; - default: - printfLine("还没有这个功能"); - break; - } - break; + int v1 = int.Parse(v.KeyChar.ToString()); + if (v1 >= 0 && v1 < str.Length) + { + y = v1; + } } + else + switch (v.Key) + { + case ConsoleKey.UpArrow: + //设置光标位置 + y = y == 0 ? y : y - 1; + break; + case ConsoleKey.DownArrow: + y = y + 1 == str.Length ? y : y + 1; + break; + case ConsoleKey.Enter: + goto Start; + } // Console.WriteLine(v.Key); - Console.SetCursorPosition(0, y); + Console.SetCursorPosition(0, y + 1); // { } while (true); + // Console.WriteLine("请选择你要执行的操作:"); + Start: + { + switch (y) + { + case 0: + Environment.Exit(0); + break; + case 1: + _ = new ChouKa(); + break; + case 2: + _ = new Mod(); + break; + case 3: + _ = new Music(); + return; + default: + printfLine("还没有这个功能"); + break; + } + } } public static void KeyEndThread()