diff --git a/MinLong/KongLong.cs b/MinLong/Main.cs similarity index 84% rename from MinLong/KongLong.cs rename to MinLong/Main.cs index 465ab5e..479f72c 100644 --- a/MinLong/KongLong.cs +++ b/MinLong/Main.cs @@ -1,24 +1,38 @@ using System.Diagnostics; using System.Text; - namespace Debug.MinLong; #pragma warning disable CA1822 // 将成员标记为 static #pragma warning disable IDE0051 // 删除未使用的私有成员 #pragma warning disable IDE1006 // 命名样式 -public class KongLong +public class Main { - public KongLong() + + public Main() { Console.WriteLine("MinLong"); - Console.CursorVisible = false; - ResetChars();//初始化 + ResetChars();//初始化 渲染界面 ResetLong();//初始化小龙 new Thread(PrintCharArray).Start(); + + var timer = new System.Timers.Timer(); + // 设置计时器事件处理方法 + timer.Elapsed += (sender, e) => + { + new Thread(() => Zhangaiwu.newshitou(xiaoLong)).Start(); + int interval = random.Next(3000, 6000); // 1000ms 到 5000ms + timer.Interval = interval; + }; + // 启动计时器 + timer.Start(); + KeyThread();//监听键盘 } private long time; + //随机数 + Random random = new(); + public void PrintCharArray() { var stopwatch = new Stopwatch(); @@ -55,11 +69,7 @@ public class KongLong for (i = 0; i < b; i++) { - buffer.Append('Ξ'); - } - if (time % 1000 == 0) - { - new Thread(Zhangaiwu.newshitou).Start(); + buffer.Append('-'); } Console.Write(buffer); Console.ResetColor(); @@ -73,22 +83,25 @@ public class KongLong double fps = frameCount / (totalTime / 1000.0); Console.SetCursorPosition(0, 0);// 设定光标位置到第二行 - Console.WriteLine($" {fps:0} FPS"); + Console.WriteLine($" {fps:0} FPS 得分{xiaoLong.score}"); // 保持每秒约16.67ms(即大约60 FPS)的间隔 // Thread.Sleep(Math.Max(0, 60 - (int)elapsedMilliseconds)); //死方法 不知道为什么 控制台限制60 帧这样闪烁不会太严重 Thread.Sleep(100); } + Console.WriteLine("任务失败!!!"); } public class XiaoLong { - public char Char = '口';//小龙的形状 + public char Char = 'k';//小龙的形状 public ConsoleColor Color = ConsoleColor.Red;//小龙的颜色 public int x;//小龙X坐标 public int y;//小龙Y坐标 public bool istiao = false;//是否跳 + //分数 + public int score = 0; } public XiaoLong xiaoLong = new(); @@ -129,7 +142,7 @@ public class KongLong { //空格 case ConsoleKey.Spacebar: - if (!xiaoLong.istiao) { new Thread(tiaoyue).Start(); } + if (!xiaoLong.istiao) { new Thread(() => tiaoyue(xiaoLong)).Start(); } break; } } @@ -140,7 +153,7 @@ public class KongLong /// /// 跳跃 /// - private void tiaoyue() + public static void tiaoyue(XiaoLong xiaoLong) { if (xiaoLong.istiao) return; xiaoLong.istiao = true; diff --git a/MinLong/Zhangaiwu.cs b/MinLong/Zhangaiwu.cs index 272c988..550c952 100644 --- a/MinLong/Zhangaiwu.cs +++ b/MinLong/Zhangaiwu.cs @@ -3,7 +3,8 @@ namespace Debug.MinLong; #pragma warning disable CS8981 // 该类型名称仅包含小写 ascii 字符。此类名称可能会成为该语言的保留值。 public class Zhangaiwu { - public static void newshitou() + private static int SleepTime = 100; + public static void newshitou(Main.XiaoLong xiaoLong) { var y = Program.chars.GetLength(0); var x = Program.chars.GetLength(1); @@ -12,12 +13,34 @@ public class Zhangaiwu x = x - 1, y = y - 1 }; + bool isjiafeng = false;//是否加分 + bool ceshi = false; for (int i = 1; i < x; i++) { - Program.chars[shitou.y, shitou.x].Char = 'O'; - Thread.Sleep(100); + //测试 + if (!ceshi && shitou.x == xiaoLong.x + 1) + { + ceshi = true; + new Thread(() => Main.tiaoyue(xiaoLong)).Start(); + // Main.tiaoyue(xiaoLong); + } + if (shitou.x != xiaoLong.x || shitou.y != xiaoLong.y) + { + Program.chars[shitou.y, shitou.x].Char = '0'; + if (shitou.x < xiaoLong.x && !isjiafeng) + { + isjiafeng = true; + xiaoLong.score++; + SleepTime--; + } + } + else + { + Program.IsWhile = false; + } + Thread.Sleep(SleepTime); Program.chars[shitou.y, shitou.x].Char = Program.ShowChar; - shitou.x--; + --shitou.x; } } diff --git a/Mod.cs b/Mod.cs index 954e5e3..451c484 100644 --- a/Mod.cs +++ b/Mod.cs @@ -2,6 +2,7 @@ using Debug; using Microsoft.VisualBasic; using Microsoft.Win32; +using System.Runtime.InteropServices; /// /// 模组搜索引擎操作 /// @@ -31,39 +32,38 @@ public class Mod public Mod() { Console.Clear(); - var SearchMode = 1; - do - { - Program.printfLine("输入 1.默认搜索 2.只执行steam搜索 3.只执行全盘搜索 0.返回主页"); - var v = Console.ReadLine(); - if (int.TryParse(v, out int i)) - { - SearchMode = i; - if (SearchMode == 0) - { - Console.Clear(); - break; - } - // StartTime = DateTime.Now; - if (SearchMode == 1 || SearchMode == 2) - { - steam();//先看看steam中有没有安装铁锈战争 - //steam中没有安装铁锈战争扫全盘 - } - if (SearchMode == 1 || SearchMode == 3) - { - if (FileDir == string.Empty) - { - init(); - } - } - if (!string.IsNullOrEmpty(FileDir)) - { - Program.printfLine("找到了:" + FileDir); - } - } - } while (true); + ModeSwitch.New("搜索模式", ["返回主页", "默认", "steam", "全盘"], MODE); + //Action action = MODE; + } + public void MODE(int a) + { + Console.Clear(); + if (a == 0) + { + _ = new Program(); + return; + } + // StartTime = DateTime.Now; + if (a == 1 || a == 2) + { + steam();//先看看steam中有没有安装铁锈战争 + //steam中没有安装铁锈战争扫全盘 + } + if ((a == 1 || a == 3) && FileDir == string.Empty) + { + init(); + } + Console.Clear(); + if (!string.IsNullOrEmpty(FileDir)) + { + ModeSwitch.New("找到了:" + FileDir, ["返回主页", "默认", "steam", "全盘"], MODE); + } + else + { + ModeSwitch.New("未找到", ["返回主页", "默认", "steam", "全盘"], MODE); + } + //FileDir=string.Empty; } private void steam() { @@ -74,7 +74,6 @@ public class Mod // Program.printfLine("找到了:" + v); if (Directory.Exists(v)) { - FileDir = v; // EndTime(); } @@ -163,6 +162,12 @@ public class Mod private static string GetSteamInstallPath() { + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return string.Empty; + // Windows 相关逻辑 + } + var installPath = GetInstallPathFromKey(@"Software\Valve\Steam"); if (string.IsNullOrEmpty(installPath)) @@ -174,11 +179,11 @@ public class Mod string GetInstallPathFromKey(string subKey) { - using (RegistryKey key = Registry.CurrentUser.OpenSubKey(subKey)) + using (var key = Registry.CurrentUser.OpenSubKey(subKey)) { if (key != null) { - object path = key.GetValue("InstallPath"); + var path = key.GetValue("InstallPath"); if (path != null) { return (string)path; @@ -186,7 +191,7 @@ public class Mod } } - using (RegistryKey key = Registry.LocalMachine.OpenSubKey(subKey)) + using (var key = Registry.LocalMachine.OpenSubKey(subKey)) { if (key != null) { diff --git a/ModelingMusic/Music.cs b/ModelingMusic/Music.cs index 223663c..8ca0efa 100644 --- a/ModelingMusic/Music.cs +++ b/ModelingMusic/Music.cs @@ -14,7 +14,12 @@ public class Music string[] str = ["退出", "启动", "测试下落", "指定字符串", "随机指定字符串下落", "扬声器节奏"]; ModeSwitch.New("模拟音游 1.0 by ", str, (a) => { + Console.Clear(); mode = a; + if (a == 0) + { + return; + } Init().GetAwaiter().GetResult(); // 启动 }); } diff --git a/Program.cs b/Program.cs index 7d7134a..c5670ee 100644 --- a/Program.cs +++ b/Program.cs @@ -22,16 +22,22 @@ public class Program Console.WriteLine(a); } - [DllImport("kernel32.dll")] - private static extern bool SetConsoleTitle(string title); //开始计时 public static void Main(string[] args) { - // 设置控制台标题为一个独特的字符串 - SetConsoleTitle("Tools"); + Console.Title = "Tools";//设置窗口标题 // 设置控制台输出编码,以支持复杂字符 Console.OutputEncoding = Encoding.UTF8; + //// 更改控制台窗口的大小 + //Console.SetWindowSize(100, 100); + + //// 设置控制台屏幕缓冲区的大小以适应窗口大小 + //if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + //{ + // Console.SetBufferSize(100, 100); + //} + // Get the handle of the console window _ = new Program(); } @@ -39,17 +45,14 @@ public class Program public static readonly Point[,] chars = new Point[10, 50]; public static bool IsWhile = true; - public static char ShowChar = ' '; + public const char ShowChar = ' '; public Program() { - // new Thread(MusicDebug.MusicRhythm).Start(); - // return; - - // new Debug.MinLong.KongLong(); - // return; Console.Clear(); Console.CursorVisible = false; + _ = new MinLong.Main(); + return; string[] str = ["退出", "抽卡", "铁锈位置搜索引擎", "音乐调试", "小龙快跑"]; var modeSwitch = new ModeSwitch("请选择你要执行的操作:", str, (a) => { @@ -67,6 +70,9 @@ public class Program case 3: _ = new Music(); break; + case 4: + _ = new MinLong.Main(); + break; default: printfLine("还没有这个功能"); break;