优化按键处理逻辑,增加按键得分功能并清理代码

This commit is contained in:
muqing 2025-01-12 14:23:44 +08:00
parent 9b3363ec35
commit ec850cd1d6
2 changed files with 24 additions and 4 deletions

View File

@ -221,7 +221,7 @@ public class MusicFrom
{ {
// 创建一个字典来跟踪每个按键的前一次状态 // 创建一个字典来跟踪每个按键的前一次状态
var keyStates = new System.Collections.Generic.Dictionary<int, bool> var keyStates = new Dictionary<int, bool>
{ {
{ VK_D, false }, { VK_D, false },
{ VK_F, false }, { VK_F, false },
@ -306,10 +306,18 @@ public class MusicFrom
case VK_F: case VK_F:
isDown[1] = true; isDown[1] = true;
// 处理F键被按下的逻辑 // 处理F键被按下的逻辑
if (Program.chars[8, 10].Char == 'F' || Program.chars[9, 10].Char == 'F')
{
score += 100;
}
break; break;
case VK_G: case VK_G:
isDown[2] = true; isDown[2] = true;
// 处理G键被按下的逻辑 // 处理G键被按下的逻辑
if (Program.chars[8, 17].Char == 'G' || Program.chars[9, 17].Char == 'G')
{
score += 100;
}
break; break;
case VK_SPACE: case VK_SPACE:
isDown[3] = true; isDown[3] = true;
@ -318,14 +326,26 @@ public class MusicFrom
case VK_J: case VK_J:
isDown[4] = true; isDown[4] = true;
// 处理J键被按下的逻辑 // 处理J键被按下的逻辑
if (Program.chars[8, 31].Char == 'J' || Program.chars[9, 31].Char == 'J')
{
score += 100;
}
break; break;
case VK_K: case VK_K:
isDown[5] = true; isDown[5] = true;
// 处理K键被按下的逻辑 // 处理K键被按下的逻辑
if (Program.chars[8, 38].Char == 'K' || Program.chars[9, 38].Char == 'K')
{
score += 100;
}
break; break;
case VK_L: case VK_L:
isDown[6] = true; isDown[6] = true;
// 处理L键被按下的逻辑 // 处理L键被按下的逻辑
if (Program.chars[8, 45].Char == 'L' || Program.chars[9, 45].Char == 'L')
{
score += 100;
}
break; break;
default: default:
break; break;

View File

@ -1,8 +1,6 @@
 using System.Text;
using System.Text;
using Debug.ModelingMusic; using Debug.ModelingMusic;
namespace Debug; namespace Debug;
/// <summary> /// <summary>
/// 主程序入口 参考 https://blog.csdn.net/oscar999/article/details/141370223 /// 主程序入口 参考 https://blog.csdn.net/oscar999/article/details/141370223
/// 在VS Code的终端中使用dotnet build命令来编译项目。这将在项目目录中生成一个bin文件夹其中包含编译后的程序集。 /// 在VS Code的终端中使用dotnet build命令来编译项目。这将在项目目录中生成一个bin文件夹其中包含编译后的程序集。
@ -10,6 +8,7 @@ namespace Debug;
/// </summary> /// </summary>
public class Program public class Program
{ {
public static void printf(object a) public static void printf(object a)
{ {
Console.Write(a); Console.Write(a);
@ -23,6 +22,7 @@ public class Program
Console.Title = "Tools";//设置窗口标题 Console.Title = "Tools";//设置窗口标题
// 设置控制台输出编码,以支持复杂字符 // 设置控制台输出编码,以支持复杂字符
Console.OutputEncoding = Encoding.UTF8; Console.OutputEncoding = Encoding.UTF8;
// 切换到英语输入法
Console.Clear(); Console.Clear();
Console.CursorVisible = false; Console.CursorVisible = false;
new MusicFrom(); new MusicFrom();