hi I started making Tic Tac Toe, but I'm having a hard time making it move inside the box properly. it's like going out of bounds the box that I specifified. I hope you could help me with this code.. BTW I'm using Borland Turbo C++ 3.0. Language is C
BTW, my boxes right there are ASCII codes so it's kinda messed right here..
Code:
#include <stdio.h>
#include <conio.h>
#define LEFT 0x4B
#define RIGHT 0X4D
#define UP 0x48
#define DOWN 0x50
#define ENTER 0x0D
#define ESC 0x1B
void box( void );
int main( void )
{
char board[ 3 ][ 3 ];
char control;
int colsPosition[] = { 31, 37, 43 };
int rowPosition1[] = { 11, 14, 17 };
int rowPosition2[] = { 12, 15, 18 };
int travelRightToLeft = 0, travelLeftToRight = 0;
int travelDown = 0, travelUp = 0;
clrscr();
box();
do
{
control = getch();
switch( control )
{
case LEFT:
clrscr();
box();
if( travelRightToLeft > 0 )
{
travelRightToLeft--;
textcolor( LIGHTGREEN );
gotoxy( colsPosition[ travelRightToLeft ], rowPosition1[ travelDown ] );cprintf( "ÉÍÍÍ»" );
gotoxy( colsPosition[ travelRightToLeft ], rowPosition2[ travelDown ] );cprintf( "ÈÍÍͼ" );
travelLeftToRight--;
}
else { }
break;
case RIGHT:
clrscr();
box();
if( travelLeftToRight < 3 )
{
textcolor( LIGHTGREEN );
gotoxy( colsPosition[ travelLeftToRight ], rowPosition1[ 0 ] );cprintf( "ÉÍÍÍ»" );
gotoxy( colsPosition[ travelLeftToRight ], rowPosition2[ 0 ] );cprintf( "ÈÍÍͼ" );
travelLeftToRight++;
travelRightToLeft++;
}
else { }
break;
case DOWN:
clrscr();
box();
if( travelDown < 3 )
{
travelDown++;
textcolor( LIGHTGREEN );
gotoxy( colsPosition[ travelRightToLeft ], rowPosition1[ travelDown ] );cprintf( "ÉÍÍÍ»" );
gotoxy( colsPosition[ travelRightToLeft ], rowPosition2[ travelDown ] );cprintf( "ÈÍÍͼ" );
travelUp++;
}
else { }
break;
case UP:
clrscr();
box();
if( travelUp > 0 )
{
textcolor( LIGHTGREEN );
travelUp--;
gotoxy( colsPosition[ travelLeftToRight ], rowPosition1[ travelUp ] );cprintf( "ÉÍÍÍ»" );
gotoxy( colsPosition[ travelLeftToRight ], rowPosition2[ travelUp ] );cprintf( "ÈÍÍͼ" );
travelDown--;
}
else { }
break;
default:
break;
}
}while( control != ESC );
return 0;
}
void box( void )
{
textcolor( CYAN );
gotoxy( 30, 5 );cprintf( "My Tic-Tac-Toe" );
//board
textcolor( BLUE );
gotoxy( 30, 10 );cprintf( "ÉÍÍÍÍÍËÍÍÍÍÍËÍÍÍÍÍ»" );
gotoxy( 30, 11 );cprintf( "º º º º" );
gotoxy( 30, 12 );cprintf( "º º º º" );
gotoxy( 30, 13 );cprintf( "ÌÍÍÍÍÍÎÍÍÍÍÍÎÍÍÍÍ͹" );
gotoxy( 30, 14 );cprintf( "º º º º" );
gotoxy( 30, 15 );cprintf( "º º º º" );
gotoxy( 30, 16 );cprintf( "ÌÍÍÍÍÍÎÍÍÍÍÍÎÍÍÍÍ͹" );
gotoxy( 30, 17 );cprintf( "º º º º" );
gotoxy( 30, 18 );cprintf( "º º º º" );
gotoxy( 30, 19 );cprintf( "ÈÍÍÍÍÍÊÍÍÍÍÍÊÍÍÍÍͼ" );
}
I cannot make a dummy box right here.. but there is a box that has 9 windows. I have a little box inside the upper left window which should be the start position. Then that box is the box I wanted to move inside each of the windows.