Advertisement
dorin98

Untitled

Dec 11th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. package commands;
  2.  
  3. import entities.Hero;
  4. import entities.Hero.Direction;
  5.  
  6. public class MoveCommand implements Command {
  7.    
  8.     private Hero hero;
  9.     private Direction direction;
  10.    
  11.     public MoveCommand(Hero h, Direction dir) {
  12.         // TODO Auto-generated constructor stub
  13.         hero = h;
  14.         direction = dir;
  15.     }
  16.  
  17.     @Override
  18.     public void undo() {
  19.         // TODO Auto-generated method stub
  20.         switch (direction) {
  21.             case E:
  22.                 hero.move(Direction.W);
  23.             case W:
  24.                 hero.move(Direction.E);
  25.             case N:
  26.                 hero.move(Direction.S);
  27.             case S:
  28.                 hero.move(Direction.N);
  29.             default:
  30.                 break;
  31.         }
  32.        
  33.     }
  34.  
  35.     @Override
  36.     public void execute() {
  37.         // TODO Auto-generated method stub
  38.         hero.move(direction);
  39.        
  40.     }
  41.  
  42.     // TODO implement the move command
  43.     /*  - MoveCommand(Hero, Direction)
  44.         - void undo()
  45.         - void execute()
  46.         - maybe helper method for undo ?
  47.     */
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement