Beispiel #1
0
  @Override
  public void mouseDragged(MouseEvent e) {

    if (_mousedown != null && _up == null) {
      _display_offset[0] += e.getX() - _mousedown[0];
      _display_offset[1] += e.getY() - _mousedown[1];
      _mousedown = new int[] {e.getX(), e.getY()};
    }
    if (_up != null) {
      if (_up.getType() == BoardObject.type.ROAD) {
        if (((Road) _up).oneDown == false) {
          _up.setX(e.getX());
          _up.setY(e.getY());
        } else {
          ((Road) _up).setX2(e.getX());
          ((Road) _up).setY2(e.getY());
        }
      } else {
        _up.setX(e.getX() - _up.getW() / 2);
        _up.setY(e.getY() - _up.getH() / 2);
      }
    }

    repaint();
  }
Beispiel #2
0
  @Override
  public void mouseReleased(MouseEvent e) {

    if (_up != null) {
      int[] pos = setUpNearest(e);

      if (_up.getType() == BoardObject.type.SETTLEMENT)
        gameLogic.writeBuildSettlement(pos[0], pos[1]);
      else if (_up.getType() == BoardObject.type.CITY) gameLogic.writeBuildCity(pos[0], pos[1]);
      else if ((_up.getType() == BoardObject.type.ROAD) && (((Road) _up).oneDown == true)) {

        gameLogic.writeBuildRoad(((Road) _up).mycoord[0], ((Road) _up).mycoord[1], pos[0], pos[1]);
      }

      if (_up.getType() == BoardObject.type.ROAD) {
        if (((Road) _up).oneDown == false) {

          _up.setX(
              hexleft
                  + ((pos[0] - (pos[0] % 2)) / 2 * intervalSide[0]
                      + (pos[0] - (pos[0] % 2)) / 2 * intervalSide[1]
                      + (pos[0] % 2) * intervalSide[0])
                  + _display_offset[0]);
          _up.setY(hextop + pos[1] * intervalUp + _display_offset[1]);

          ((Road) _up).oneDown = true;
          ((Road) _up).mycoord = pos;

          _mousedown = null;
          e.consume();
        } else {
          ((Road) _up)
              .setX2(
                  hexleft
                      + ((pos[0] - (pos[0] % 2)) / 2 * intervalSide[0]
                          + (pos[0] - (pos[0] % 2)) / 2 * intervalSide[1]
                          + (pos[0] % 2) * intervalSide[0]));
          ((Road) _up).setY2(hextop + pos[1] * intervalUp);
          ((Road) _up).oneDown = true;
          _up = null;
          _mousedown = null;
        }
      } else {
        _up.setX(
            hexleft
                + ((pos[0] - (pos[0] % 2)) / 2 * intervalSide[0]
                    + (pos[0] - (pos[0] % 2)) / 2 * intervalSide[1]
                    + (pos[0] % 2) * intervalSide[0])
                - _up.getW() / 2);
        _up.setY(hextop + pos[1] * intervalUp - _up.getH() / 2);
        _up = null;
        _mousedown = null;
      }
    }
    repaint();
  }