添加稳定性

This commit is contained in:
muqing 2024-08-30 14:48:22 +08:00
parent 6d21641a41
commit ce8d466277
4 changed files with 15 additions and 32 deletions

View File

@ -56,7 +56,6 @@ public class Music
case 3: case 3:
case 4: case 4:
{ {
Console.CursorVisible = true; // 隐藏光标
Console.WriteLine("请输入字符串"); Console.WriteLine("请输入字符串");
string? v = Console.ReadLine(); string? v = Console.ReadLine();
//string转成char[] //string转成char[]
@ -80,7 +79,6 @@ public class Music
default: default:
break; break;
} }
Console.CursorVisible = false; // 隐藏光标
new Thread(PrintCharArray).Start(); new Thread(PrintCharArray).Start();
if (mode == 1) { return; } if (mode == 1) { return; }
new Thread(Program.KeyEndThread).Start(); new Thread(Program.KeyEndThread).Start();
@ -92,44 +90,27 @@ public class Music
/// <summary> /// <summary>
/// 随机字符下落 /// 随机字符下落
/// </summary> /// </summary>
private static readonly Random random = new();
//常量
public const char ShowChar = ' ';
// public static readonly char[,] chars = new char[10, 30];
public static void Down(char a) public static void Down(char a)
{ {
// 随机生成字符出现的初始位置 // 随机生成字符出现的初始位置
// 设置光标位置 // 设置光标位置
ConsoleColor Color = ConsoleColor.White; ConsoleColor Color = Program.random.Next(0, 2) == 1 ? ConsoleColor.Red : ConsoleColor.Blue;
int v = random.Next(0, 2);
switch (v)
{
case 0:
Color = ConsoleColor.Red;
break;
case 1:
Color = ConsoleColor.Blue;
break;
}
// 让字符从初始位置下落 // 让字符从初始位置下落
int x = random.Next(0, Program.chars.GetLength(1)); int x = Program.random.Next(0, Program.chars.GetLength(1));
for (int y = 0; y < Program.chars.GetLength(0); y++) // 注意这里使用consoleHeight for (int y = 0; y < Program.chars.GetLength(0); y++) // 注意这里使用consoleHeight
{ {
// 移动到下一行 // 移动到下一行
Program.chars[y, x].Char = a; Program.chars[y, x].Char = a;
Program.chars[y, x].Color = Color;
if (y > 0) if (y > 0)
{ {
Program.chars[y - 1, x].Char = ShowChar; Program.chars[y - 1, x].Char = Program.ShowChar;
} }
Program.chars[y, x].Color = Color; Thread.Sleep(Program.random.Next(60, 100)); // 控制字符下落速度
Thread.Sleep(random.Next(60, 120)); // 控制字符下落速度
} }
Thread.Sleep(50); Thread.Sleep(50);
Program.chars[Program.chars.GetLength(0) - 1, x].Char = ShowChar; Program.chars[Program.chars.GetLength(0) - 1, x].Char = Program.ShowChar;
} }
private static long time = 0; private static long time = 0;
// 定义一个方法来打印二维字符数组 // 定义一个方法来打印二维字符数组
@ -144,7 +125,7 @@ public class Music
var a = Program.chars.GetLength(0); var a = Program.chars.GetLength(0);
var b = Program.chars.GetLength(1); var b = Program.chars.GetLength(1);
var buffer = new StringBuilder(); var buffer = new StringBuilder();
ConsoleColor xiantiaoColor = random.Next(0, 2) == 0 ? ConsoleColor.Red : ConsoleColor.Blue;//线条的颜色 ConsoleColor xiantiaoColor = Program.random.Next(0, 2) == 0 ? ConsoleColor.Red : ConsoleColor.Blue;//线条的颜色
while (Program.IsWhile) while (Program.IsWhile)
{ {
stopwatch.Restart(); stopwatch.Restart();
@ -172,7 +153,7 @@ public class Music
Console.Write(buffer.ToString()); Console.Write(buffer.ToString());
if (time % 1000 == 0) if (time % 1000 == 0)
{ {
xiantiaoColor = random.Next(0, 2) == 0 ? ConsoleColor.Red : ConsoleColor.Blue; xiantiaoColor = Program.random.Next(0, 2) == 0 ? ConsoleColor.Red : ConsoleColor.Blue;
} }
// Console.ForegroundColor = (ConsoleColor)random.Next(0, 16); // Console.ForegroundColor = (ConsoleColor)random.Next(0, 16);
Console.ForegroundColor = xiantiaoColor; Console.ForegroundColor = xiantiaoColor;

View File

@ -35,7 +35,6 @@ public class MusicDebug
public static void DebugDefault() public static void DebugDefault()
{ {
Console.Clear(); Console.Clear();
Console.CursorVisible = false; // 隐藏光标
var random = new Random(); var random = new Random();
while (Program.IsWhile) while (Program.IsWhile)
@ -151,7 +150,7 @@ public class MusicDebug
} }
else else
{ {
Program.chars[9, x].Char = Music.ShowChar; Program.chars[9, x].Char = Program.ShowChar;
} }
} }
} }

View File

@ -4,7 +4,7 @@ namespace Debug.ModelingMusic;
public partial class Point public partial class Point
{ {
public ConsoleColor Color = Console.ForegroundColor; public ConsoleColor Color = Console.ForegroundColor;
public char Char = Music.ShowChar; public char Char = Program.ShowChar;
public Point() public Point()
{ {

View File

@ -38,6 +38,10 @@ public class Program
// Console.SetBufferSize(100, 100); // Console.SetBufferSize(100, 100);
//} //}
// Get the handle of the console window // Get the handle of the console window
Console.Clear();
Console.CursorVisible = false;
_ = new Program(); _ = new Program();
} }
@ -50,8 +54,7 @@ public class Program
public Program() public Program()
{ {
Console.Clear(); // MinLong.Main.ResetChars();
Console.CursorVisible = false;
// _ = new MinLong.Main(); // _ = new MinLong.Main();
// return; // return;
string[] str = ["退出", "抽卡", "铁锈位置搜索引擎", "音乐调试", "小龙快跑"]; string[] str = ["退出", "抽卡", "铁锈位置搜索引擎", "音乐调试", "小龙快跑"];