-
Moving the cursor
I was thinking of making a simple (keyword: simple! lol) tic-tac-toe game, but how do I make the cursor move around the command prompt window using the arrowkeys?
Suppose i printed something like this to the screen (without numbers):
_1_|_2_|_3_
_4_|_5_|_6_
7 | 8 | 9
then i wanted to go back and say print an X in the number 5 cell. how would i do that?
PS. Sorry if this is in the wrong forum. I couldn't decide if this was more of a C++ question or a game programming one. :p
-
read the faq for starters, then if that dont solve your problem do a search of the boards.
-
try making that boadrs like
Code:
char[][]={'_', '_', '_', '_', '_', '_', '_',
'_', '_', '_', '_', '_', '_'}
and print it out like that on screen.
and you can make a switch case or if on which char possision the "X" is going to be. and clrscr() write the variable between each key press. then you can have the X moves. and some other key to mark the char[x][y] permanent.
if this was what yo ment.
-
If you are doing this in a Windows console, (a "DOS" box), you might want to take a look through my 6 part consoles tutorial starting here.
Hey SC, long time no see.
-
Thanks for the guide adrian. finally found what I was looking for (COORD). I had gotoxy() in mind, but when I tried it, i realized Dev-C++ wasn't going to support it because it's not a standard function.
COORD does the trick though. just a few more things to type. Thanks for everyone's help.
-
I got COORD to work, and have a simple semi-working code, but I can't get it "move" after the first initial move.
Code:
#include <windows.h>
#include <iostream>
#include <conio.h>
enum
{
C = 99,
W = 119,
};
int ch = getch();
int i = 1;
using namespace std;
int X;
int Y;
int moveto( int moveX, int moveY );
int main()
{
while ( i == 1 ){
switch (ch) {
case C:
X = 0, Y = 0;
moveto(X,Y);
break;
case W:
X = 16, Y = 30;
moveto(X,Y);
break;
}
cout<<"move";
}
}
int moveto( int moveX, int moveY )
{
HANDLE hOut;
COORD Position;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
Position.X = moveX;
Position.Y = moveY;
SetConsoleCursorPosition(hOut,Position);
}
PS. I know the indentation is horrible. haha.