Skip to content

Commit

Permalink
new version 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisTurco authored Nov 9, 2022
1 parent 04deaa8 commit 9d99469
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 88 deletions.
Binary file added Minesweeper 1.0.2 setup file.exe
Binary file not shown.
Binary file modified Minesweeper.exe
Binary file not shown.
Binary file modified bin/game/FrameMinesweeper$Screen.class
Binary file not shown.
Binary file modified bin/game/FrameMinesweeper.class
Binary file not shown.
Binary file modified bin/game/ImageLoader_Minesweeper.class
Binary file not shown.
Binary file modified bin/game/MainMinesweeper.class
Binary file not shown.
Binary file modified bin/game/WorldMinesweeper.class
Binary file not shown.
Binary file modified config_files/installer setup.ifp
Binary file not shown.
38 changes: 14 additions & 24 deletions src/game/FrameMinesweeper.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.awt.Toolkit;
import java.awt.Point;

import javax.naming.InitialContext;
import javax.swing.*;


Expand All @@ -38,8 +37,6 @@ class FrameMinesweeper extends JFrame implements MouseListener, WindowListener,
private static JButton time_number;
private JCheckBoxMenuItem sounds;

private String current_difficult;

private int insetLeft;
private int insetTop;

Expand Down Expand Up @@ -234,11 +231,6 @@ public boolean isSoundEffectActive() {
return sounds.isSelected();
}

public String getDifficultyMode() {
return current_difficult;
}


// SETTER
public void setFlagsNumber(int value) {
flags_number.setText("Flags = " + value);
Expand All @@ -252,19 +244,20 @@ public static void setTimer(float value) {
time_number.setText("Time = " + value);
}

public void setDifficultyMode(String difficulty) {
current_difficult = difficulty;
}

// MOUSE
@Override
public void mousePressed(MouseEvent e) {}

@Override
public void mouseReleased(MouseEvent e) {
if(e.getButton() == 1) WorldMinesweeper.left_click(e.getX() - insetLeft, e.getY() - insetTop - menu_bar.getHeight() - tool_bar.getHeight());
if(e.getButton() == 3) WorldMinesweeper.right_click(e.getX() - insetLeft, e.getY() - insetTop - menu_bar.getHeight() - tool_bar.getHeight());
screen.repaint();
try {
if(e.getButton() == 1) WorldMinesweeper.left_click(e.getX() - insetLeft, e.getY() - insetTop - menu_bar.getHeight() - tool_bar.getHeight());
if(e.getButton() == 3) WorldMinesweeper.right_click(e.getX() - insetLeft, e.getY() - insetTop - menu_bar.getHeight() - tool_bar.getHeight());
screen.repaint();
} catch (ArrayIndexOutOfBoundsException ex) {
System.err.println("Exception --> " + ex);
}

}

@Override
Expand Down Expand Up @@ -308,18 +301,18 @@ public void actionPerformed(ActionEvent e) {
else if (command.equals("Easy")) {
width = 440;
height = 440;
new WorldMinesweeper(11, 11);
new WorldMinesweeper(WorldMinesweeper.DIFFICULTY[0]);
}

else if (command.equals("Normal")) {
width = 600;
height = 600;
new WorldMinesweeper(15, 15);
new WorldMinesweeper(WorldMinesweeper.DIFFICULTY[1]);
}
else if (command.equals("Hard")) {
width = 840;
height = 840;
new WorldMinesweeper(21, 21);
new WorldMinesweeper(WorldMinesweeper.DIFFICULTY[2]);
}
else if (command.equals("Remove All Flags")) {
WorldMinesweeper.removeAllFlags();
Expand Down Expand Up @@ -354,24 +347,21 @@ else if (command.equals("Credits")) {
}
else if (command.equals("Scoreboard Easy Mode")) {
try {
current_difficult = "difficultEasy";
WorldMinesweeper.OpenScoreboard(null, current_difficult);
WorldMinesweeper.OpenScoreboard(null, WorldMinesweeper.DIFFICULTY[0]);
} catch (Exception e1) {
e1.printStackTrace();
}
}
else if (command.equals("Scoreboard Normal Mode")) {
try {
current_difficult = "difficultNormal";
WorldMinesweeper.OpenScoreboard(null, current_difficult);
WorldMinesweeper.OpenScoreboard(null, WorldMinesweeper.DIFFICULTY[1]);
} catch (Exception e1) {
e1.printStackTrace();
}
}
else if (command.equals("Scoreboard Hard Mode")) {
try {
current_difficult = "difficultHard";
WorldMinesweeper.OpenScoreboard(null, current_difficult);
WorldMinesweeper.OpenScoreboard(null, WorldMinesweeper.DIFFICULTY[2]);
} catch (Exception e1) {
e1.printStackTrace();
}
Expand Down
1 change: 0 additions & 1 deletion src/game/ImageLoader_Minesweeper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import javax.imageio.ImageIO;

Expand Down
4 changes: 1 addition & 3 deletions src/game/MainMinesweeper.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package game;

class MainMinesweeper {

public static void main(String[] args) {
new WorldMinesweeper();
new WorldMinesweeper(WorldMinesweeper.DIFFICULTY[1]); // per default imposto la difficolta' a normal
}

}
126 changes: 66 additions & 60 deletions src/game/WorldMinesweeper.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,76 +27,68 @@
import java.awt.Rectangle;

class WorldMinesweeper {
private static int COLS = 15;
private static int ROWS = 15;
private static int N_BOMBS = COLS*ROWS*16/100; // la quantità di bombe è data circa dal 16% del numero totale di caselle (COLS*ROWS)
private static int N_FLAGS = N_BOMBS;
private static int COLS;
private static int ROWS;
private static int N_BOMBS;
private static int N_FLAGS;
private static boolean dead;
private static boolean finish;
private static boolean started;
private static TileMinesweeper[][] matrix;
private static TimerMinesweeper timer = new TimerMinesweeper();
private static String[] list;

public static String []DIFFICULTY = {"difficultyEasy", "difficultyNormal", "difficultyHard"};
private static String current_difficulty;

private static FrameMinesweeper frame;

// scalo le immagini in base alla dimensione dello schermo
private BufferedImage bomb_img = ImageLoader_Minesweeper.scale(ImageLoader_Minesweeper.loadImage("res/bomb_face.png"), TileMinesweeper.getWidth(), TileMinesweeper.getHeight());
private BufferedImage bomb_no_face_img = ImageLoader_Minesweeper.scale(ImageLoader_Minesweeper.loadImage("res/bomb.png"), TileMinesweeper.getWidth(), TileMinesweeper.getHeight());
private BufferedImage flag_img = ImageLoader_Minesweeper.scale(ImageLoader_Minesweeper.loadImage("res/flag.png"), TileMinesweeper.getWidth(), TileMinesweeper.getHeight());
private BufferedImage pressed_img = ImageLoader_Minesweeper.scale(ImageLoader_Minesweeper.loadImage("res/tile_brown_normal.png"), TileMinesweeper.getWidth(), TileMinesweeper.getHeight());
private BufferedImage pressed2_img = ImageLoader_Minesweeper.scale(ImageLoader_Minesweeper.loadImage("res/tile_brown2_normal.png"), TileMinesweeper.getWidth(), TileMinesweeper.getHeight());
private BufferedImage normal_img = ImageLoader_Minesweeper.scale(ImageLoader_Minesweeper.loadImage("res/tile_green_normal.png"), TileMinesweeper.getWidth(), TileMinesweeper.getHeight());
private BufferedImage normal2_img = ImageLoader_Minesweeper.scale(ImageLoader_Minesweeper.loadImage("res/tile_green2_normal.png"), TileMinesweeper.getWidth(), TileMinesweeper.getHeight());
private BufferedImage error_img = ImageLoader_Minesweeper.scale(ImageLoader_Minesweeper.loadImage("res/error.png"), TileMinesweeper.getWidth(), TileMinesweeper.getHeight());
private BufferedImage bomb_img;
private BufferedImage bomb_no_face_img;
private BufferedImage flag_img;
private BufferedImage pressed_img;
private BufferedImage pressed2_img;
private BufferedImage normal_img;
private BufferedImage normal2_img;
private BufferedImage error_img;

//TODO: aggiungere la texture di un fiore da inserire quando si vince
//TODO: aggiungere delay tra le immagini
//TODO: aggiungere hover sulle caselle selezionate

//CONSTRUCTOR
public WorldMinesweeper() {

matrix = new TileMinesweeper[ROWS][COLS];

frame = new FrameMinesweeper();
public WorldMinesweeper(String difficulty) {

frame.setDifficultyMode("difficultyNormal");

// costruisco ogni cella
boolean tile_switch = false;
for (int i=0; i<ROWS; i++) {
for (int j=0; j<COLS; j++) {
if (tile_switch == false) {
matrix[i][j] = new TileMinesweeper(i, j, normal_img, bomb_no_face_img, bomb_img, pressed_img, flag_img, error_img);
tile_switch = true;
}
else {
matrix[i][j] = new TileMinesweeper(i, j, normal2_img, bomb_no_face_img, bomb_img, pressed2_img, flag_img, error_img);
tile_switch = false;
}

}

// imposto la difficoltà corrente
if (difficulty.equals(DIFFICULTY[0])) {
current_difficulty = DIFFICULTY[0];
COLS = 11;
ROWS = 11;
}

reset(); //resetto il mondo e creo una nuova partita

}

public WorldMinesweeper(int cols, int rows) {
COLS = cols;
ROWS = rows;
if (difficulty.equals(DIFFICULTY[1])) {
current_difficulty = DIFFICULTY[1];
COLS = 15;
ROWS = 15;
}
if (difficulty.equals(DIFFICULTY[2])) {
current_difficulty = DIFFICULTY[2];
COLS = 21;
ROWS = 21;
}
N_BOMBS = COLS*ROWS*16/100; // la quantità di bombe è data circa dal 16% del numero totale di caselle (COLS*ROWS)
N_FLAGS = N_BOMBS;

scaleImages();

matrix = new TileMinesweeper[ROWS][COLS];

// distruggo il vecchio frame
frame.setVisible(false);
frame.dispose(); //Destroy the JFrame object
if (frame != null) {
frame.setVisible(false);
frame.dispose(); //Destroy the JFrame object
}

// creo il nuovo frame
frame = new FrameMinesweeper();

// costruisco ogni cella
Expand All @@ -117,7 +109,17 @@ public WorldMinesweeper(int cols, int rows) {
}

reset(); //resetto il mondo e creo una nuova partita

}

private void scaleImages() {
bomb_img = ImageLoader_Minesweeper.scale(ImageLoader_Minesweeper.loadImage("res/bomb_face.png"), TileMinesweeper.getWidth(), TileMinesweeper.getHeight());
bomb_no_face_img = ImageLoader_Minesweeper.scale(ImageLoader_Minesweeper.loadImage("res/bomb.png"), TileMinesweeper.getWidth(), TileMinesweeper.getHeight());
flag_img = ImageLoader_Minesweeper.scale(ImageLoader_Minesweeper.loadImage("res/flag.png"), TileMinesweeper.getWidth(), TileMinesweeper.getHeight());
pressed_img = ImageLoader_Minesweeper.scale(ImageLoader_Minesweeper.loadImage("res/tile_brown_normal.png"), TileMinesweeper.getWidth(), TileMinesweeper.getHeight());
pressed2_img = ImageLoader_Minesweeper.scale(ImageLoader_Minesweeper.loadImage("res/tile_brown2_normal.png"), TileMinesweeper.getWidth(), TileMinesweeper.getHeight());
normal_img = ImageLoader_Minesweeper.scale(ImageLoader_Minesweeper.loadImage("res/tile_green_normal.png"), TileMinesweeper.getWidth(), TileMinesweeper.getHeight());
normal2_img = ImageLoader_Minesweeper.scale(ImageLoader_Minesweeper.loadImage("res/tile_green2_normal.png"), TileMinesweeper.getWidth(), TileMinesweeper.getHeight());
error_img = ImageLoader_Minesweeper.scale(ImageLoader_Minesweeper.loadImage("res/error.png"), TileMinesweeper.getWidth(), TileMinesweeper.getHeight());
}

private static void place_all_bombs() {
Expand Down Expand Up @@ -199,6 +201,7 @@ else if (matrix[x_axis][y_axis].isBomb()) {
openSound(".//res//buttonEffect.wav");
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
e.printStackTrace();
System.err.println("Exception --> " + e);
}
}
else if (matrix[x_axis][y_axis].getAmountOfNearBombs() == 0 && matrix[x_axis][y_axis].isBomb() == false) open(x_axis, y_axis);
Expand All @@ -214,6 +217,7 @@ else if (matrix[x_axis][y_axis].isBomb()) {
openSound(".//res//"+choose[index]);
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
e.printStackTrace();
System.err.println("Exception --> " + e);
}
}

Expand All @@ -227,10 +231,11 @@ else if (matrix[x_axis][y_axis].isBomb()) {
if (dead == false && finish == true) {
try {
String result = JOptionPane.showInputDialog(null, "Enter your name:", "Congratulations!! Seconds Passed = " + timer.getTimer(), JOptionPane.INFORMATION_MESSAGE); //messaggio popup
if (result.length() > 0) newScoreScoreboard(result, frame.getDifficultyMode()); // passo il nome del vincitore nella scoreboard
OpenScoreboard(result, frame.getDifficultyMode());
if (result.length() > 0) newScoreScoreboard(result); // passo il nome del vincitore nella scoreboard
OpenScoreboard(result, current_difficulty);
} catch (Exception e) {
e.printStackTrace();
System.err.println("Exception --> " + e);
}

}
Expand All @@ -257,6 +262,7 @@ public static void right_click(int x, int y) {
openSound(".//res//sound_effect_flag.wav");
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
e.printStackTrace();
System.err.println("Exception --> " + e);
}
}

Expand Down Expand Up @@ -301,8 +307,8 @@ private void winLayout() {
try {
TimeUnit.MILLISECONDS.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.err.println("Exception --> " + e);
}

// inserisco i fiori
Expand All @@ -313,8 +319,8 @@ private void winLayout() {
TimeUnit.MILLISECONDS.sleep(100);
matrix[i][j].placeFlower();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.err.println("Exception --> " + e);
}
}
}
Expand Down Expand Up @@ -399,8 +405,8 @@ public static void OpenCredits() {


// ######################## Scoreboard ########################
public static void OpenScoreboard(String player_name, String difficulty_mode) throws Exception {
getScoreboard(difficulty_mode);
public static void OpenScoreboard(String player_name, String difficulty) throws Exception {
getScoreboard(difficulty);


// utilizzo le JLabel anzichè semplici String perchè voglio colorare la stringa appena aggiunta
Expand Down Expand Up @@ -432,28 +438,28 @@ public static void OpenScoreboard(String player_name, String difficulty_mode) th

}

private static void newScoreScoreboard(String name, String difficulty_mode) throws IOException {
BufferedWriter bw = new BufferedWriter(new FileWriter(".//res//scoreboard" + "_" + difficulty_mode, true)); //true = append
private static void newScoreScoreboard(String name) throws IOException {
BufferedWriter bw = new BufferedWriter(new FileWriter(".//res//scoreboard" + "_" + current_difficulty, true)); //true = append
bw.write("" + name + " --> Seconds: " + timer.getTimer() + "\n");
bw.close();
getScoreboard(difficulty_mode); //ottengo la scoreboard
getScoreboard(current_difficulty); //ottengo la scoreboard
}

private static void getScoreboard(String difficulty_mode) {
private static void getScoreboard(String difficulty) {
int DIM_MAX = 11;
list = new String[DIM_MAX]; //la classifica è una top 10

//leggo le righe
try {
BufferedReader br = new BufferedReader(new FileReader(".//res//scoreboard" + "_" + difficulty_mode));
BufferedReader br = new BufferedReader(new FileReader(".//res//scoreboard" + "_" + difficulty));

for (int i=0; i<DIM_MAX; i++) {
if ((list[i] = br.readLine()) != null);
}

br.close();
} catch (IOException e) {
e.printStackTrace();
System.err.println("Exception --> " + e);
}

//ordino
Expand All @@ -462,13 +468,13 @@ private static void getScoreboard(String difficulty_mode) {
// scrivo i nuovi valori ordinati
BufferedWriter bw;
try {
bw = new BufferedWriter(new FileWriter(".//res//scoreboard" + "_" + difficulty_mode, false)); //false = append
bw = new BufferedWriter(new FileWriter(".//res//scoreboard" + "_" + difficulty, false)); //false = append
for (int i=0; i<DIM_MAX-1; i++) {
if (list[i] != null) bw.write("" + list[i] + "\n");
}
bw.close();
} catch (IOException e) {
e.printStackTrace();
System.err.println("Exception --> " + e);
}

}
Expand Down

0 comments on commit 9d99469

Please sign in to comment.