Cell Values question

Hi, I am a first year programming student and I have hit a roadblock in one of my assignments. Any help will be greatly appreciated.

So I am making the penguin game (simpler version) found online:

http://www.miniclip.com/games/penguin-push/en/

The problem I am having is that once the penguin has moved a block to a goal he can move it again off of it and the goal should be back to its original color. However, my issue is that once i move a block onto the goal and move it off, the cell for where the goal is supposed to be turn gray, the background color.

Here is the method that checks for all of this. Can anyone please help. Thanks in advance.

// There is a movable block at cell location (blockX, blockY). The direction

// in which we're trying to move is (dx, dy). If the block can be moved,

// then the block should get a new location, making the cell array

// location it used to be in a FREE_CELL. Returns true when the block

// is moved (and thus the player can move too). Returns false when the

// block cannot be moved (and thus the player should stay in the same

// location). Does not change the location of the player itself.

privateboolean handleMovableBlock(int dx,int dy,int blockX,int blockY){

int newY = blockY + dy;

int newX = blockX + dx;

if ((newY < getRows() && newX < getColumns())

&& (cells[newY][newX] != CellValues.MOVABLE_BLOCK)

&& (cells[newY][newX] != CellValues.OCCUPIED_CELL)){

if (cells[blockY][blockX] != CellValues.GOAL)

cells[blockY][blockX] = CellValues.FREE_CELL;

cells[newY][newX] = CellValues.MOVABLE_BLOCK;

if(cells[newY][newX] == CellValues.MOVABLE_BLOCK_ON_GOAL)//trying to change color back to original if block is moved past

cells[blockY][blockX] = CellValues.GOAL;

returntrue;

}

returnfalse;

}

[2795 byte] By [kumar103a] at [2007-11-27 7:55:04]
# 1

i think your problem is here:

if (cells[blockY][blockX] != CellValues.GOAL)

cells[blockY][blockX] = CellValues.FREE_CELL;

cells[newY][newX] = CellValues.MOVABLE_BLOCK;

you don't put '{ ... }' after if statement. so cells[newY][newX] = CellValues.MOVABLE_BLOCK statement definitely will executed regardless that if condition.

perhaps you mean :

if (cells[blockY][blockX] != CellValues.GOAL) {

cells[blockY][blockX] = CellValues.FREE_CELL;

cells[newY][newX] = CellValues.MOVABLE_BLOCK;

}

this also not correct yet. u should replace cell[blockY][blockX] to its old value. if its old is GOAL. by replacing to FREE,

Puff!!!... your goal disappear... =D

Edit: confuse between blockX,Y and newX,Y

Message was edited by:

j_shadinata

j_shadinataa at 2007-7-12 19:36:23 > top of Java-index,Desktop,Core GUI APIs...