Пример #1
0
  public void checkDrag() {
    Land land = (Land) getWorld();
    if (Greenfoot.mouseDragged(this)) {
      MouseInfo mouse = Greenfoot.getMouseInfo();
      if (cost <= land.getMoneyAmount()) {
        if (hasTurret == false) {
          land.removeObjects(land.getObjects(Radius.class));

          machineGun = new MachineGun_Turret();
          getWorld().addObject(machineGun, mouse.getX(), mouse.getY());
          hasTurret = true;
          land.setMoneyCounter(-cost);
        }
      }
      if (hasTurret == true) machineGun.setLocation(mouse.getX(), mouse.getY());
    }
    if ((Greenfoot.mouseDragEnded(null)) && (machineGun != null)) {
      grid();
      if (machineGun.checkLocation()) {
        machineGun.placed = true;
        hasTurret = false;
        machineGun = null;
      } else {
        land.removeObject(machineGun);
        machineGun = null;
        land.setMoneyCounter(cost);
        hasTurret = false;
      }
    }
  }
Пример #2
0
  public void act() {
    int mouseX, mouseY;

    if (Greenfoot.mouseDragged(this)) {
      MouseInfo mouse = Greenfoot.getMouseInfo();
      mouseX = mouse.getX();
      mouseY = mouse.getY();
      setLocation(mouseX, mouseY);
    }
  }