I just started learning programming couple months ago and decided to do a console snake game. Everything works great expect for one thing.
If my snake is going upwards and I press down arrow and keep it pressed, my snake just stops and stays stopped even awhile after I stop pressing the button.
Same thing happens if my snake is going right and I press right arrow too long, I lose control for some time(but snake does not stop). It happens for every way(left,right,up,down).
I tried to compare the cki to another ConsoleKeyInfo with slight delay between them, but it doesn't matter. If I keep the key pressed, my program just stays that spot and updates for a key. (atleast I think thats the problem)
Is this a "feature" of the Console.ReadKey or is there some way arount this?
Keep in mind, that I just started so I don't know about the advanced stuff, yet.
Everything works flawless as long as I don't keep the key pressed more than 1 sec.
public void LiikutaMato() //movesnake
{
if (Console.KeyAvailable)
{
ConsoleKeyInfo cki;
cki = Console.ReadKey(true); // <-- I believe this is where it gets stuck
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…