Skip to content

Instantly share code, notes, and snippets.

@gregtemp
Created June 10, 2013 21:43
Show Gist options
  • Save gregtemp/5752638 to your computer and use it in GitHub Desktop.
Save gregtemp/5752638 to your computer and use it in GitHub Desktop.
MatchGame (ITP version) a simple match game
//
// C4WorkSpace.m
// Examples
//
// Created by Greg Debicki.
//
#import "C4WorkSpace.h"
@implementation C4WorkSpace {
C4Shape *s1, *s2, *s3, *s4, *s5, *s6;
C4Shape *m1, *m2, *m3, *m4, *m5, *m6;
C4Image *i1, *i2, *i3, *i4, *i5, *i6;
C4Timer *win;
BOOL s1Bool, s2Bool, s3Bool, s4Bool, s5Bool, s6Bool;
}
-(void)setup {
[self setupMasks];
[self setupImages];
[self placeImages];
[self setupShapes];
[self setupGestures];
win = [C4Timer automaticTimerWithInterval:1.0f target:self method:@"didWin" repeats:YES];
}
-(void) didWin {
if (s1Bool==YES && s2Bool==YES && s3Bool==YES &&
s4Bool==YES && s5Bool==YES && s6Bool==YES) {
s1.animationDuration = 2.0f;
s2.animationDuration = 2.0f;
s3.animationDuration = 2.0f;
s4.animationDuration = 2.0f;
s5.animationDuration = 2.0f;
s6.animationDuration = 2.0f;
s1Bool = NO;
s2Bool = NO;
s3Bool = NO;
s4Bool = NO;
s5Bool = NO;
s6Bool = NO;
s1.alpha = 1.0f;
s2.alpha = 1.0f;
s3.alpha = 1.0f;
s4.alpha = 1.0f;
s5.alpha = 1.0f;
s6.alpha = 1.0f;
}
}
-(void) setupMasks {
CGRect rect = CGRectMake(0, 0, 150, 150);
m1 = [C4Shape ellipse:rect];
m2 = [C4Shape ellipse:rect];
m3 = [C4Shape ellipse:rect];
m4 = [C4Shape ellipse:rect];
m5 = [C4Shape ellipse:rect];
m6 = [C4Shape ellipse:rect];
}
-(void) setupImages {
i1 = [C4Image imageNamed:@"C4Sky"];
i2 = [C4Image imageNamed:@"C4Table"];
i3 = [C4Image imageNamed:@"C4Gradient"];
i4 = [C4Image imageNamed:@"C4Sky"];
i5 = [C4Image imageNamed:@"C4Table"];
i6 = [C4Image imageNamed:@"C4Gradient"];
i1.width *= .5f;
i2.width *= .5f;
i3.width *= .5f;
i4.width *= .5f;
i5.width *= .5f;
i6.width *= .5f;
m1.center = i1.center;
i1.mask = m1;
m2.center = i2.center;
i2.mask = m2;
m3.center = i3.center;
i3.mask = m3;
m4.center = i4.center;
i4.mask = m4;
m5.center = i5.center;
i5.mask = m5;
m6.center = i6.center;
i6.mask = m6;
}
-(void) placeImages {
CGPoint currentCenter = self.canvas.center;
currentCenter.x -= 200;
i1.center = currentCenter;
currentCenter.x += 200;
i2.center = currentCenter;
currentCenter.x += 200;
i3.center = currentCenter;
currentCenter = self.canvas.center;
currentCenter.x -= 200;
currentCenter.y += 200;
i4.center = currentCenter;
currentCenter.x += 200;
i5.center = currentCenter;
currentCenter.x += 200;
i6.center = currentCenter;
[self.canvas addObjects:@[i1,i2,i3,i4,i5,i6]];
i1.userInteractionEnabled = NO;
i2.userInteractionEnabled = NO;
i3.userInteractionEnabled = NO;
i4.userInteractionEnabled = NO;
i5.userInteractionEnabled = NO;
i6.userInteractionEnabled = NO;
}
-(void) setupShapes {
CGRect rect = CGRectMake(0, 0, 150, 150);
s1 = [C4Shape ellipse:rect];
s2 = [C4Shape ellipse:rect];
s3 = [C4Shape ellipse:rect];
s4 = [C4Shape ellipse:rect];
s5 = [C4Shape ellipse:rect];
s6 = [C4Shape ellipse:rect];
s1.center = i1.center;
s2.center = i2.center;
s3.center = i3.center;
s4.center = i4.center;
s5.center = i5.center;
s6.center = i6.center;
[self.canvas addObjects:@[s1,s2,s3,s4,s5,s6]];
}
-(void) setupGestures {
[self listenFor:@"touchesBegan" fromObject:s1 andRunMethod:@"s1On"];
[self listenFor:@"touchesBegan" fromObject:s4 andRunMethod:@"s4On"];
[self listenFor:@"touchesBegan" fromObject:s2 andRunMethod:@"s2On"];
[self listenFor:@"touchesBegan" fromObject:s5 andRunMethod:@"s5On"];
[self listenFor:@"touchesBegan" fromObject:s3 andRunMethod:@"s3On"];
[self listenFor:@"touchesBegan" fromObject:s6 andRunMethod:@"s6On"];
}
-(void) s1On {
s1.animationDuration = 0.2f;
s1.alpha = 0.0f;
s1Bool = YES;
[self runMethod:@"s1Off" afterDelay:1.0f]; }
-(void) s1Off {
if(s4Bool != YES) {
s1.alpha = 1.0f;
s1Bool = NO; }}
-(void) s4On {
s4.animationDuration = 0.2f;
s4.alpha = 0.0f;
s4Bool = YES;
[self runMethod:@"s4Off" afterDelay:1.0f]; }
-(void) s4Off {
if(s1Bool != YES) {
s4.alpha = 1.0f;
s4Bool = NO; }}
-(void) s2On {
s2.animationDuration = 0.2f;
s2.alpha = 0.0f;
s2Bool = YES;
[self runMethod:@"s2Off" afterDelay:1.0f]; }
-(void) s2Off {
if(s5Bool != YES) {
s2.alpha = 1.0f;
s2Bool = NO; }}
-(void) s5On {
s5.animationDuration = 0.2f;
s5.alpha = 0.0f;
s5Bool = YES;
[self runMethod:@"s5Off" afterDelay:1.0f]; }
-(void) s5Off {
if(s2Bool != YES) {
s5.alpha = 1.0f;
s5Bool = NO; }}
-(void) s3On {
s3.animationDuration = 0.2f;
s3.alpha = 0.0f;
s3Bool = YES;
[self runMethod:@"s3Off" afterDelay:1.0f]; }
-(void) s3Off {
if(s6Bool != YES) {
s3.alpha = 1.0f;
s3Bool = NO; }}
-(void) s6On {
s6.animationDuration = 0.2f;
s6.alpha = 0.0f;
s6Bool = YES;
[self runMethod:@"s6Off" afterDelay:1.0f]; }
-(void) s6Off {
if(s3Bool != YES) {
s6.alpha = 1.0f;
s6Bool = NO; }}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment