Reputation: 19
Recently I am trying to make basic games in Console-Application, like to move the cursor with the arrows (maybe as a very basic start of snake and games that you move something all over the Console screen), and I wanted to ask if it's possible to make that the cursor won't stop to move, and just change the direction when I press on some arrow? Is it something with events?
Thanks.
Upvotes: 0
Views: 569
Reputation: 8655
I do not believe there is anyway to control the cursor position of the console window. You can read or write text, but that's about it. So if you want to make a console game, it will need to be text-based. You may be able to make an game ASCII art based where new text is printed to the console fast enough that it appears to be animated, but I don't think the console can go fast enough to make this work well.
Upvotes: 0
Reputation: 4786
I would suggest something like the following:
bool isRight, isUp; //Used to determine direction
while (gamePlaying)
{
if(Console.KeyAvailable)
{
Console.ReadKey(); //Do your thing in here
}
}
So you check if a key is being pressed, and if it is you read it.
Also, bear in mind if you're making a console game you'll want to double-buffer your screen and use the Win32 API to minimise write calls if possible or your screen with flicker horribly.
Upvotes: 1