Ajout de classes pour l'affichage manuel de la simulation
This commit is contained in:
parent
4488c72f28
commit
21e2bdb163
17
src/Algo.java
Normal file
17
src/Algo.java
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Interface for the algorithms
|
||||
* @version 1.0
|
||||
* @author Amir Daouadi
|
||||
* @author Lyanis Souidi
|
||||
*/
|
||||
public interface Algo {
|
||||
/**
|
||||
* Makes the next move of the algorithm
|
||||
*/
|
||||
void nextMove();
|
||||
|
||||
/**
|
||||
* Resets the algorithm
|
||||
*/
|
||||
void reset();
|
||||
}
|
70
src/ManualSimulationController.java
Normal file
70
src/ManualSimulationController.java
Normal file
@ -0,0 +1,70 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* Controller for the manual simulation view.
|
||||
* @version 1.0
|
||||
* @author Amir Daouadi
|
||||
* @author Lyanis Souidi
|
||||
*/
|
||||
public class ManualSimulationController {
|
||||
/**
|
||||
* The simulation model
|
||||
*/
|
||||
private Simulation model;
|
||||
/**
|
||||
* The manual simulation view
|
||||
*/
|
||||
private ManualSimulationView view;
|
||||
/**
|
||||
* The grid model
|
||||
*/
|
||||
private Grid grid;
|
||||
/**
|
||||
* The algorithm used for the simulation
|
||||
*/
|
||||
private Algo algo;
|
||||
/**
|
||||
* The restart button
|
||||
*/
|
||||
private Button restartButton = new Button("Recommencer");
|
||||
/**
|
||||
* The next button
|
||||
*/
|
||||
private Button nextButton = new Button("Coup suivant");
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param model The simulation model
|
||||
* @param view The manual simulation view
|
||||
* @param algo The algorithm used for the simulation
|
||||
*/
|
||||
public ManualSimulationController(Simulation model, ManualSimulationView view, Algo algo) {
|
||||
this.model = model;
|
||||
this.view = view;
|
||||
this.algo = algo;
|
||||
|
||||
JPanel buttons = new JPanel();
|
||||
|
||||
restartButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
algo.reset();
|
||||
}
|
||||
});
|
||||
buttons.add(restartButton);
|
||||
|
||||
nextButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
algo.nextMove();
|
||||
if (model.isSuccess()) {
|
||||
nextButton.setEnabled(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
buttons.add(nextButton);
|
||||
|
||||
this.view.add(buttons, BorderLayout.NORTH);
|
||||
}
|
||||
}
|
35
src/ManualSimulationView.java
Normal file
35
src/ManualSimulationView.java
Normal file
@ -0,0 +1,35 @@
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* The manual simulation view
|
||||
* @version 1.0
|
||||
* @author Amir Daouadi
|
||||
* @author Lyanis Souidi
|
||||
*/
|
||||
public class ManualSimulationView extends GridView {
|
||||
/**
|
||||
* The simulation model
|
||||
*/
|
||||
private Simulation model;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param window The window
|
||||
* @param model The simulation model
|
||||
*/
|
||||
public ManualSimulationView(Window window, Simulation model) {
|
||||
super(window);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.setFont(new Font("Arial", Font.PLAIN, 20));
|
||||
FontMetrics metrics = g.getFontMetrics(g.getFont());
|
||||
|
||||
String movesStr = "Coups : " + this.model.getMoves();
|
||||
g.drawString(movesStr, 5, 5);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user