你们中的任何人都建议我如何在[x]退出时显示时间?我目前正在使用Console.Write()和ch.gotoxy()将光标设置到不同的位置
(顺便说一句,我的光标在293旁边是'Ö')
我有一个迷宫游戏.按Enter键后,您可以输入作弊码,计时器也会暂停.但是在输入代码后,我的计时器恢复,但每秒减少3次.这是按Enter键的条件:
// gt.setTimer() is called at the moment the maze started
// I'm using getch to trap inputs
else if (move == 13) //Reads if Enter is pressed
{
pause = 1; //A Flag saying that the timer must be paused
gt.setTimer(pause); //Calls my setTimer() method
Console.Write("Enter Cheat: ");
cheat = Console.ReadLine();
pause = 0; //A Flag saying that the timer should resume
gt.setTimer(lives, pause); //Calls again the Timer
}
Run Code Online (Sandbox Code Playgroud)
这是我的setTimer()代码:
static System.Timers.Timer t = new System.Timers.Timer();
static int gTime …
Run Code Online (Sandbox Code Playgroud) 我正在制作一个迷宫游戏.如何在Console.Read()之后限制用户输入的字符数?我需要限制它,以便如果用户输入一个非常长的字符串,它将覆盖我的迷宫.如果你打算告诉我之后重写迷宫,我会说不.我不能.相信我,这将需要我另一个漫长的过程.我只想要一个简单的代码来限制输入.
这是显示问题的屏幕截图.你asdasjhasd....
在屏幕上看到了吗?看看它是如何混淆迷宫的?我想限制用户可以输入的字符数,以便它不会到达迷宫.你们能告诉我使用什么代码吗?
解决了
string str = string.Empty;
while (true)
{
char c = Console.ReadKey(true).KeyChar;
if (c == '\r')
break;
if (c == '\b' )
{
if (str != "")
{
str = str.Substring(0, str.Length - 1);
Console.Write("\b \b");
}
}
else if (str.Length < limit)
{
Console.Write(c);
str += c;
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个迷宫游戏,我试图一次创建两个计时器.1号(300秒后退出比赛)
t1.Interval = 30000;
t1.Enabled = true;
t1.Elapsed += new ElapsedEventHandler(hiddenTimer);
public static void hiddenTimer(object source, ElapsedEventArgs e)
{
Console.Clear();
Environment.Exit(1);
}
Run Code Online (Sandbox Code Playgroud)
2号(显示每1秒剩余的时间(如真实计时器))
t2.Interval = 1000;
t2.Enabled = true;
t2.Elapsed += new ElapsedEventHandler(showTimer);
public static void showTimer(object source, ElapsedEventArgs e)
{
Console.Write(timeLeft);
}
Run Code Online (Sandbox Code Playgroud)
我想在全局范围内传递声明timeLeft,但它说"非静态字段,方法或属性需要一个对象引用......"
我该如何正确申报?
我正在制作菜单.我想使用箭头键从我的列表中选择.
char move;
do
{
move = (char)_getch();
if (move == 38)
{
// Move Indicator Up
}
else if (move == 40)
{
// Move Indicator Down
}
}
while (move != 13);
Run Code Online (Sandbox Code Playgroud)
我是否使用上下键的错误ascii值?
解决了
我将(char)_getch()替换为(int)_getch()并将char移动到int然后移动38和40到?? 和80