very major improvements
This commit is contained in:
parent
3068c5ba94
commit
9afffd4297
8 changed files with 112 additions and 16 deletions
BIN
images/crossLaser.png
Normal file
BIN
images/crossLaser.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 298 B |
BIN
images/miror1.png
Normal file
BIN
images/miror1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 494 B |
BIN
images/miror2.png
Normal file
BIN
images/miror2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 520 B |
BIN
images/miror3.png
Normal file
BIN
images/miror3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 502 B |
BIN
images/miror4.png
Normal file
BIN
images/miror4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 517 B |
|
@ -79,6 +79,14 @@ public class Universe {
|
|||
break;
|
||||
|
||||
case 5:
|
||||
System.out.printf(" /");
|
||||
break;
|
||||
|
||||
case 6:
|
||||
System.out.printf(" \\");
|
||||
break;
|
||||
|
||||
case 7:
|
||||
System.out.printf(" \\");
|
||||
break;
|
||||
|
||||
|
@ -295,16 +303,26 @@ public class Universe {
|
|||
this.grid[i][j] = 3;
|
||||
}
|
||||
}
|
||||
if ((c == 3 && d == 10) || (c == 3 && d == 11) || (c == 2 && d == 12) || (c == 2 && d == 13)) {
|
||||
if ((c == 3 && d == 10) || (c == 2 && d == 13)) {
|
||||
this.grid[i][j] = 4;
|
||||
this.filled_boxes ++;
|
||||
this.nb_mirors ++;
|
||||
}
|
||||
if ((c == 2 && d == 10) || (c == 2 && d == 11) || (c == 3 && d == 12) || (c == 3 && d == 13)) {
|
||||
if ((c == 2 && d == 12) || (c == 3 && d == 11)) {
|
||||
this.grid[i][j] = 5;
|
||||
this.filled_boxes ++;
|
||||
this.nb_mirors ++;
|
||||
}
|
||||
if ((c == 2 && d == 10) || (c == 3 && d == 12)) {
|
||||
this.grid[i][j] = 6;
|
||||
this.filled_boxes ++;
|
||||
this.nb_mirors ++;
|
||||
}
|
||||
if ((c == 2 && d == 11) || (c == 3 && d == 13)) {
|
||||
this.grid[i][j] = 7;
|
||||
this.filled_boxes ++;
|
||||
this.nb_mirors ++;
|
||||
}
|
||||
|
||||
// changing the position of the situation
|
||||
|
||||
|
@ -340,7 +358,7 @@ public class Universe {
|
|||
this.grid[i][j] = 1;
|
||||
}
|
||||
} else {
|
||||
if (this.grid[i][j] == 4 || this.grid[i][j] == 5) {this.nb_mirors--;}
|
||||
if (this.grid[i][j] == 4 || this.grid[i][j] == 5 || this.grid[i][j] == 6 || this.grid[i][j] == 7) {this.nb_mirors--;}
|
||||
this.filled_boxes--;
|
||||
this.grid[i][j] = 0;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ public class Grid extends JPanel {
|
|||
private JButton[][] mat;
|
||||
private int selected;
|
||||
private Universe universe;
|
||||
private int button_width, button_height;
|
||||
|
||||
public Grid(int width, int height, Universe universe) {
|
||||
super(new GridLayout(height, width));
|
||||
|
@ -39,6 +40,8 @@ public class Grid extends JPanel {
|
|||
this.height = height;
|
||||
this.selected = 0;
|
||||
this.universe = universe;
|
||||
this.button_width = 600 / this.height;
|
||||
this.button_height = button_width;
|
||||
|
||||
this.mat = new JButton[height][width];
|
||||
|
||||
|
@ -46,7 +49,7 @@ public class Grid extends JPanel {
|
|||
for (int j = 0; j < this.width; j++) {
|
||||
this.mat[i][j] = new JButton();
|
||||
|
||||
this.mat[i][j].setPreferredSize(new Dimension(Math.max(50, 600 / this.height), Math.max(50, (this.width * 600 / this.height) / this.width)));
|
||||
this.mat[i][j].setPreferredSize(new Dimension(this.button_width, this.button_height));
|
||||
|
||||
final int coord_i = i;
|
||||
final int coord_j = j;
|
||||
|
@ -118,7 +121,7 @@ public class Grid extends JPanel {
|
|||
Image photo;
|
||||
switch (this.universe.getGrid()[i + 1][j + 1]) {
|
||||
case -1:
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/wall.png")).getImage();
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/wall.png")).getImage().getScaledInstance(this.button_width, this.button_height, Image.SCALE_SMOOTH);
|
||||
this.mat[i][j].setIcon(new ImageIcon(photo));
|
||||
break;
|
||||
case 0:
|
||||
|
@ -126,39 +129,47 @@ public class Grid extends JPanel {
|
|||
this.mat[i][j].setIcon(null);
|
||||
break;
|
||||
case 1:
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/verticalLaser.png")).getImage();
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/verticalLaser.png")).getImage().getScaledInstance(this.button_width, this.button_height, Image.SCALE_SMOOTH);
|
||||
this.mat[i][j].setIcon(new ImageIcon(photo));
|
||||
break;
|
||||
case 2:
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/horizontalLaser.png")).getImage();
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/horizontalLaser.png")).getImage().getScaledInstance(this.button_width, this.button_height, Image.SCALE_SMOOTH);
|
||||
this.mat[i][j].setIcon(new ImageIcon(photo));
|
||||
break;
|
||||
case 3:
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/wall.png")).getImage();
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/crossLaser.png")).getImage().getScaledInstance(this.button_width, this.button_height, Image.SCALE_SMOOTH);
|
||||
this.mat[i][j].setIcon(new ImageIcon(photo));
|
||||
break;
|
||||
case 4:
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/wall.png")).getImage();
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/miror1.png")).getImage().getScaledInstance(this.button_width, this.button_height, Image.SCALE_SMOOTH);
|
||||
this.mat[i][j].setIcon(new ImageIcon(photo));
|
||||
break;
|
||||
case 5:
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/wall.png")).getImage();
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/miror2.png")).getImage().getScaledInstance(this.button_width, this.button_height, Image.SCALE_SMOOTH);
|
||||
this.mat[i][j].setIcon(new ImageIcon(photo));
|
||||
break;
|
||||
case 6:
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/miror3.png")).getImage().getScaledInstance(this.button_width, this.button_height, Image.SCALE_SMOOTH);
|
||||
this.mat[i][j].setIcon(new ImageIcon(photo));
|
||||
break;
|
||||
case 7:
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/miror4.png")).getImage().getScaledInstance(this.button_width, this.button_height, Image.SCALE_SMOOTH);
|
||||
this.mat[i][j].setIcon(new ImageIcon(photo));
|
||||
break;
|
||||
case 10:
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/startUp.png")).getImage();
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/startUp.png")).getImage().getScaledInstance(this.button_width, this.button_height, Image.SCALE_SMOOTH);
|
||||
this.mat[i][j].setIcon(new ImageIcon(photo));
|
||||
break;
|
||||
case 11:
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/startBot.png")).getImage();
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/startBot.png")).getImage().getScaledInstance(this.button_width, this.button_height, Image.SCALE_SMOOTH);
|
||||
this.mat[i][j].setIcon(new ImageIcon(photo));
|
||||
break;
|
||||
case 12:
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/startRight.png")).getImage();
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/startRight.png")).getImage().getScaledInstance(this.button_width, this.button_height, Image.SCALE_SMOOTH);
|
||||
this.mat[i][j].setIcon(new ImageIcon(photo));
|
||||
break;
|
||||
case 13:
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/startLeft.png")).getImage();
|
||||
photo = new ImageIcon(this.getClass().getResource("../images/startLeft.png")).getImage().getScaledInstance(this.button_width, this.button_height, Image.SCALE_SMOOTH);
|
||||
this.mat[i][j].setIcon(new ImageIcon(photo));
|
||||
break;
|
||||
}
|
||||
|
@ -207,6 +218,8 @@ public class Grid extends JPanel {
|
|||
best_filled_boxes = universe.getFilledBoxes();
|
||||
best_nb_mirrors = universe.getNbMirrors();
|
||||
|
||||
System.out.println(best_filled_boxes + " " + best_nb_mirrors);
|
||||
|
||||
printUniverse();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,13 @@ import java.awt.GridBagConstraints;
|
|||
import java.awt.GridLayout;
|
||||
import java.awt.Insets;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.*;
|
||||
|
@ -91,6 +98,65 @@ public class Window extends JFrame {
|
|||
menuBar.add(aideMenu);
|
||||
menuBar.add(toolsMenu);
|
||||
|
||||
nouveauItem.addActionListener(e -> {
|
||||
this.universe.changeUniverseDim(5, 5);
|
||||
this.universe.changeUniverseStart(1, 1, 11);
|
||||
this.panel.remove(this.grid);
|
||||
this.grid = new Grid(3, 3, this.universe);
|
||||
this.panel.add(this.grid);
|
||||
super.pack();
|
||||
super.repaint();
|
||||
});
|
||||
|
||||
enregistrerItem.addActionListener(e -> {
|
||||
String name = JOptionPane.showInputDialog("Choose the universe name");
|
||||
this.universe.save(name);
|
||||
});
|
||||
|
||||
ouvrirItem.addActionListener(e -> {
|
||||
String message = "Choose the universe among those : ";
|
||||
|
||||
Set<String> files = Stream.of(new File("./saves").listFiles()).filter(file -> !file.isDirectory()).map(File::getName).collect(Collectors.toSet());
|
||||
|
||||
for (String element : files) {
|
||||
message += "\n- " + element.replace(".txt", "");
|
||||
}
|
||||
|
||||
String name = JOptionPane.showInputDialog(message);
|
||||
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new FileReader("./saves/" + name + ".txt"));
|
||||
int universe_height = Integer.valueOf(reader.readLine());
|
||||
int universe_width = Integer.valueOf(reader.readLine());
|
||||
int start_dir = Integer.valueOf(reader.readLine());
|
||||
int start_i = Integer.valueOf(reader.readLine());
|
||||
int start_j = Integer.valueOf(reader.readLine());
|
||||
|
||||
|
||||
this.universe.changeUniverseDim(universe_width + 2, universe_height + 2);
|
||||
this.universe.changeUniverseStart(start_i, start_j, start_dir);
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
int pos1 = Integer.valueOf(reader.readLine());
|
||||
int pos2 = Integer.valueOf(reader.readLine());
|
||||
|
||||
this.universe.addObstacle(pos1, pos2);
|
||||
}
|
||||
catch (Exception error) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.panel.remove(this.grid);
|
||||
this.grid = new Grid(universe_width, universe_height, this.universe);
|
||||
this.panel.add(this.grid);
|
||||
super.pack();
|
||||
super.repaint();
|
||||
}
|
||||
catch (Exception error) {}
|
||||
});
|
||||
|
||||
regles.addActionListener(e -> {
|
||||
JOptionPane.showMessageDialog(this, "Définissez la taille du plateau ainsi que l'orientation du laser, enfin ajoutez des obstacles et laissez le programme trouver le bon chemin !");
|
||||
});
|
||||
|
@ -119,7 +185,6 @@ public class Window extends JFrame {
|
|||
this.grid.solve();
|
||||
});
|
||||
|
||||
|
||||
reset.addActionListener(e -> {
|
||||
this.grid.reset();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue