下面是我那个程序的打字控制段的代码,你参考着,那些标识符用英文单词,很容易知道是什么意思的:
程序代码:
Console.CursorVisible = false;
Boolean exit = false;
Int32 row = 0;
Int32 col = 0;
while (!exit)
{
if (Console.KeyAvailable)
{
ConsoleKeyInfo keypress = Console.ReadKey(true);
switch (keypress.Key)
{
case ConsoleKey.Escape:
exit = true;
break;
case ConsoleKey.F2:
row = 0;
col = 0;
Console.SetCursorPosition(text_scope.Left, text_scope.Top);
Console.CursorVisible = true;
message.Start();
break;
case ConsoleKey.F3:
message.Stop();
break;
case ConsoleKey.F4:
message.Stop();
message.Clear();
Show_Text();
Console.CursorVisible = false;
break;
case ConsoleKey.Enter:
if ((row < Text.Count) && (row < text_scope.Height - 1))
{
++row;
col = 0;
++Console.CursorTop;
Console.CursorLeft = text_scope.Left;
}
break;
default:
if (message.Processing && !Char.IsControl(keypress.KeyChar))
{
++message.Total_Number;
if (col < Text[row].Length)
{
if (keypress.KeyChar == Text[row][col])
{
++message.Correct_Number;
Console.ForegroundColor = ConsoleColor.Green;
}
else
{
--message.Correct_Number;
if (message.Correct_Number < 0)
{
message.Correct_Number = 0;
}
Console.ForegroundColor = ConsoleColor.Red;
}
Console.Write(Text[row][col++]);
if (col >= Text[row].Length)
{
if ((row < Text.Count) && (row < text_scope.Height - 1))
{
++row;
col = 0;
++Console.CursorTop;
Console.CursorLeft = text_scope.Left;
}
}
}
}
break;
}
}
}