添加稳定性

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 4:
{
Console.CursorVisible = true; // 隐藏光标
Console.WriteLine("请输入字符串");
string? v = Console.ReadLine();
//string转成char[]
@ -80,7 +79,6 @@ public class Music
default:
break;
}
Console.CursorVisible = false; // 隐藏光标
new Thread(PrintCharArray).Start();
if (mode == 1) { return; }
new Thread(Program.KeyEndThread).Start();
@ -92,44 +90,27 @@ public class Music
/// <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)
{
// 随机生成字符出现的初始位置
// 设置光标位置
ConsoleColor Color = ConsoleColor.White;
int v = random.Next(0, 2);
switch (v)
{
case 0:
Color = ConsoleColor.Red;
break;
case 1:
Color = ConsoleColor.Blue;
break;
}
ConsoleColor Color = Program.random.Next(0, 2) == 1 ? ConsoleColor.Red : ConsoleColor.Blue;
// 让字符从初始位置下落
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
{
// 移动到下一行
Program.chars[y, x].Char = a;
Program.chars[y, x].Color = Color;
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(random.Next(60, 120)); // 控制字符下落速度
Thread.Sleep(Program.random.Next(60, 100)); // 控制字符下落速度
}
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;
// 定义一个方法来打印二维字符数组
@ -144,7 +125,7 @@ public class Music
var a = Program.chars.GetLength(0);
var b = Program.chars.GetLength(1);
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)
{
stopwatch.Restart();
@ -172,7 +153,7 @@ public class Music
Console.Write(buffer.ToString());
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 = xiantiaoColor;

View File

@ -35,7 +35,6 @@ public class MusicDebug
public static void DebugDefault()
{
Console.Clear();
Console.CursorVisible = false; // 隐藏光标
var random = new Random();
while (Program.IsWhile)
@ -151,7 +150,7 @@ public class MusicDebug
}
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 ConsoleColor Color = Console.ForegroundColor;
public char Char = Music.ShowChar;
public char Char = Program.ShowChar;
public Point()
{

View File

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