Hey guys!
# = grid
O = bricks
########
#OOOOOO#
#OOOOOO#
#OOOOOO#
#OOOOOO#
#OOOOOO#
#OOOOO #
########
I´m creating a puzzle game where I have several, randomly picked bricks on a 6x6 grid. The thing is that I wanted the space at X=5 and Y=5 to be empty from the beginning, in other words instead of filling the grid with 36 bricks, I would have 35 bricks on it and 1 blank space. The reason for that is that the bricks would only be able to move on the grid if they are located next to it. (similar to a picture slide game)
The thing is that the brick located at X=4 Y=5 acts very strangely due to this. it moves twice instead of once.
I´ve located the problem to this part
Code:
if( blankPosition.x == orgPosition.x && blankPosition.y == orgPosition.y ){
continue;
}
which you see in the code below. This part is the part that creates the empty space on the grid. Everything seems to work fine when I remove it from the equation but as soon as I enable it again, the brick located at X = 4 Y =5 starts to act as the brick that should have been at X = 5 Y = 5 (if the empty space wasn´t there) is "inside" it and starts to move twice instead of once upon touch.
can anyone help me solve this?
Code:
-(void)createbricks{
//Level 1, 6 types of bricks
brickTypes[0] = @"Ch'en.png";
brickTypes[1] = @"K'ank'in.png";
brickTypes[2] = @"K'ayab'.png";
brickTypes[3] = @"kej.png";
brickTypes[4] = @"kumk'u.png";
brickTypes[5] = @"mak.png";
LianTop[0] = @"lian.png";
//empty spot in the bottom right corner of the grid
blankPosition = CGPointMake(5, 5);
int Bx = blankPosition.x;
int By = blankPosition.y;
NSLog(@"CreateBricks, blankPosition.x = Bx: %d", Bx);
NSLog(@"CreateBricks, blankPosition.y = By: %d", By);
for (int y = 0; y < BRICKHEIGHT; y++)
{
for (int x = 0; x < BRICKWIDTH; x++)
{
CGPoint orgPosition = CGPointMake(x,y);
if( blankPosition.x == orgPosition.x && blankPosition.y == orgPosition.y ){
continue;
}
UIImage *image = [UIImage imageNamed: brickTypes [rand() % 6]];
grid[x][y] = [[[UIImageView alloc] initWithImage:image] autorelease];
CGRect newFrame = grid[x][y].frame;
newFrame.origin = CGPointMake((x * 48)+52, (y * 49)+7);
grid[x][y].frame = newFrame;
[self.view addSubview:grid[x][y]];
}
}
}