### Author Topic: 'SameGame' logic help  (Read 1044 times)

#### zuperxtreme

• Contributor
• Posts: 254
• Karma: +0/-0
##### 'SameGame' logic help
« on: Sun, Nov 7, 2010 »
So I'm just remaking the 'classics', I'm making a 'SameGame' right now.

Here's what I got so far: http://megaswf.com/serve/68956/

"Removing" the blocks is sort of working, the problem is when a block has to move down two spaces and the block below is the same. Say:
Y
Y
B
Y

If you click B, the Y above it will move down, but not the first one.

My set-up is:
2D array, each cell has its own block. Each block holds its position within the array(say [1][2]) and listens for a click, if it's clicked, it calls:
Code: [Select]
`public function checkAdjacent(posX:int, posY:int):void { var blockHold:* =  gameArray[posX][posY].block; var tempBlock:*; var startType:int = blockHold.type; var gotoNext:Boolean = false; var currentCheck:int = 0; var _dirs:Array = [ { x: -1, y:0 },{ x:0, y:-1 } ,{x:0,y:0}, { x:0, y: 1 } ,{ x: 1, y:0 }]; startCheck(posX, posY); function startCheck(iniX:int, iniY:int):void { for (var i:int = 0; i < _dirs.length; i++) { if ((iniX + _dirs[i].x < 0) || (iniY + _dirs[i].y) < 0) { //out of bounds }else { //within bounds, check tiles tempBlock = gameArray[(iniX + _dirs[i].x)][(iniY + _dirs[i].y)].block; if (tempBlock.type == startType && !tempBlock.checked && tempBlock.visible) { tempBlock.visible = false; checkAdjacent(tempBlock.pos.x, tempBlock.pos.y); } } } } }`
And the block's update override:
Code: [Select]
`override public function update():void { super.update(); if (FlxG.mouse.justPressed() && this.overlapsPoint(FlxG.mouse.x, FlxG.mouse.y)) { TOP_CLASS.checkAdjacent(pos.x, pos.y); //FlxG.log("Block? " + TOP_CLASS.gameArray[pos.x][(pos.y)].block); } checkBelow();//gotta move things above as well } public function checkBelow():void { if ((pos.y + 1) < TOP_CLASS.gameArrayHeight) { var blockBelow:* = TOP_CLASS.gameArray[pos.x][(pos.y + 1)].block; if (!blockBelow.visible) { //FlxG.log("Moved block at: " + pos.x + "/" + pos.y); this.y = (pos.y + 1) * 32; this.pos.y = pos.y + 1; TOP_CLASS.gameArray[pos.x][pos.y].block = this; } } }`
I'm not sure why the function isn't continuously checking, it should, right?

..."without order nothing exists, without chaos nothing evolves"...
Zoklet.net