Exemplo n.º 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();
  }
Exemplo n.º 2
0
  private int[] setUpNearest(MouseEvent e) {

    int mousex = e.getX() - _display_offset[0];
    int mousey = e.getY() - _display_offset[1];

    int i = 0;
    int j;

    j = (int) Math.round((mousey - hextop) * 1.0 / intervalUp);

    if ((j % 2 + (rings - 1) % 2) == 0 || (((j - 1) % 2 + (rings) % 2) == 0)) {
      int glob = 1;
      for (i = 0;
          (Math.floor((i + 1) / 2) * radius + Math.floor(i / 2) * radius * 2)
              < mousex - hexleft - radius / 2;
          i++) glob += (((i % 2) == 0) ? 1 : 3);

      double dx =
          (Math.floor((i + 1) / 2) * radius + Math.floor(i / 2) * radius * 2)
              - (mousex - hexleft - radius / 2);

      if ((i % 2) == 1 && dx > radius / 2) {
        i = i - 1;
        glob -= 1;
      } else if ((i % 2) == 0 && dx > radius) {
        i = i - 1;
        glob -= 3;
      }

      i = glob;

    } else {
      int glob = 0;
      for (i = 0;
          (Math.floor((i + 1) / 2) * radius * 2 + Math.floor(i / 2) * radius) < mousex - hexleft;
          i++) glob += (((i % 2) == 0) ? 3 : 1);

      double dx =
          (Math.floor((i + 1) / 2) * radius * 2 + Math.floor(i / 2) * radius) - (mousex - hexleft);

      if ((i % 2) == 0 && dx > radius / 2) {
        i = i - 1;
        glob -= 1;
      } else if ((i % 2) == 1 && dx > radius) {
        i = i - 1;
        glob -= 3;
      }

      i = glob;
    }

    return new int[] {i, j};
  }
Exemplo n.º 3
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();
  }
Exemplo n.º 4
0
 @Override
 public void mousePressed(MouseEvent e) {
   if (_up == null) _mousedown = new int[] {e.getX(), e.getY()};
 }
Exemplo n.º 5
0
 /** MOUSE EVENTS! */
 @Override
 public void mouseClicked(MouseEvent e) {
   callObjectAtLocation(e.getX() - _display_offset[0], e.getY() - _display_offset[1]);
   repaint();
 }