Ejemplo n.º 1
0
 private void saveBoardConnections(Board board) {
   for (IGizmo gizmo : board.getGizmos()) {
     for (IBoardItem item : gizmo.getConnectedItems()) {
       fileOutput.format(CONNECT_FORMAT, getName(gizmo), getName(item));
     }
   }
 }
Ejemplo n.º 2
0
  @Override
  public void paint(Graphics2D g, IGizmo gizmo) {
    int orientation = gizmo.getOrientation();
    int x = gizmo.getX(), y = gizmo.getY();

    Flipper flipper = (Flipper) gizmo;

    Path2D.Double path = new Path2D.Double();
    path.moveTo(x, y + 0.25);
    path.lineTo(x, y + 1.75);
    path.curveTo(x, y + 2, x + 0.5, y + 2, x + 0.5, y + 1.75);
    path.lineTo(x + 0.5, y + 0.25);
    path.curveTo(x + 0.5, y, x, y, x, y + 0.25);

    if (flipper.getAngle() != 0)
      path.transform(AffineTransform.getRotateInstance(flipper.getAngle(), x + 0.25, y + 0.25));

    if (orientation != 0)
      path.transform(AffineTransform.getRotateInstance(Math.PI / 2 * orientation, x + 1, y + 1));

    g.setColor(Color.ORANGE);
    g.fill(path);

    g.setColor(Color.ORANGE.darker());
    g.draw(path);
  }
Ejemplo n.º 3
0
  private void saveGizmo(IGizmo gizmo, String type) {
    String name = giveName(gizmo, type);
    fileOutput.format(GIZMO_FORMAT, type, name, gizmo.getX(), gizmo.getY());

    int orientation = gizmo.getOrientation();

    // right flippers are stored as left flippers rotated by one,
    // need to get rid of this before saving
    if (type.equals("RightFlipper")) orientation -= 1;

    for (int i = 0; i < orientation; i++) {
      fileOutput.format(ROTATE_FORMAT, name);
    }
  }
Ejemplo n.º 4
0
  private void saveGizmos(Board board) {
    int x, y;
    for (IGizmo gizmo : board.getGizmos()) {
      switch (gizmo.getType()) {
        case CircleBumper:
          saveGizmo(gizmo, "Circle");
          break;

        case SquareBumper:
          saveGizmo(gizmo, "Square");
          break;

        case TriangleBumper:
          saveGizmo(gizmo, "Triangle");
          break;

        case Flipper:
          Class<? extends IGizmo> cls = gizmo.getClass();
          if (cls.equals(LeftFlipper.class)) {
            saveGizmo(gizmo, "LeftFlipper");
          } else if (cls.equals(RightFlipper.class)) {
            saveGizmo(gizmo, "RightFlipper");
          }
          break;

        case Absorber:
          x = gizmo.getX();
          y = gizmo.getY();
          fileOutput.format(
              ABSORBER_FORMAT,
              giveName(gizmo, "Absorber"),
              x,
              y,
              x + gizmo.getWidth(),
              y + gizmo.getHeight());
          break;

        case AcceleratorGizmo:
          saveGizmo(gizmo, "Accelerator");
          break;

        case GateGizmo:
          saveGizmo(gizmo, "Gate");
          break;

        case SpinnerGizmo:
          saveGizmo(gizmo, "Spinner");
          break;

        case MultiballGizmo:
          saveGizmo(gizmo, "Multiball");
          break;

        case PortalGizmo:
          saveGizmo(gizmo, "Portal");
          break;

        default:
          throw new IllegalStateException(
              String.format("Unknown gizmo type '%s'.", gizmo.getType()));
      }
    }
  }