I'm working on the base of a game in which the object is to destroy as many blocks as possible. If connected, clicking a block will destroy it along with all blocks connected to it (cardinal directions only). The blocks above a destroyed section will fall down. If a column is empty, all columns to the right of it will shift left to occupy the empty space and ensure that the blocks are kept together.
I am a bit confused: you said all the blocks above the clicked block will be destroyed yet you also said those same blocks will fall down. This sounds very contradictory if they fall down to me, they are still displayed in the game. Which one is it?
Assuming, the above blocks do get destroyed along with the clicked block, here are my thoughts:
for the destroy block implementation for cardinal direction(North): check what column of the block that was clicked and loop through every block above that block that clicked and remove them for each run of the loop. These blocks above the clicked bows are all located at the rows less than the row of the clicked block. Their column remains the same.
Say the block clicked was at row 5 and column 5, the blocks destroyed should be at the same column as the clicked block which is 5, but the rows of those destroyed are less than the column of the clicked block. These values are 0-4.
For the other cardinal directions, the approach is very similar. Try drawing what I said on paper and the implementations will be clear.
My problem lies with just how I should go about tracking and shifting the columns to the right of an empty one. I use an associative array to keep track of the columns (1-10) and which blocks are located within them. Beyond that, I'm not too sure. I have had some success but run into problems when there is more than one empty column next to each other, between full columns.
in terms of shifting these are just row and column offsets. If you are shifting blocks to the left, then check the column right after the empty column and offset row and column of those blocks in that column.
In terms of tracking, the block has only two information: their row and column represented the blocks position in the game. Arrays will do it.
This project reminds me of a Tetris and Bomberman game implementations.
Edited by warnexus, 03 October 2013 - 09:07 PM.