Esempio n. 1
1
  private void winning() {
    String[] options = {"Try again", "Go back to Start", "Quit"};
    InformationFrame.stopClock();
    int n =
        JOptionPane.showOptionDialog(
            rootPane,
            "You won!"
                + "\n╔══╗░░░░╔╦╗░░╔═════╗"
                + "\n║╚═╬════╬╣╠═╗║░▀░▀░║"
                + "\n╠═╗║╔╗╔╗║║║╩╣║╚═══╝║"
                + "\n╚══╩╝╚╝╚╩╩╩═╝╚═════╝",
            "Smileys  c:  ☺  ☻  ت ヅ  ツ  ッ  シ Ü  ϡ  ﭢ" + "\nWhat would you like to do now?",
            JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            options,
            options[2]);

    if (n == 2) {
      // System.out.println("n = " + n);
      System.exit(0);
    } else if (n == 1) {
      InformationFrame.dispose();
      main(null);
      this.dispose();
    } else if (n == 0) {
      String difficulty = MainManager.getMainGrid().getDifficulty();
      MainPanel.removeAll();
      constructMinesweeper(difficulty.toLowerCase());
    }
  }
Esempio n. 2
0
  /**
   * Losing Function. This method contains everything required to end a game, and also give the user
   * options afterwards.
   */
  private void losing() {
    InformationFrame.stopClock();
    timerStart = false;

    for (int r = 0; r < ButtonGrid.length; r++) {
      for (int c = 0; c < ButtonGrid[1].length; c++) {
        if (MainManager.getMainGrid().getMines(r, c) == 9) {
          ButtonGrid[r][c].setSelected(true);
          // prepare special icons

          ImageIcon MineIcon;
          MineIcon =
              new ImageIcon(
                  "C://Users/Joseph/Downloads/GitHub/"
                      + "Outside/2013/Minesweeper/src/Images/MineImage.png");

          // prepare resize
          Image MineImage = MineIcon.getImage(); // transform it

          int maxSize = Math.max(ButtonGrid[r][c].getHeight(), ButtonGrid[r][c].getWidth()) / 2;

          Image rescaledImage;
          ImageIcon imageIcon;

          rescaledImage =
              MineImage.getScaledInstance(
                  maxSize, maxSize, Image.SCALE_SMOOTH); // scale it the smooth way
          imageIcon = new ImageIcon(rescaledImage); // transform it back

          JLabel test1 = new JLabel(imageIcon);

          ButtonGrid[r][c].add(test1);
          // ButtonGrid[r][c].repaint();
          resetFont("", r, c);
        }
      }
    }

    /*
    JOptionPane.showMessageDialog(rootPane, "You lose. Sorry."
            + "\n╔╦╦╦╦╦╦╦╦╦╦╦╦╗"
            + "\n╠╬╬╬╬╬╬╬╬╬╬╬╬╣"
            + "\n╠╬╬╬╬╬╬╬╬╬╬╬╬╣"
            + "\n╠╬╬█╬╬╬╬╬╬█╬╬╣"
            + "\n╠╬╬╬╬╬╬╬╬╬╬╬╬╣"
            + "\n╠╬╬╬╬╬╬╬╬╬╬╬╬╣"
            + "\n╠╬╬╬╬╬╬╬╬╬╬╬╬╣"
            + "\n╠╬██████████╬╣"
            + "\n╠╬█╬╬╬╬╬╬╬╬█╬╣"
            + "\n╚╩╩╩╩╩╩╩╩╩╩╩╩╝", "☹", JOptionPane.YES_NO_CANCEL_OPTION);
            * */
    // Custom button text
    String[] options = {"Try again", "Go back to Start", "Quit"};
    int n =
        JOptionPane.showOptionDialog(
            rootPane,
            "You lose. Sorry."
                + "\n╔╦╦╦╦╦╦╦╦╦╦╦╦╗"
                + "\n╠╬╬╬╬╬╬╬╬╬╬╬╬╣"
                + "\n╠╬╬╬╬╬╬╬╬╬╬╬╬╣"
                + "\n╠╬╬█╬╬╬╬╬╬█╬╬╣"
                + "\n╠╬╬╬╬╬╬█╬╬╬╬╬╣"
                + "\n╠╬╬╬╬╬╬╬╬╬╬╬╬╣"
                + "\n╠╬╬╬╬╬╬╬╬╬╬╬╬╣"
                + "\n╠╬██████████╬╣"
                + "\n╠╬█╬╬╬╬╬╬╬╬█╬╣"
                + "\n╚╩╩╩╩╩╩╩╩╩╩╩╩╝"
                + "\n What would you like to do?",
            "☹",
            JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            options,
            options[2]);

    if (n == 2) {
      // System.out.println("n = " + n);
      System.exit(0);
    } else if (n == 1) {
      InformationFrame.dispose();
      main(null);
      this.dispose();
    } else if (n == 0) {
      String difficulty = MainManager.getMainGrid().getDifficulty();
      MainPanel.removeAll();
      constructMinesweeper(difficulty.toLowerCase());
    }

    for (int y = 0; y < ButtonGrid.length; y++) {
      for (int x = 0; x < ButtonGrid[1].length; x++) {
        ButtonGrid[y][x].setFocusable(false);
      }
    }

    System.out.println("You lose");
  }