Skip to content
Snippets Groups Projects
Commit e2153863 authored by Azurlors's avatar Azurlors
Browse files

Game Over + 1 seul JFrame

parent c4b8e3cc
Branches
No related tags found
No related merge requests found
......@@ -57,9 +57,9 @@ public class GameEngineGraphical {
// creation de l'interface graphique
this.gui = new GraphicalInterface(this.gamePainter,this.gameController);
boolean x = true;
// boucle de game
while (!this.game.isFinished()) {
while (!this.game.isFinished() || x) {
// demande controle utilisateur
HashMap<String,Boolean> a = this.gameController.getCommand(); //
// fait evoluer le game
......@@ -69,9 +69,10 @@ public class GameEngineGraphical {
if ( i == 5){
i = 0;
this.gui.paint();
x = false;
}
// met en attente
Thread.sleep(1);
Thread.sleep(2);
}
}
......
......@@ -10,6 +10,7 @@ import javax.swing.JFrame;
*
*/
public class GraphicalInterface {
public static JFrame f;
/**
* le Panel pour l'afficheur
......@@ -24,7 +25,6 @@ public class GraphicalInterface {
*
*/
public GraphicalInterface(GamePainter gamePainter, GameController gameController){
JFrame f=new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// attacher le panel contenant l'afficheur du game
......
......@@ -3,31 +3,56 @@ package engine;
import javax.swing.*;
import java.awt.*;
import static engine.GraphicalInterface.f;
public class MenuPanel {
private boolean lancementpartie = false;
private final JButton button;
private static boolean lancementpartie = false;
private JButton button;
public static void setLancementpartie(boolean lancementpartie) {
MenuPanel.lancementpartie = lancementpartie;
}
private Panel gameMenu;
public boolean isLancementpartie() {
return lancementpartie;
}
public MenuPanel(){
JFrame f=new JFrame();
f=new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new BorderLayout());
f.setPreferredSize(new Dimension(jeu.Painter.getWidth(), jeu.Painter.getHeight()));
this.button = new JButton("Nouvelle partie");
JPanel panel = new JPanel();
panel.add(button,BorderLayout.CENTER);
f.getContentPane().add(panel);
}
public void menudebut(){
gameMenu = new Panel();
button = new JButton("Nouvelle partie");
gameMenu.add(button,BorderLayout.CENTER);
f.getContentPane().add(gameMenu);
f.pack();
f.setVisible(true);
f.getContentPane().setFocusable(true);
}
public void menufin(){
gameMenu = new Panel(new FlowLayout(FlowLayout.CENTER));
JLabel label = new JLabel("Game Over");
label.setFont(new Font("Arial", Font.BOLD, 24));
label.setForeground(Color.RED);
gameMenu.add(label);
f.getContentPane().add(gameMenu);
f.pack();
f.setVisible(true);
f.getContentPane().setFocusable(true);
}
public void waitlancementpartie(){
button.addActionListener(e -> lancementpartie = true);
}
......
......@@ -187,11 +187,13 @@ public class Jeu implements Game{
//animation du perso dans le jeu (definir la bonne frame a cet instant)
animation(Attack, Right, Left);
}
@Override
public boolean isFinished() {
if(gameCharacter.death()){
return true;
}
// le jeu n'est jamais fini
return false;
}
......
......@@ -8,6 +8,8 @@ import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
public class MP3 {
Clip clip;
String filePath;
public MP3(String musicPath){
String fn = "Music/";
......@@ -21,7 +23,7 @@ public class MP3 {
File music = new File(new File(filePath).getAbsolutePath());
try {
AudioInputStream audios = AudioSystem.getAudioInputStream(music);
Clip clip = AudioSystem.getClip();
clip = AudioSystem.getClip();
clip.open(audios);
clip.start();
......@@ -34,4 +36,7 @@ public class MP3 {
}
public void stopMusic(){
clip.stop();
}
}
......@@ -8,6 +8,8 @@ import engine.GameEngineGraphical;
import jeu.Controller;
import jeu.Jeu;
import static engine.MenuPanel.setLancementpartie;
/**
* lancement du moteur avec le jeu
*/
......@@ -20,11 +22,15 @@ public class Main {
Painter painter = new Painter();
Controller controller = new Controller();
GameEngineGraphical engine = new GameEngineGraphical(game, painter, controller);
//creation du menu
MenuPanel menu = new MenuPanel();
menu.menudebut();
while(!menu.isLancementpartie()){
menu.waitlancementpartie();
}
setLancementpartie(false);
//pour la musique
......@@ -32,8 +38,15 @@ public class Main {
mp3.displayMusic();
// classe qui lance le moteur de jeu generique
GameEngineGraphical engine = new GameEngineGraphical(game, painter, controller);
engine.run();
mp3.stopMusic();
mp3 = new MP3("failsound.wav");
mp3.displayMusic();
menu.menufin();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment