How do you delete the returned string? Also I made a few alterations to the code so that for the most part the turn changes approriately but your method would be more efficient...
while (LoopGDK())
{
int mC = dbMouseClick();
if (mC == 1)
{
playerId = 3 - playerId;
Play();
dbWait(100);
}
dbSync();
}
this seems to work as long as you dont accidently click a used square or the black space..
I just finished making the adjustments you suggested and this is the complete code up to this point
#include "DarkGDK.h"
//protypes
void Play ( void );
void PlacePiece ( void );
//Globals
int playerId = 2;
int clicked;
int boxs[ ] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int cat = 0;
int mX;
int mY;
void DarkGDK ( void )
{
//Variables
int windowH = dbScreenHeight ( );
int windowW = dbScreenWidth ( );
int windowD = dbScreenDepth ( );
//turn sync on and set sync rate
dbSyncOn( );
dbSyncRate( 60 );
//Window Settings
dbSetWindowTitle( "Tic Tac Toe" );
if ( dbCheckDisplayMode( 800, 600, 32) )
dbSetDisplayMode ( 800, 600, 32);
dbSetWindowOff( );
dbBackdropOn( );
dbColorBackdrop( dbRgb( 0, 0, 0));
//LoadImages
dbLoadImage( "EmptyCell.bmp", 1 );
dbLoadImage( "XCell.bmp", 2 );
dbLoadImage( "OCell.bmp", 3 );
dbLoadImage( "NewGame.bmp", 4 );
/*Change images into sprites && position on screen
screen is 800x600 */
dbSprite( 1, 188, 66, 1);
dbSprite( 2, 354, 66, 1);
dbSprite( 3, 520, 66, 1);
dbSprite( 4, 188, 232, 1);
dbSprite( 5, 354, 232, 1);
dbSprite( 6, 520, 232, 1);
dbSprite( 7, 188, 398, 1);
dbSprite( 8, 354, 398, 1);
dbSprite( 9, 520, 398, 1);
dbSprite( 10, 0, 500, 4);
while (LoopGDK())
{
int mC = dbMouseClick();
if (mC == 1)
{
Play();
}
dbSync();
}
return;
}
void Play()
{
int mX = dbMouseX();
int mY = dbMouseY();
//int mC = dbMouseClick();
//if (mC == 1)
//{
if ( mX > 188 && mY > 66 && mX < 288 && mY < 166 )
{
clicked = 1;
PlacePiece();
}
if ( mX > 354 && mY > 66 && mX < 454 && mY < 166 )
{
clicked = 2;
PlacePiece();
}
if ( mX > 520 && mY > 66 && mX < 620 && mY < 166 )
{
clicked = 3;
PlacePiece();
}
if ( mX > 188 && mY > 232 && mX < 288 && mY < 332 )
{
clicked = 4;
PlacePiece();
}
if ( mX > 354 && mY > 232 && mX < 454 && mY < 332 )
{
clicked = 5;
PlacePiece();
}
if ( mX > 520 && mY > 232 && mX < 620 && mY < 332 )
{
clicked = 6;
PlacePiece();
}
if ( mX > 188 && mY > 398 && mX < 288 && mY < 498 )
{
clicked = 7;
PlacePiece();
}
if ( mX > 354 && mY > 398 && mX < 454 && mY < 498 )
{
clicked = 8;
PlacePiece();
}
if ( mX > 520 && mY > 398 && mX < 620 && mY < 498 )
{
clicked = 9;
PlacePiece();
}
//}
}
void PlacePiece( void )
{
switch ( clicked )
{
case 1:
if ( boxs[0] == 0 )
{
boxs[0] = playerId;
dbSprite( 1, 188, 66, playerId + 1 );
playerId = 3 - playerId;
break;
} else {
dbText( 0, 0, "This box is already being used");
break;
}
case 2:
if ( boxs[1] == 0 )
{
boxs[1] = playerId;
dbSprite( 2, 354, 66, playerId + 1 );
playerId = 3 - playerId;
break;
} else {
dbText( 0, 0, "This box is already being used");
break;
}
case 3:
if ( boxs[2] == 0 )
{
boxs[2] = playerId;
dbSprite( 3, 520, 66, playerId + 1 );
playerId = 3 - playerId;
break;
} else {
dbText( 0, 0, "This box is already being used");
break;
}
case 4:
if ( boxs[3] == 0 )
{
boxs[3] = playerId;
dbSprite( 4, 188, 232, playerId + 1 );
playerId = 3 - playerId;
break;
} else {
dbText( 0, 0, "This box is already being used");
break;
}
case 5:
if ( boxs[4] == 0 )
{
boxs[4] = playerId;
dbSprite( 5, 354, 232, playerId + 1 );
playerId = 3 - playerId;
break;
} else {
dbText( 0, 0, "This box is already being used");
break;
}
case 6:
if ( boxs[5] == 0 )
{
boxs[5] = playerId;
dbSprite( 6, 520, 232, playerId + 1 );
playerId = 3 - playerId;
break;
} else {
dbText( 0, 0, "This box is already being used");
break;
}
case 7:
if ( boxs[6] == 0 )
{
boxs[6] = playerId;
dbSprite( 7, 188, 398, playerId + 1 );
playerId = 3 - playerId;
break;
} else {
dbText( 0, 0, "This box is already being used");
break;
}
case 8:
if ( boxs[7] == 0 )
{
boxs[7] = playerId;
dbSprite( 8, 354, 398, playerId + 1 );
playerId = 3 - playerId;
break;
} else {
dbText( 0, 0, "This box is already being used");
break;
}
case 9:
if ( boxs[8] == 0 )
{
boxs[8] = playerId;
dbSprite( 9, 520, 398, playerId + 1 );
playerId = 3 - playerId;
break;
} else {
dbText( 0, 0, "This box is already being used");
break;
}
default:
dbPrint("ERROR");
break;
}
}
It works proporly now, My next step is to create a newgame function that resets all the boxs[ ] to 0, resets the sprites to image 1, and sets the playerId to 1..
NewGame()..
void NewGame ( void )
{
for (int n = 0; n < 9; n++)
{
boxs[n] = 0;
}
dbSprite( 1, 188, 66, 1);
dbSprite( 2, 354, 66, 1);
dbSprite( 3, 520, 66, 1);
dbSprite( 4, 188, 232, 1);
dbSprite( 5, 354, 232, 1);
dbSprite( 6, 520, 232, 1);
dbSprite( 7, 188, 398, 1);
dbSprite( 8, 354, 398, 1);
dbSprite( 9, 520, 398, 1);
playerId = 1;
}
And add this to the bottom of Play()
if ( mX > 0 && mY > 500 && mX < 300 && mY < 600)
{
NewGame();
}
Is there a way to change the directory to load the images from? as it is the images must be in the same directory as the exe. I would like to have them in a folder labled "media" or something to help organize it a little better.
Also, I think that in the long run I will make many versions of tic tac toe and have them all be separate programs. But I will make one prgram that can launch the one that somone wants to play if that makes sense. Is there a way to code it so that it will launch other applications?
I notice that in some of the samples there are animated sprites in the format of .png and .bmp, is there a good tutorial on how to create images that can be used as animated sprites?
Is there a way to replace the cursor with a sprite so that I can use sprite collosion instead of x/y coordinates to determine what the players are clicking on?
When I click on a cell it will both place my piece and tell me that the box is being used already ( I assume it is again because the loop runs multiple times within one click of the mouse ) Eventually i will have a sound play instead of a message but I dont want the sound played at the same time a player attempts to place a piece. Any suggestions?
[edit]Refer to the original post for downloads...
EYE R T3H +ick +ack +oe mester