优化按键处理逻辑,使用switch语句替代随机按键选择,并调整DownKey方法以支持不同列的按键显示

This commit is contained in:
muqing 2025-01-07 19:51:33 +08:00
parent b75ca2bc5a
commit 9b3363ec35

View File

@ -32,7 +32,32 @@ public class MusicFrom
{
// 随机数
int random = Program.random.Next(0, 7);
DownKey(jianpan[random]);
switch (random)
{
case 0:
DownKey('D', 3);
break;
case 1:
DownKey('F', 10);
break;
case 2:
DownKey('G', 17);
break;
case 3:
DownKey('M', 24);
break;
case 4:
DownKey('J', 31);
break;
case 5:
DownKey('K', 38);
break;
case 6:
DownKey('L', 45);
break;
default:
break;
}
Thread.Sleep(1000);
}
}
@ -41,16 +66,16 @@ public class MusicFrom
public char key;
public bool isDown;//是否被按下
}
public void DownKey(char key)
public void DownKey(char key, int x)
{
new Thread(() =>
{
var zIFUKEY = new ZIFUKEY() { key = key, isDown = false };
for (int i = 0; i < MaxY; i++)
{
Program.chars[i, 3].Char = zIFUKEY.key;
Thread.Sleep(500);
Program.chars[i, 3].Char = ' ';
Program.chars[i, x].Char = zIFUKEY.key;
Thread.Sleep(260);
Program.chars[i, x].Char = ' ';
if (zIFUKEY.isDown)
{
break;