tic tac toe game

Discuss any Chipmunk bugs here.
Post Reply
jimmy.patel
Posts: 1
Joined: Sat Nov 05, 2011 7:01 am
Contact:

tic tac toe game

Post by jimmy.patel »

hello i m new in game development and i m stuck in the developmemnt of tic tac toe game.
my problem is i m usinf touch delegate for making cross and circle visible.
but touch area is on whole screen so it makes cross and circles at every part of the screen .
can any body help me in making the boundary for the touch event so that i can set the boundary of the touch which is implemented
i have attached my code if anybody can help me plz help me.

my .m file represents as follows have a look at it and m sorry if i have not written the code in proper standard asa i m a new developer i m learning to write it perfectly.


+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];

// 'layer' is an autorelease object.
HelloWorldLayer *layer = [HelloWorldLayer node];

// add layer as a child to scene
[scene addChild: layer];

// return the scene
return scene;
}

// on "init" you need to initialize your instance
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init])) {


// create and initialize a Label
CCLabelTTF *label = [CCLabelTTF labelWithString:@"TIC TAC TOE" fontName:@"Marker Felt" fontSize:54];



// position the label on the center of the screen
label.position = ccp(150,420 );

// add the label as a child to this Layer

[self addChild: label];

// ask director the the window size

CGSize size = [[CCDirector sharedDirector] winSize];

//add sprite of circle

backGround=[CCSprite spriteWithFile:@"background.jpeg"];
backGround.position=ccp( size.width /2 , size.height/2 );
[self addChild:backGround];



self.isTouchEnabled=TRUE;



}
return self;
}

// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
// in case you have something to dealloc, do it in this method
// in this particular example nothing needs to be released.
// cocos2d will automatically release all the children (Label)

// don't forget to call "super dealloc"

/*
self.Circle=nil;
self.Cross=nil;
self.backGround=nil;
self.sampleLayer=nil;
*/
[super dealloc];
}
-(void) registerWithTouchDispatcher
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}



-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{



touchCounter++;

NSLog(@"touch began");
[self Cordinatedetection:touch];



return TRUE;

}

-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

int count=[touches count];

NSLog(@"count %d",count);

}

//METHOD IMPLEMENTED WHEN THE CALL FUNCTION IS CALLED

-(void)Cordinatedetection:(UITouch*)touchfound{

[Circle setVisible:TRUE];
[Cross setVisible:TRUE];

CGPoint Point=[touchfound locationInView:[UIApplication sharedApplication].keyWindow];
float x=Point.x;
float y=Point.y;


//touchCounter++;

float z=[UIScreen mainScreen].bounds.size.height;

float tempHeight=z-y;


//particleSystem.position=ccp(x, tempHeight);

if (touchCounter<10) {

//odd and even touches recognization logic
if (touchCounter%2==0) {
Cross=[CCSprite spriteWithFile:@"cross.png"];
Cross.position=ccp(x,tempHeight);
[self addChild:Cross];

crosscount++;
NSLog(@"number of cross on screen %d",crosscount);
if (crosscount==3) {
NSLog(@"cross wins");

UIAlertView* alert=[[UIAlertView alloc]initWithTitle:@"Game Over" message:@"thanks for playing tic tav toe.!" delegate:self cancelButtonTitle:@"mian menu" otherButtonTitles:nil, nil];

[alert show];

[alert release];

}


}
else{
Circle=[CCSprite spriteWithFile:@"circle.png"];
Circle.position=ccp(x,tempHeight);
[self addChild:Circle];

circlecount++;
NSLog(@"number of circle on screen %d",circlecount);

if (circlecount==3) {


UIAlertView* alert=[[UIAlertView alloc]initWithTitle:@"Game Over" message:@"Player one won!!" delegate:self cancelButtonTitle:@"main menu" otherButtonTitles:nil, nil];

[alert show];

[alert release];

}

}
}

else{

// self.isTouchEnabled=FALSE;
UIAlertView* alert=[[UIAlertView alloc]initWithTitle:@"Game Over" message:@"PLay Again!!" delegate:self cancelButtonTitle:@"Main Menu" otherButtonTitles:@"Submit Scores!", nil];

[alert show];

[alert release];


}


}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0)
{


[[CCDirector sharedDirector] replaceScene:[menuClass scene]];
NSLog(@"ok");


}
else
{
NSLog(@"cancel");
}
}
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: tic tac toe game

Post by slembcke »

You should post this on the Cocos2D forum: http://www.cocos2d-iphone.org/forum/

This forum is specifically for the Chipmunk Physics library.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests