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

Ajout du choix du perso + retry après game over

parent 6c15f5c4
No related branches found
No related tags found
No related merge requests found
...@@ -8,20 +8,55 @@ import static engine.GraphicalInterface.f; ...@@ -8,20 +8,55 @@ import static engine.GraphicalInterface.f;
public class MenuPanel { public class MenuPanel {
private static boolean lancementpartie = false; private static boolean lancementpartie = false;
public static boolean isRetourdebut() {
return retourdebut;
}
private static boolean retourdebut = true;
private JButton button; private JButton button;
private JButton button1;
private JButton button2;
private JButton button3;
private static boolean shootingCharacter = false;
private static boolean normalCharacter = false;
public static boolean isShootingCharacter() {
return shootingCharacter;
}
public static void setLancementpartie(boolean lancementpartie) { public static boolean isNormalCharacter() {
MenuPanel.lancementpartie = lancementpartie; return normalCharacter;
}
private void resetLancementpartie() {
button.removeActionListener(e -> lancementpartie = true);
lancementpartie = false;
}
private void resetRetourdebut() {
button.removeActionListener(e -> retourdebut = true);
retourdebut = false;
}
private void resetCharacter() {
button1.removeActionListener(e -> shootingCharacter = true);
button2.removeActionListener(e -> normalCharacter = true);
shootingCharacter = false;
normalCharacter = false;
} }
private Panel gameMenu; private Panel gameMenu;
private Panel gameChoice;
private Panel gameFin;
public boolean isLancementpartie() { public boolean isLancementpartie() {
return lancementpartie; return lancementpartie;
} }
public MenuPanel(){ public MenuPanel(){
f=new JFrame(); f=new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
...@@ -29,31 +64,74 @@ public class MenuPanel { ...@@ -29,31 +64,74 @@ public class MenuPanel {
f.setPreferredSize(new Dimension(jeu.Painter.getWidth(), jeu.Painter.getHeight())); f.setPreferredSize(new Dimension(jeu.Painter.getWidth(), jeu.Painter.getHeight()));
} }
public void menudebut(){ public void menudebut() {
gameMenu = new Panel(); gameMenu = new Panel();
button = new JButton("Nouvelle partie"); button = new JButton("Nouvelle partie");
gameMenu.add(button,BorderLayout.CENTER); gameMenu.add(button, BorderLayout.CENTER);
button.addActionListener(e -> lancementpartie = true);
f.getContentPane().add(gameMenu); f.getContentPane().add(gameMenu);
f.setContentPane(gameMenu);
f.pack();
f.setVisible(true);
f.getContentPane().setFocusable(true);
while(!isLancementpartie()){
try {
Thread.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
resetLancementpartie();
resetRetourdebut();
f.getContentPane().remove(gameMenu);
}
public void menuChoice(){
gameChoice = new Panel();
button1 = new JButton("Personnage Distance");
button2 = new JButton("Personnage Melee");
gameChoice.add(button1,BorderLayout.CENTER);
gameChoice.add(button2,BorderLayout.CENTER);
button1.addActionListener(e -> shootingCharacter = true);
button2.addActionListener(e -> normalCharacter = true);
f.getContentPane().add(gameChoice);
f.setContentPane(gameChoice);
f.pack(); f.pack();
f.setVisible(true); f.setVisible(true);
f.getContentPane().setFocusable(true); f.getContentPane().setFocusable(true);
while(!isShootingCharacter() && !isNormalCharacter()){
try {
Thread.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
f.getContentPane().remove(gameChoice);
} }
public void menufin(){ public void menufin(){
gameMenu = new Panel(new FlowLayout(FlowLayout.CENTER)); resetCharacter();
gameFin= new Panel(new FlowLayout(FlowLayout.CENTER));
button3 = new JButton("Ecran debut");
JLabel label = new JLabel("Game Over"); JLabel label = new JLabel("Game Over");
label.setFont(new Font("Arial", Font.BOLD, 24)); label.setFont(new Font("Arial", Font.BOLD, 24));
label.setForeground(Color.RED); label.setForeground(Color.RED);
gameMenu.add(label); gameFin.add(label);
f.getContentPane().add(gameMenu); gameFin.add(button3,BorderLayout.CENTER);
button3.addActionListener(e -> retourdebut = true);
f.getContentPane().add(gameFin);
f.setContentPane(gameFin);
f.pack(); f.pack();
f.setVisible(true); f.setVisible(true);
f.getContentPane().setFocusable(true); f.getContentPane().setFocusable(true);
} while(!isRetourdebut()){
try {
Thread.sleep(1);
public void waitlancementpartie(){ } catch (InterruptedException e) {
button.addActionListener(e -> lancementpartie = true); throw new RuntimeException(e);
}
}
f.getContentPane().remove(gameFin);
} }
} }
...@@ -138,8 +138,16 @@ public class Jeu implements Game{ ...@@ -138,8 +138,16 @@ public class Jeu implements Game{
monsterList.add(new Bat(new Coordonnees(1500, sol.getHitbox().getExtremites().get("HautGauche").getZ()-500), 1, 3)); monsterList.add(new Bat(new Coordonnees(1500, sol.getHitbox().getExtremites().get("HautGauche").getZ()-500), 1, 3));
monsterList.add(new Boss(new Coordonnees(3000, sol.getHitbox().getExtremites().get("HautGauche").getZ()-500), 500, 90, 180, 3, 50));*/ monsterList.add(new Boss(new Coordonnees(3000, sol.getHitbox().getExtremites().get("HautGauche").getZ()-500), 500, 90, 180, 3, 50));*/
//on charge le perso (a la fin du constructeur, cest important par rapport a obstacleTable, sinon y'a des pbs de "causalite") //on charge le perso (a la fin du constructeur, cest important par rapport a obstacleTable, sinon y'a des pbs de "causalite")
gameCharacterLoader = new CharacterLoader(characterSkinPath,new ShootingCharacter(new Coordonnees(xdebut, zdebut), 1500, 1,600000)); //regarde le choix du personnage
gameCharacter = new ShootingCharacter(new Coordonnees(xdebut, zdebut), 1500, 1,600000); if (engine.MenuPanel.isShootingCharacter()) {
gameCharacter = new ShootingCharacter(new Coordonnees(xdebut, zdebut), 1500, 1, 600000);
gameCharacterLoader = new CharacterLoader(characterSkinPath, gameCharacter);
}
if (engine.MenuPanel.isNormalCharacter()){
gameCharacter = new Character(new Coordonnees(xdebut, zdebut), 1500, 1, 600000);
gameCharacterLoader = new CharacterLoader(characterSkinPath, gameCharacter);
}
//on genere la table des monstres //on genere la table des monstres
monsterList= levelManager.generateMonsterTable(); monsterList= levelManager.generateMonsterTable();
......
...@@ -8,7 +8,6 @@ import engine.GameEngineGraphical; ...@@ -8,7 +8,6 @@ import engine.GameEngineGraphical;
import jeu.Controller; import jeu.Controller;
import jeu.Jeu; import jeu.Jeu;
import static engine.MenuPanel.setLancementpartie;
/** /**
* lancement du moteur avec le jeu * lancement du moteur avec le jeu
...@@ -16,36 +15,37 @@ import static engine.MenuPanel.setLancementpartie; ...@@ -16,36 +15,37 @@ import static engine.MenuPanel.setLancementpartie;
public class Main { public class Main {
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
MenuPanel menu = new MenuPanel();
while(engine.MenuPanel.isRetourdebut()) {
// creation du jeu particulier et de son afficheur menu.menudebut();
Jeu game = new Jeu("helpFilePacman.txt"); Thread.sleep(2);
Painter painter = new Painter(); menu.menuChoice();
Controller controller = new Controller();
GameEngineGraphical engine = new GameEngineGraphical(game, painter, controller); // creation du jeu particulier et de son afficheur
Jeu game = new Jeu("helpFilePacman.txt");
Painter painter = new Painter();
Controller controller = new Controller();
//creation du menu GameEngineGraphical engine = new GameEngineGraphical(game, painter, controller);
MenuPanel menu = new MenuPanel();
menu.menudebut();
while(!menu.isLancementpartie()){
menu.waitlancementpartie();
}
setLancementpartie(false);
//pour la musique
MP3 mp3 = new MP3("cyberPacMusic1bon.wav");
mp3.displayMusic();
// classe qui lance le moteur de jeu generique
engine.run(); //pour la musique
mp3.stopMusic(); MP3 mp3 = new MP3("cyberPacMusic1bon.wav");
mp3.displayMusic();
// classe qui lance le moteur de jeu generique
engine.run();
mp3 = new MP3("failsound.wav"); //stop la musique du jeu
mp3.displayMusic(); mp3.stopMusic();
menu.menufin();
mp3 = new MP3("failsound.wav");
mp3.displayMusic();
menu.menufin();
mp3.stopMusic();
}
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment