// TicTac 2Playr @cid "YGt2"; @name "TicTac2Plyr"; @dbname "TicTac2Plyr"; int Turn; int Arr[ 9 ]; pointer Brd[ 3 ]; Reset(); Won(); Full(); main(){ int X, Y; // Initialize for( X = 0; X < 3; X++ ) Brd[ X ] = Arr + 3*X ; textattr( 2, 1, 2 ); textalign( 11 ); title( "Tic Tac Toe" ); graph_on(); do{ Reset(); do{ do{ }while( event(0) != 2 ); X = (int)(penx() / 53); Y = (int)(peny() / 53); if( Brd[X][Y] ) alert( "Spot's taken!" ); else{ Brd[X][Y] = Turn; if( Turn == 1 ) rect( 1, X*53+8, Y*53+8, X*53+45, Y*53+45, 0 ); else frame( 1, X*53+8, Y*53+8, X*53+45, Y*53+45, 18 ); Turn = (-1) * Turn; } }while( !Won() && !Full() ); if( Won() ){ if( -Turn == 1 ) text( 80, 80, " Box won! " ); else text( 80, 80, " Circle won! " ); }else text( 80, 80, " No winners " ); event( 1 ); event( 1 ); }while( confirm( "Another game?" ) ); exit(); } Reset(){ int X, Y; rect( 0, 0, 0, 180, 180, 0 ); for( X = 0; X <= 160; X = X + 53 ) line( 1, X, 0, X, 180 ); for( Y = 0; Y <= 160; Y = Y+ 53 ) line( 1, 0, Y, 180, Y ); Turn = 1; for( Y = 0; Y < 3; Y++ ) for( X = 0; X < 3; X++ ) Brd[ X ][ Y ] = 0; } Won(){ int i, j, k; for( i = 0; i < 3; i++ ){ j = Brd[i][0] + Brd[i][1] + Brd[i][2]; k = Brd[0][i] + Brd[1][i] + Brd[2][i]; if( k == -3 * Turn || j == -3 * Turn ) return 1; } j = Brd[0][0] + Brd[1][1] + Brd[2][2]; k = Brd[0][2] + Brd[1][1] + Brd[2][0]; if( k == -3*Turn || j == -3*Turn ) return 1; return 0; } Full(){ int X, Y; for( X = 0; X < 3; X++) for( Y = 0; Y < 3; Y++) if( Brd[X][Y] == 0 ) return 0; return 1; }