Printing 2 times..

So I made a tic-tac-toe game, but it has some problems


int castiguri_player_1,castiguri_player_2,turn=1;
int x,y;
int key_press;
loop_1:
system("cls");
if(turn==1) {
cout << "Player 1's turn" << endl << endl;
}
else if(turn==2) {
cout << "Player 2's turn" << endl << endl;
}
switch(key_press=getch()) {
case KEY_UP:
y++;
if(y==4) {
y=3;
}
break;
case KEY_DOWN:
y--;
if(y==0) {
y=1;
}
break;
case KEY_LEFT:
x++;
if(x==4) {
x=3;
}
break;
case KEY_RIGHT:
x--;
if(x==0) {
x=1;
}
break;
}
turn++;
if(turn==3) {
turn=1;
}
goto loop_1;


The problem is that each time I press an arrow key it prints Player 2's turn and Player 1's turn, but why?
Last edited on
your code in psuedo code...

1
2
3
4
print the prompt
get the key
update x,y
goto top


your code does nothing with the x and y. in fact the players are just taking it in turns to press left/right/up/down. they cant even press several keys to get to the square they want.

Topic archived. No new replies allowed.