I′m currently working on a roguelike in c#.
The world, player etc. are rendered inside of a console. But when there are too many changes in the console, it lags.
To bypass this, I′m trying to let programm wait for the player to un-press the key the player is pressing.
Anyone has an idea on how to make this?
Bad, that there isn′t something like Console.ReadKeyUp()
.
while(Console.KeyAvailable){
}
seems not to work...
Here′s a bit of code:
public void move(){
if(!MainClass.loading){
switch(Console.ReadKey().Key){
case ConsoleKey.NumPad8:
//walk up
break;
case ConsoleKey.NumPad4:
//walk left
break;
case ConsoleKey.NumPad6:
//walk right
break;
case ConsoleKey.NumPad2:
//walk down
break;
case ConsoleKey.NumPad7:
//walk left up
break;
case ConsoleKey.NumPad9:
//walk right up
break;
case ConsoleKey.NumPad1:
//walk left down
break;
case ConsoleKey.NumPad3:
//walk right down
break;
case ConsoleKey.NumPad5:
//eat
break;
}
}
}
And here's what it looks like:
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…