@Override
  public void onPaint(Graphics2D graphics2D) {
    this.runtimeMillis = System.currentTimeMillis() - this.startTimeMillis;
    graphics2D.setColor(new Color(0, 0, 100, 120));
    graphics2D.fillRect(25, 240, 350, 82);

    graphics2D.setColor(Color.GREEN);
    graphics2D.fillRect(25, 240, 3 * this.expTracker.getPercentageToNextLevel(Skill.HERBLORE), 9);

    graphics2D.setColor(Color.WHITE);
    graphics2D.drawRect(25, 240, 350, 9);
    graphics2D.drawRect(25, 240, 350, 82);

    int cleanedPerHour =
        (int)
            (3600000.0
                / (double) (System.currentTimeMillis() - this.startTimeMillis)
                * (double) this.herbsCleaned);
    String profitsPerHour =
        String.valueOf(cleanedPerHour * this.profitPerClean)
            .replaceAll("(\\d)(?=(\\d{3})+$)", "$1,");

    graphics2D.setFont(new Font("Monospaced", 0, 12));
    graphics2D.drawString(
        "Herbs cleaned: " + this.herbsCleaned + " | (" + cleanedPerHour + ")", 28, 260);
    graphics2D.drawString("Current State: " + this.textualState, 28, 270);
    graphics2D.drawString("Time running: " + Core.formatElapsedTime(this.runtimeMillis), 28, 280);
    graphics2D.drawString(
        "XP Gained: "
            + this.expTracker.getExperienceGained(Skill.HERBLORE)
            + (" | (" + this.expTracker.getLevelsGained(Skill.HERBLORE) + ")"),
        28,
        290);
    graphics2D.drawString(
        "XP/hr: "
            + this.expTracker.gainedPerHour(Skill.HERBLORE)
            + " | Profit/hr: "
            + profitsPerHour,
        28,
        300);
    graphics2D.drawString(
        "Time till next level: "
            + Core.formatElapsedTime(this.expTracker.timeUntilNextLevel(Skill.HERBLORE)),
        28,
        310);

    graphics2D.drawLine(
        (int) this.getMouse().getPosition().getX(),
        (int) this.getMouse().getPosition().getY() + 10,
        (int) this.getMouse().getPosition().getX(),
        (int) this.getMouse().getPosition().getY() - 10);
    graphics2D.drawLine(
        (int) this.getMouse().getPosition().getX() + 10,
        (int) this.getMouse().getPosition().getY(),
        (int) this.getMouse().getPosition().getX() - 10,
        (int) this.getMouse().getPosition().getY());

    graphics2D.setColor(Color.RED);
    graphics2D.drawString("by Chicken Wing      v1.0", 70, 320);
  }
Exemple #2
0
  @Override
  protected void execute(Core core, ActionEvent event, Object[] dependencies) {
    // Récupération du modèle
    category = core.createCategory();
    // Vue
    view = new JCreateCategory(category);
    view.setTitle(Text.APP_TITLE.toString() + " - " + Text.SUBCATEGORY_CREATION_TITLE.toString());
    Positions.setPositionOnScreen(view, ScreenPosition.CENTER);

    initListeners(core);

    category.addObserver(view);

    // ATTENTION : le réglage de la modalité doit être fait après la
    // paramétrisation de la fenêtre !
    view.setModalityType(ModalityType.APPLICATION_MODAL);
    view.setVisible(true);
  }
  @Override
  public int onLoop() throws InterruptedException {
    State state = null;
    for (State cur : this.states) {
      if (cur.shouldExecute()) {
        state = cur;
        break;
      }
    }

    if (state == null) {
      return 100;
    }

    this.textualState = state.getTextualState();
    state.onLoop();
    return Core.random(200, 400);
  }
  public static void main(String[] args) throws IOException {
    try {
      Core.init();

      new Thread() {
        @Override
        public void run() {
          try {
            Player p = new Player(null);

            // Choose level
            int level =
                Query.ask(p, new IntegerQuery("Choose your character's level", "Level", 1, 20))
                    .response;

            // Choose race
            String chosenRace =
                Query.ask(
                        p,
                        new SelectQuery(
                            "Choose your character's race", Selectable.load("races.txt")))
                    .response
                    .getName();
            p.rac.setRace(chosenRace);

            // Choose class
            String chosenClass =
                Query.ask(
                        p,
                        new SelectQuery(
                            "Choose your character's class", Selectable.load("classes.txt")))
                    .response
                    .getName();
            p.clc.addLevel(chosenClass);

            // Choose alignment
            p.cdc.alignment =
                Query.ask(
                        p,
                        new SelectQuery(
                            "Choose your character's alignment", Selectable.load("alignments.txt")))
                    .response
                    .getName();

            // Choose background
            String chosenBack =
                Query.ask(
                        p,
                        new SelectQuery(
                            "Choose your character's background",
                            Selectable.load("backgrounds.txt")))
                    .response
                    .getName();
            p.bc.setBackground(chosenBack);

            // Point buy
            p.asc.setAll(
                Query.ask(
                        p,
                        new PointBuyQuery(27, p.asc.getAll(), new int[] {20, 20, 20, 20, 20, 20}))
                    .response);

            p.clc.classes.get(0).levelTo(level);

            Log.print(p.characterSheet());

            SerializationUtils.save("chars/bob.ser", p);

            System.exit(0);
          } catch (Exception ex) {
            Log.error(ex);
            ex.printStackTrace();
          }
        }
      }.start();

      Core.run();
    } catch (Exception ex) {
      ex.printStackTrace();
    } finally {
      Core.destroy();
    }
    System.exit(0);
  }