My Scenario
There is ABSOLUTELY no reason why the man can not move in all 4 directions.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | if ( "w" .equals(Greenfoot.getKey())) { setLocation(getX(), getY() - 1 ); } if ( "s" .equals(Greenfoot.getKey())) { setLocation(getX(), getY() + 1 ); } if ( "d" .equals(Greenfoot.getKey())) { setLocation(getX() + 1 , getY()); } if ( "a" .equals(Greenfoot.getKey())) { setLocation(getX() - 1 , getY()); } |
1 2 3 4 5 6 7 | List<String> enteredKeys = new ArrayList<String>(); // this is a list to hold the individually keystrokes in the order that they are entered public String getKey() { if (enteredKeys.isEmpty()) return null ; // if the list is empty, return a 'null' value return enteredKeys.remove( 0 ); // otherwise, remove and return the first element in the list } |