Package gui.commands

Source Code of gui.commands.MoveByOne

package gui.commands;

import gui.MainWindow;

import java.awt.event.KeyEvent;

import preseci_krugova.Krug;
import preseci_krugova.Tacka;

public class MoveByOne implements Command {

  private Krug circleToMove;
  private int direction;
 
  public MoveByOne(Krug circleToMove, int direction) {
    this.circleToMove = circleToMove;
    this.direction = direction;
  }

  @Override
  public void execute() {
    switch (direction) {
    case KeyEvent.VK_LEFT:
      circleToMove.setCentar(new Tacka(circleToMove.getCentar().getX()-1, circleToMove.getCentar().getY()));
      break;
    case KeyEvent.VK_RIGHT:
      circleToMove.setCentar(new Tacka(circleToMove.getCentar().getX()+1, circleToMove.getCentar().getY()));
      break;
    case KeyEvent.VK_UP:
      circleToMove.setCentar(new Tacka(circleToMove.getCentar().getX(), circleToMove.getCentar().getY()+1));
      break;
    case KeyEvent.VK_DOWN:
      circleToMove.setCentar(new Tacka(circleToMove.getCentar().getX(), circleToMove.getCentar().getY()-1));
      break;
    }
   
    MainWindow.getInstance().drawImage();
  }

  @Override
  public void undo() {
    switch (direction) {
    case KeyEvent.VK_LEFT:
      circleToMove.setCentar(new Tacka(circleToMove.getCentar().getX()+1, circleToMove.getCentar().getY()));
      break;
    case KeyEvent.VK_RIGHT:
      circleToMove.setCentar(new Tacka(circleToMove.getCentar().getX()-1, circleToMove.getCentar().getY()));
      break;
    case KeyEvent.VK_UP:
      circleToMove.setCentar(new Tacka(circleToMove.getCentar().getX(), circleToMove.getCentar().getY()-1));
      break;
    case KeyEvent.VK_DOWN:
      circleToMove.setCentar(new Tacka(circleToMove.getCentar().getX(), circleToMove.getCentar().getY()+1));
      break;
    }
   
    MainWindow.getInstance().drawImage();
  }

}
TOP

Related Classes of gui.commands.MoveByOne

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.