Пример #1
0
  public int compare(MapElement one, MapElement other) {
    int value;
    int otherValue;
    String otherName = other.getName();
    int minlength = otherName.length();
    if (name.length() < minlength) {
      minlength = name.length();
    }

    for (int i = 0; i < minlength; i++) {
      value = Character.getNumericValue(name.charAt(i));
      otherValue = Character.getNumericValue(otherName.charAt(i));

      if (value > otherValue) {
        return otherValue - value;
      } else if (value < otherValue) {
        return value - otherValue;
      }
    }

    /*wenn Präfix gleich aber dieser String kürzer
    steht er lexikographisch weiter vorne*/
    return name.length() - otherName.length();
  }
Пример #2
0
  // action listeners
  public void actionPerformed(ActionEvent e) {

    // doge click button gives doge
    if (e.getSource() == dogeClick) {

      cps = cps + 1;

      Sounds.run("wow");

      // increases size of button temporarily
      if (animation == 0) {
        dogeClick.setBounds(460, 110, 80, 80);
        dogeClick.setIcon(new ImageIcon("Images/dogeopen.jpg"));
        animation = 1;

      } else if (animation == 1) {
        dogeClick.setBounds(450, 100, 100, 100);
        dogeClick.setIcon(new ImageIcon("Images/doge.jpg"));
        animation = 0;
      }

      // adds doge accordingly and updates JLabel
      doge = doge + ((clickUpgrade) * clickMultiply) * multiplier;
      dogeCount.setText("Doge: " + doge);

      // randomize text
      flavourClick.setText(flavourText[(int) (Math.random() * 49)]);
      flavourClick.setBounds(
          (int) (Math.random() * (800)), (int) ((Math.random() * (401)) + 50), getWidth(), 50);
      flavourClick.setFont(
          new Font("Comic Sans MS", Font.BOLD, (int) ((Math.random() * (15)) + 15)));
      Color colour = Random.getRandomColour();
      flavourClick.setForeground(colour);
      flavourClick.setVisible(true);
    }
    // for loop for all buttons
    for (int i = 0; i < MAX_UPGRADES; i++) {

      // updates button stats and count
      if (e.getSource() == producers[i] && doge >= producerStats[i].getCost()) {

        doge = doge - producerStats[i].getCost();
        producers[i].setIcon(new ImageIcon("Images//bought.PNG"));
        producerStats[i].increaseCount();
        producerStats[i].increaseCost();
        producers[i].setToolTipText(
            "Your "
                + producerStats[i].getButtonName()
                + " gives "
                + producerStats[i].getDogeProduction() * producerStats[i].getCount()
                + " doge per second");
        dps = dps + producerStats[i].getDogeProduction();
        buyProducers[i].setText(
            "Buy "
                + producerStats[i].getButtonName()
                + " for "
                + producerStats[i].getCost()
                + " doge");
        buyDetails[i].setText(
            "You have: " + producerStats[i].getCount() + " " + producerStats[i].getButtonName());
      }
    }
    // updates click stats and count
    for (int i = 0; i < MAX_CLICK; i++) {
      if (e.getSource() == clickers[i] && doge >= clickerStats[i].getCost()) {

        doge = doge - clickerStats[i].getCost();
        clickerStats[i].increaseCount();
        clickUpgrade = clickUpgrade + clickerStats[i].getClickBonus();
        clickMultiply = clickMultiply * clickerStats[i].getClickMultiplier();
        dogeClick.setToolTipText(
            "Each click gives you " + (clickUpgrade) * clickMultiply + " doge. wow");

        clickers[i].setVisible(false);
        buyClickers[i].setVisible(false);
      }
    }

    // secret developer button in corner
    if (e.getSource() == devButton) {

      doge = doge * 2;

      // plays Sandstorm by Darude
      Sounds.run("sandstorm");
    }
    if (e.getSource() == options) {

      // opens options gui
      Options options = new Options();
    }
    // saves current progress into save file
    if (e.getSource() == save) {

      // opens JOtionPane
      Sounds.run("save");
      Save temp = new Save();
      String name = JOptionPane.showInputDialog("What is the name of your save file?");
      temp.createOutputFile("Save//" + name + ".txt");

      String producerCount = "";
      String clickCount = "";
      String achievementCount = "";

      // adds line of code for the amount of producers
      for (int i = 0; i < MAX_UPGRADES; i++) {

        producerCount = producerCount + producerStats[i].getCount() + "|";
      }
      // adds line of code for the amount of clickers
      for (int i = 0; i < MAX_CLICK; i++) {

        // if bought write true
        if (clickerStats[i].getCount() != 0) {
          clickCount = clickCount + "t|";
        } else {
          // if not bought write false
          clickCount = clickCount + "f|";
        }
      }

      // adds a line of code for achievements
      for (int i = 0; i < MAX_ACHIEVEMENTS; i++) {

        // if possess write true
        if (achievementStats[i].getCount() != 0) {
          achievementCount = achievementCount + "t|";
        } else {
          // if do not have write f
          achievementCount = achievementCount + "f|";
        }
      }

      // add all lines to file
      temp.addInfo("" + doge);
      temp.addInfo("" + producerCount);
      temp.addInfo("" + clickCount);
      temp.addInfo("" + achievementCount);
      temp.closeOutputFile();
    }
    // opens existing save file
    if (e.getSource() == open) {

      Save temp = new Save();
      String name = JOptionPane.showInputDialog("What is the name of your save file?");
      temp.openInputFile("Save//" + name + ".txt");
      try {

        // counters to open save file
        int add = 0;
        String data = "";
        int producerCount = 0;
        int clickCount = 0;
        int achievementCount = 0;

        // turn each line into char array
        doge = Long.parseLong(temp.getInfo());
        char producerSave[] = temp.getInfo().toCharArray();
        char clickSave[] = temp.getInfo().toCharArray();
        char achievementSave[] = temp.getInfo().toCharArray();

        // looks at producer line and adjusts values and resets Jlabel
        // text
        for (int i = 0; i < producerSave.length; i++) {

          if (producerSave[i] != '|') {

            data = data + Character.getNumericValue(producerSave[i]);

          } else {

            // updates data in producers
            add = Integer.parseInt(data);
            producerStats[producerCount].setCount(add);
            producerStats[producerCount].setCost(
                (int)
                    (producerStats[producerCount].getCost()
                        * (add * producerStats[producerCount].getCostIncrease())));
            buyProducers[producerCount].setText(
                "Buy "
                    + producerStats[producerCount].getButtonName()
                    + " for "
                    + producerStats[producerCount].getCost()
                    + " doge");
            buyDetails[producerCount].setText(
                "You have: "
                    + producerStats[producerCount].getCount()
                    + " "
                    + producerStats[producerCount].getButtonName());
            producers[producerCount].setToolTipText(
                "Your "
                    + producerStats[producerCount].getButtonName()
                    + " gives "
                    + producerStats[producerCount].getDogeProduction()
                        * producerStats[producerCount].getCount()
                    + " doge per second");
            dps =
                dps
                    + (producerStats[producerCount].getDogeProduction()
                        * producerStats[producerCount].getCount());

            data = "";
            producerCount++;
            add = 0;
          }
        }
        // reads clicker upgrades saves
        for (int i = 0; i < MAX_CLICK * 2; i++) {

          if (clickSave[i] == 't') {

            // updates data in clickers
            clickerStats[clickCount].setCount(1);
            clickUpgrade =
                (clickUpgrade + clickerStats[clickCount].getClickBonus())
                    * clickerStats[clickCount].getClickMultiplier();
            dogeClick.setToolTipText("Each click gives you " + clickUpgrade + " doge. wow");

            clickers[clickCount].setVisible(false);
            buyClickers[clickCount].setVisible(false);

            clickCount++;

          } else if (clickSave[i] == 'f') {
            clickCount++;
          }
        }
        // reads achievement lines
        for (int i = 0; i < MAX_ACHIEVEMENTS * 2; i++) {

          if (achievementSave[i] == 't') {

            // updates achievements
            achievementStats[achievementCount].setCount(1);
            achievements[achievementCount].setVisible(true);

            achievementCount++;

          } else if (achievementSave[i] == 'f') {
            achievementCount++;
          }
        }

        dogeCount.setText("Doge: " + doge);
      } catch (IOException e1) {
        // access invalid file
        e1.printStackTrace();
        System.out.println("Invalid file!");
      }

      // closes input file
      try {
        temp.closeInputFile();
      } catch (IOException e1) {
        // access invalid file
        e1.printStackTrace();
        System.out.println("Invalid file!");
      }
    }
  }