From 208706918fde31ae1a38b466a168087f406dbf14 Mon Sep 17 00:00:00 2001 From: exterlulz Date: Sat, 21 Aug 2010 16:19:24 +0200 Subject: [PATCH] clean some stuff --- src/Game.m | 251 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 138 insertions(+), 113 deletions(-) diff --git a/src/Game.m b/src/Game.m index 65689ea..3d1321f 100644 --- a/src/Game.m +++ b/src/Game.m @@ -21,104 +21,119 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #import "Game.h" #import "Gem.h" -// + // MW... -// #import "ScoreBubble.h" -// @implementation Game -- (id) init +- (id)init { - int i,j; - self = [super init]; + self = [super init]; + if (self != nil) { gemsFaded = 0; - for (i = 0; i < 8; i++) - for (j = 0; j < 8; j++) - board[i][j] = [[Gem alloc] init]; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + board[i][j] = [[Gem alloc] init]; + } + } + // MW - scoreBubbles= [[NSMutableArray arrayWithCapacity:12] retain]; - // - return self; + scoreBubbles = [[NSMutableArray arrayWithCapacity:12] retain]; + } + + return self; } -- (id) initWithImagesFrom:(NSArray *) imageArray +- (id)initWithImagesFrom:(NSArray *)imageArray { - int i,j; - self = [super init]; + self = [super init]; + if (self != nil) { srand([[NSDate date] timeIntervalSince1970]); // seed by time - for (i = 0; i < 8; i++) - for (j = 0; j < 8; j++) - { - int r = [self randomGemTypeAt:i:j]; - board[i][j] = [[Gem gemWithNumber:r andImage:[imageArray objectAtIndex:r]] retain]; - [board[i][j] setPositionOnBoard:i:j]; - [board[i][j] setPositionOnScreen:i*48:j*48]; - [board[i][j] shake]; - } - // MW... - scoreBubbles= [[NSMutableArray arrayWithCapacity:12] retain]; - // + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + int r = [self randomGemTypeAt:i:j]; + Gem *gem = [[Gem gemWithNumber:r andImage:[imageArray objectAtIndex:r]] retain]; + board[i][j] = gem; + [gem setPositionOnBoard:i:j]; + [gem setPositionOnScreen:i*48:j*48]; + [gem shake]; + } + } + + // MW... + scoreBubbles = [[NSMutableArray arrayWithCapacity:12] retain]; + score = 0; gemsFaded = 0; bonusMultiplier = 1; - return self; + } + + return self; } -- (id) initWithSpritesFrom:(NSArray *) spriteArray +- (id)initWithSpritesFrom:(NSArray *)spriteArray { - int i,j; - self = [super init]; + self = [super init]; + if (self != nil) { srand([[NSDate date] timeIntervalSince1970]); // seed by time - for (i = 0; i < 8; i++) - for (j = 0; j < 8; j++) - { - //int r = (rand() % 3)*2+((i+j)%2); - int r = [self randomGemTypeAt:i:j]; - board[i][j] = [[Gem gemWithNumber:r andSprite:[spriteArray objectAtIndex:r]] retain]; - [board[i][j] setPositionOnBoard:i:j]; - [board[i][j] setPositionOnScreen:i*48:j*48]; - [board[i][j] shake]; - } - // MW... - scoreBubbles= [[NSMutableArray arrayWithCapacity:12] retain]; - // + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + //int r = (rand() % 3)*2+((i+j)%2); + int r = [self randomGemTypeAt:i:j]; + board[i][j] = [[Gem gemWithNumber:r andSprite:[spriteArray objectAtIndex:r]] retain]; + [board[i][j] setPositionOnBoard:i:j]; + [board[i][j] setPositionOnScreen:i*48:j*48]; + [board[i][j] shake]; + } + } + + // MW... + scoreBubbles= [[NSMutableArray arrayWithCapacity:12] retain]; + score = 0; gemsFaded = 0; bonusMultiplier = 1; - return self; + } + + return self; } -- (void) dealloc +- (void)dealloc { - int i,j; - for (i = 0; i < 8; i++) - for (j = 0; j < 8; j++) - [board[i][j] release]; - // MW... - [scoreBubbles release]; - // - [super dealloc]; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + [board[i][j] release]; + } + } + + // MW... + [scoreBubbles release]; + + [super dealloc]; } -- (void) setImagesFrom:(NSArray *) imageArray +- (void)setImagesFrom:(NSArray *)imageArray { - int i,j; - for (i = 0; i < 8; i++) - for (j = 0; j < 8; j++) - [board[i][j] setImage:[imageArray objectAtIndex:[board[i][j] gemType]]]; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + Gem *gem = board[i][j]; + [gem setImage:[imageArray objectAtIndex:[gem gemType]]]; + } + } } -- (void) setSpritesFrom:(NSArray *) spriteArray +- (void)setSpritesFrom:(NSArray *)spriteArray { - int i,j; - for (i = 0; i < 8; i++) - for (j = 0; j < 8; j++) - [board[i][j] setSprite:[spriteArray objectAtIndex:[board[i][j] gemType]]]; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + Gem *gem = board[i][j]; + [gem setSprite:[spriteArray objectAtIndex:[gem gemType]]]; + } + } } -- (int) randomGemTypeAt:(int)x :(int)y +- (int)randomGemTypeAt:(int)x :(int)y { int c = (x+y) % 2; int r = rand() % 7; @@ -129,33 +144,32 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. return (r | 1); // odd } -- (Gem *) gemAt:(int)x :(int)y -{ - return board[x][y]; +- (Gem *)gemAt:(int)x :(int)y { + return board[x][y]; } -// // MW... -// -- (NSMutableArray *)scoreBubbles -{ +- (NSMutableArray *)scoreBubbles { return scoreBubbles; } -// -//// -- (void) setMuted:(BOOL)value +- (void)setMuted:(BOOL)value { - int i,j; - muted = value; - if (muted) - for (i = 0; i < 8; i++) - for (j = 0; j < 8; j++) - [board[i][j] setSoundsTink:NULL Sploink:NULL]; - else - for (i = 0; i < 8; i++) - for (j = 0; j < 8; j++) - [board[i][j] setSoundsTink:[NSSound soundNamed:@"tink"] Sploink:[NSSound soundNamed:@"sploink"]]; + muted = value; + if (muted) { + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + [board[i][j] setSoundsTink:NULL Sploink:NULL]; + } + } + } + else { + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + [board[i][j] setSoundsTink:[NSSound soundNamed:@"tink"] Sploink:[NSSound soundNamed:@"sploink"]]; + } + } + } } - (void) swap:(int) x1 :(int) y1 and:(int) x2:(int) y2 @@ -168,9 +182,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. sx1 = x1; sx2 = x2; sy1 = y1; sy2 = y2; } -- (void) unswap -{ - [self swap:sx1:sy1 and:sx2:sy2]; +- (void)unswap { + [self swap:sx1:sy1 and:sx2:sy2]; } - (BOOL) testForThreeAt:(int) x :(int) y @@ -305,20 +318,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. return NO; } -- (BOOL) checkBoardForThrees +- (BOOL)checkBoardForThrees { - int i,j; - BOOL result = NO; - // CASCADE BONUS increase - cascade++; - // - for (i = 0; i < 8; i++) - for (j = 0; j < 8; j++) - if (board[i][j]._state != GEMSTATE_FADING) - result = result | [self testForThreeAt:i:j]; - // CASCADE BONUS check for reset - if (!result) cascade = 1; - return result; + BOOL result = NO; + + // CASCADE BONUS increase + cascade++; + + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + if (board[i][j]._state != GEMSTATE_FADING) { + result = result | [self testForThreeAt:i:j]; + } + } + } + + // CASCADE BONUS check for reset + if (!result) { + cascade = 1; + } + + return result; } - (void) showAllBoardMoves @@ -496,21 +516,26 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. } } -- (void) shake +- (void)shake { - int i,j; - for (i = 0; i < 8; i++) - for (j = 0; j < 8; j++) - [board[i][j] shake]; + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + [board[i][j] shake]; + } + } } -- (void) erupt +- (void)erupt { - int i,j; - if (!muted) [[NSSound soundNamed:@"yes"] play]; - for (i = 0; i < 8; i++) - for (j = 0; j < 8; j++) - [board[i][j] erupt]; + if (!muted) { + [[NSSound soundNamed:@"yes"] play]; + } + + for (int i = 0; i < 8; i++) { + for (int j = 0; j < 8; j++) { + [board[i][j] erupt]; + } + } } - (void) explodeGameOver @@ -570,7 +595,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. return NSMakePoint(hintx * 48, hinty * 48); } -- (float) collectGemsFaded +- (float)collectGemsFaded { float result = (float)gemsFaded; gemsFaded = 0; -- 2.11.4.GIT