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;
public class MenuPanel {
private static boolean lancementpartie = false;
public static boolean isRetourdebut() {
return retourdebut;
}
private static boolean retourdebut = true;
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) {
MenuPanel.lancementpartie = lancementpartie;
public static boolean isNormalCharacter() {
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 gameChoice;
private Panel gameFin;
public boolean isLancementpartie() {
return lancementpartie;
}
public MenuPanel(){
f=new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
......@@ -29,31 +64,74 @@ public class MenuPanel {
f.setPreferredSize(new Dimension(jeu.Painter.getWidth(), jeu.Painter.getHeight()));
}
public void menudebut(){
public void menudebut() {
gameMenu = new Panel();
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.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.setVisible(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(){
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");
label.setFont(new Font("Arial", Font.BOLD, 24));
label.setForeground(Color.RED);
gameMenu.add(label);
f.getContentPane().add(gameMenu);
gameFin.add(label);
gameFin.add(button3,BorderLayout.CENTER);
button3.addActionListener(e -> retourdebut = true);
f.getContentPane().add(gameFin);
f.setContentPane(gameFin);
f.pack();
f.setVisible(true);
f.getContentPane().setFocusable(true);
}
public void waitlancementpartie(){
button.addActionListener(e -> lancementpartie = true);
while(!isRetourdebut()){
try {
Thread.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
f.getContentPane().remove(gameFin);
}
}
......@@ -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 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")
gameCharacterLoader = new CharacterLoader(characterSkinPath,new ShootingCharacter(new Coordonnees(xdebut, zdebut), 1500, 1,600000));
gameCharacter = new ShootingCharacter(new Coordonnees(xdebut, zdebut), 1500, 1,600000);
//regarde le choix du personnage
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
monsterList= levelManager.generateMonsterTable();
......
......@@ -8,7 +8,6 @@ import engine.GameEngineGraphical;
import jeu.Controller;
import jeu.Jeu;
import static engine.MenuPanel.setLancementpartie;
/**
* lancement du moteur avec le jeu
......@@ -16,36 +15,37 @@ import static engine.MenuPanel.setLancementpartie;
public class Main {
public static void main(String[] args) throws InterruptedException {
MenuPanel menu = new MenuPanel();
while(engine.MenuPanel.isRetourdebut()) {
// creation du jeu particulier et de son afficheur
Jeu game = new Jeu("helpFilePacman.txt");
Painter painter = new Painter();
Controller controller = new Controller();
menu.menudebut();
Thread.sleep(2);
menu.menuChoice();
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
MenuPanel menu = new MenuPanel();
menu.menudebut();
while(!menu.isLancementpartie()){
menu.waitlancementpartie();
}
setLancementpartie(false);
//pour la musique
MP3 mp3 = new MP3("cyberPacMusic1bon.wav");
mp3.displayMusic();
GameEngineGraphical engine = new GameEngineGraphical(game, painter, controller);
// classe qui lance le moteur de jeu generique
engine.run();
mp3.stopMusic();
//pour la musique
MP3 mp3 = new MP3("cyberPacMusic1bon.wav");
mp3.displayMusic();
// classe qui lance le moteur de jeu generique
engine.run();
mp3 = new MP3("failsound.wav");
mp3.displayMusic();
menu.menufin();
//stop la musique du jeu
mp3.stopMusic();
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.
Please register or to comment