@Override
  public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException
  {
    dispatchHotkeys(container, delta);
    
    if (currentState == STATE_DEAD || currentState == STATE_PAUSED) {
      return;
    }
    
    map.update(this, container, delta);
      
    // detect tower selection
    Input in = container.getInput();
    if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
      if (building == null) {
        Iterator<Tower> it = availableTowers.iterator();
        while (it.hasNext()) {
          Tower t = it.next();
          if (t.getRectangle().contains(in.getMouseX(), in.getMouseY())) {
            building = t;
            break;
          }
        }
      } else {
        try {
          // place the tower
          if (in.getMouseX() < WIDTH * SCALE && in.getMouseY() < HEIGHT * SCALE) { // only in the field
            map.addTile(building, new Point(in.getMouseX() / SCALE, in.getMouseY() / SCALE));
            building = null;
          }
        } catch (Exception e) {
          System.out.println("cannot place tower");
        }
      }
    }
  }