"Moving" graphics in console

Hi!
I'm trying to make a text-based game and I'd like to use an arrow pointing at my current option during the start-up menu as well as during the game, for example:
-> 1. Singleplayer
2. Multiplayer

and when I click up or down using the arrow keypads the arrow will skip to the next option. Following the previous example, if I press down it will look like this:
1. Singleplayer
-> 2. Multiplayer

Using system ("cls") to clear screen and then re-printing everything is not an acceptable solution because it's too slow.

I'm using Visual Studio C++ with windows 7.
Thanks in advance! :)
You can make a text-based game, but you should not do it in the console. Learn a graphics library like SFML or SDL - you can still make the game text-based, but I and others strong recommend leaving the console behind at this point.
I agree with L B. There are ways to do what you want... but learning how to do them would be a waste of time IMO, because it'd be just as easy to learn how to use a graphic lib.
Either way, if you are still going to make this in the console. Here's a link for a goto function, which will set the cursor position.

Just cout spaces at the correct position to remove the arrow.

http://www.cplusplus.com/forum/beginner/28859/#msg156124
In order to move the arrow to Multiplayer you'll have to use gotoxy statement in which you can move your cursor anywhere on the console screen.
Print Space where you want character to become removed. Space will replace arrow.

Let me give you a code for example, do run it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//Press Right and Left key and see what Happens?

#include <iomanip>
#include <windows.h>
using namespace std;

int main()
{
int i = 0;

while(1) //infinite loop!
{


if(GetAsyncKeyState(VK_RIGHT))
{
i++;
cout<<setw(i)<<"---------->" ;
}

if(GetAsyncKeyState(VK_LEFT))
{
i--;
cout<<setw(i)<<"<----------";
}

Sleep(10);
system("cls");
}
return 0;
}


Though I've used syste("cls"), you can edit this code. Try to figure out how helpful space is as an alternate to system("cls")
Last edited on
Thank you for such fast replies, really appreciated.

I'm afraid I'll have to do it in the console window because it's a task from my professor and one of the requirements is to create the game in the console.

Solution understood, thread closed.
Thanks again :)
Topic archived. No new replies allowed.