Hello!
I'm trying to make a game in which crates are to be moved (pushed) around towards specific locations in a grid by the player class. It includes the following separate classes: Player, Block, Crate and Goal. The Blocks are solid and can't move, the Crates are solid and can be moved, but only if the field on the other side of them is free. The player class can be moved around the grid by the player with the arrow keys, taking one step each time it is pressed.
I already got the player class to move around using the arrow keys. I'm trying to find a way to allow it to push the crates. So: if the player class is in a field horizontally or vertically next to a crate class and the field on the other side of the crate is free and the player class is moved into the direction of the crate, both the player and the crate should be moved in the specific direction.
So I've got it pretty clear on how I want it and what conditions are attached but I don't have a clue on how to get this into my program. I'm wondering whether I should be making a single canMove() method. Note that the program will need to check different fields for each arrow key being pressed.
Maybe I could add extra conditions to the main movement programming.
For example:
IF i press my left arrow key
AND there is no Block class in the field left of my class.
THEN : setLocation(getX() - 1, getY());
IF i press my left arrow key
AND there is a crate class in the field left of my class
AND the field left of that crate (2 fields left of my class) is empty
THEN : setLocation(getX() - 1, getY()); AND set location of the crate one field to the left.
But I'd have to combine them to make them work at the same time. And I still wouldn't know whether that would work, let alone what methods I'd need to work this out.
Can anybody help? Any ideas?

