Compare commits
20 Commits
27f8f60bed
...
201002222
| Author | SHA1 | Date | |
|---|---|---|---|
| 0eea417ad2 | |||
| 008e45bb68 | |||
| 44ac782380 | |||
| 26850ca823 | |||
| 7f63cdf089 | |||
| dce34ed607 | |||
| 56d4764773 | |||
| 08e68ad1ba | |||
| 6feffb79d9 | |||
| 5a974ce7ac | |||
| bbb26bcb3d | |||
| dcd4cd3d07 | |||
| cb3b3d0e35 | |||
| 7bb44b019e | |||
| da1962145a | |||
| 647276be0d | |||
| d10578c313 | |||
| c52547120b | |||
| 2721516b0b | |||
| 8f39b0ad7f |
51
src/linea/CampagneAutoroute.java
Normal file
51
src/linea/CampagneAutoroute.java
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package linea;
|
||||||
|
|
||||||
|
import javax.swing.Timer;
|
||||||
|
import java.awt.Color;
|
||||||
|
|
||||||
|
public class CampagneAutoroute {
|
||||||
|
|
||||||
|
protected Jeu jeu; // Référence au jeu principal
|
||||||
|
|
||||||
|
public CampagneAutoroute(Jeu j) {
|
||||||
|
this.jeu = j;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lancerNiveau1() {
|
||||||
|
System.out.println("Lancement du niveau autoroute ...");
|
||||||
|
|
||||||
|
|
||||||
|
if(jeu.horloge != null) {
|
||||||
|
jeu.horloge.stop();
|
||||||
|
}
|
||||||
|
jeu.horloge = new Timer(40, jeu);
|
||||||
|
|
||||||
|
|
||||||
|
jeu.ecran.viderObjets();
|
||||||
|
|
||||||
|
|
||||||
|
FondAutoroute fond = new FondAutoroute();
|
||||||
|
jeu.ecran.ajouterObjet(fond);
|
||||||
|
|
||||||
|
jeu.laligne = new Ligne(); // La ligne
|
||||||
|
jeu.ecran.ajouterObjet(jeu.laligne);
|
||||||
|
|
||||||
|
Voiture maVoiture = new Voiture();
|
||||||
|
|
||||||
|
jeu.ecran.ajouterObjet(maVoiture);
|
||||||
|
|
||||||
|
jeu.demiCercleAvant = maVoiture;
|
||||||
|
jeu.demiCercleArriere = maVoiture;
|
||||||
|
|
||||||
|
|
||||||
|
jeu.ecran.setGameOver(false);
|
||||||
|
jeu.score = 0;
|
||||||
|
jeu.labScore.setText("<html><h3 style='color:white;'>score : 0</h3></html>");
|
||||||
|
|
||||||
|
|
||||||
|
jeu.layout.show(jeu.conteneurPrincipal, "JEU");
|
||||||
|
jeu.ecran.setFocusable(true);
|
||||||
|
jeu.ecran.requestFocusInWindow();
|
||||||
|
jeu.horloge.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
54
src/linea/CampagneOcean.java
Normal file
54
src/linea/CampagneOcean.java
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
package linea;
|
||||||
|
|
||||||
|
import javax.swing.Timer;
|
||||||
|
import java.awt.Color;
|
||||||
|
|
||||||
|
public class CampagneOcean {
|
||||||
|
|
||||||
|
protected Jeu jeuPrincipal;
|
||||||
|
|
||||||
|
public CampagneOcean(Jeu jeu) {
|
||||||
|
this.jeuPrincipal = jeu;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void demarrerLeNiveau(int niveau) {
|
||||||
|
System.out.println("Lancement du niveau Ocean - Difficulté : " + niveau);
|
||||||
|
|
||||||
|
if (jeuPrincipal.horloge != null) {
|
||||||
|
jeuPrincipal.horloge.stop();
|
||||||
|
}
|
||||||
|
jeuPrincipal.horloge = new Timer(40, jeuPrincipal);
|
||||||
|
|
||||||
|
jeuPrincipal.ecran.viderObjets();
|
||||||
|
|
||||||
|
FondOcean monFond = new FondOcean();
|
||||||
|
jeuPrincipal.ecran.ajouterObjet(monFond);
|
||||||
|
|
||||||
|
jeuPrincipal.laligne = new Ligne();
|
||||||
|
|
||||||
|
if (niveau == 1) {
|
||||||
|
jeuPrincipal.laligne.setInclinaisonMax(10.0);
|
||||||
|
} else if (niveau == 2) {
|
||||||
|
jeuPrincipal.laligne.setInclinaisonMax(30.0);
|
||||||
|
} else {
|
||||||
|
jeuPrincipal.laligne.setInclinaisonMax(55.0);
|
||||||
|
}
|
||||||
|
jeuPrincipal.ecran.ajouterObjet(jeuPrincipal.laligne);
|
||||||
|
|
||||||
|
Cercle joueur = new Cercle(0, 360);
|
||||||
|
joueur.setCouleur(new Color(200, 230, 255));
|
||||||
|
jeuPrincipal.ecran.ajouterObjet(joueur);
|
||||||
|
|
||||||
|
jeuPrincipal.demiCercleAvant = joueur;
|
||||||
|
jeuPrincipal.demiCercleArriere = joueur;
|
||||||
|
|
||||||
|
jeuPrincipal.ecran.setGameOver(false);
|
||||||
|
jeuPrincipal.score = 0;
|
||||||
|
jeuPrincipal.labScore.setText("<html><h3 style='color:white;'>Oxygène : 0</h3></html>");
|
||||||
|
|
||||||
|
jeuPrincipal.layout.show(jeuPrincipal.conteneurPrincipal, "JEU");
|
||||||
|
jeuPrincipal.ecran.setFocusable(true);
|
||||||
|
jeuPrincipal.ecran.requestFocusInWindow();
|
||||||
|
jeuPrincipal.horloge.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
42
src/linea/FondAutoroute.java
Normal file
42
src/linea/FondAutoroute.java
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package linea;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
|
||||||
|
public class FondAutoroute extends ObjetGraphique {
|
||||||
|
|
||||||
|
private double decalage = 0;
|
||||||
|
|
||||||
|
public FondAutoroute() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void Afficher(Graphics g) {
|
||||||
|
// Ciel de nuit urbaine
|
||||||
|
g.setColor(new Color(20, 20, 45));
|
||||||
|
g.fillRect(0, 0, 800, 50);
|
||||||
|
|
||||||
|
// Asphalte de l'autoroute en bas
|
||||||
|
g.setColor(new Color(30, 30, 30));
|
||||||
|
g.fillRect(0, 50, 800, 500);
|
||||||
|
|
||||||
|
// Lignes de séparation de voie qui défilent
|
||||||
|
g.setColor(Color.YELLOW);
|
||||||
|
for(int i = 0; i < 900; i += 120) {
|
||||||
|
for(int j = 0; j < 500; j+=167) {
|
||||||
|
g.fillRect(i - (int)decalage, 117+j, 60, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g.setColor(new Color(20, 20, 45));
|
||||||
|
g.fillRect(0, 550, 800, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void Animer() {
|
||||||
|
decalage += 5.0;
|
||||||
|
if (decalage >= 120) {
|
||||||
|
decalage = 0; // Boucle infinie
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/linea/FondOcean.java
Normal file
36
src/linea/FondOcean.java
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package linea;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
|
||||||
|
public class FondOcean extends ObjetGraphique {
|
||||||
|
|
||||||
|
private int[] positionsBullesX = {100, 250, 400, 550, 700, 150, 450};
|
||||||
|
private int[] positionsBullesY = {600, 800, 700, 900, 650, 1000, 1100};
|
||||||
|
private int vitesseRemonteeDesBulles = 2;
|
||||||
|
|
||||||
|
public FondOcean() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void Afficher(Graphics pinceau) {
|
||||||
|
pinceau.setColor(new Color(0, 105, 148));
|
||||||
|
pinceau.fillRect(0, 0, 800, 600);
|
||||||
|
|
||||||
|
pinceau.setColor(new Color(255, 255, 255, 150));
|
||||||
|
for (int i = 0; i < positionsBullesX.length; i++) {
|
||||||
|
pinceau.drawOval(positionsBullesX[i], positionsBullesY[i], 10, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
void Animer() {
|
||||||
|
for (int i = 0; i < positionsBullesY.length; i++) {
|
||||||
|
positionsBullesY[i] = positionsBullesY[i] - vitesseRemonteeDesBulles;
|
||||||
|
|
||||||
|
if (positionsBullesY[i] < -20) {
|
||||||
|
positionsBullesY[i] = 650;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,22 +9,23 @@ public class Jeu implements KeyListener, ActionListener {
|
|||||||
protected JPanel conteneurPrincipal;
|
protected JPanel conteneurPrincipal;
|
||||||
protected CardLayout layout;
|
protected CardLayout layout;
|
||||||
|
|
||||||
// Instances du jeu
|
|
||||||
protected ZoneDessin ecran = new ZoneDessin();
|
protected ZoneDessin ecran = new ZoneDessin();
|
||||||
|
|
||||||
|
// MENUS
|
||||||
protected MenuPrincipal menu;
|
protected MenuPrincipal menu;
|
||||||
|
protected MenuCampagne menuCampagne;
|
||||||
|
|
||||||
protected Cercle demiCercleAvant = new Cercle(90, -180);
|
protected Cercle demiCercleAvant;
|
||||||
protected Cercle demiCercleArriere = new Cercle(90, 180);
|
protected Cercle demiCercleArriere;
|
||||||
protected Ligne laligne = new Ligne();
|
protected Ligne laligne = new Ligne();
|
||||||
|
|
||||||
protected Timer horloge;
|
protected Timer horloge;
|
||||||
protected JLabel labScore;
|
protected JLabel labScore;
|
||||||
|
protected int score;
|
||||||
|
|
||||||
public Jeu() {
|
public Jeu(){
|
||||||
// Initialisation du score (comme dans le fichier original)
|
score = 0;
|
||||||
labScore = new JLabel();
|
labScore = new JLabel("<html><h3>score : 0</h3></html>");
|
||||||
labScore.setText("<html><h3>score : 0</h3></html>");
|
labScore.setBounds(20, 540, 200, 50);
|
||||||
labScore.setBounds(20, 0, 200, 50);
|
|
||||||
ecran.add(labScore);
|
ecran.add(labScore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,82 +33,126 @@ public class Jeu implements KeyListener, ActionListener {
|
|||||||
fenetre = new JFrame("Linea");
|
fenetre = new JFrame("Linea");
|
||||||
layout = new CardLayout();
|
layout = new CardLayout();
|
||||||
conteneurPrincipal = new JPanel(layout);
|
conteneurPrincipal = new JPanel(layout);
|
||||||
|
score = 0;
|
||||||
|
|
||||||
// Création du menu en lui passant l'instance actuelle de Jeu
|
|
||||||
menu = new MenuPrincipal(this);
|
menu = new MenuPrincipal(this);
|
||||||
|
menuCampagne = new MenuCampagne(this);
|
||||||
|
|
||||||
// Configuration de la zone de dessin
|
// Initialisation initiale
|
||||||
|
resetPartie();
|
||||||
|
|
||||||
|
// On ajoute l'action au bouton "Retour" de la ZoneDessin (Game Over)
|
||||||
|
ecran.btnRetour.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
afficherMenuPrincipal();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ecran.addKeyListener(this);
|
||||||
|
|
||||||
|
conteneurPrincipal.add(menu, "MENU");
|
||||||
|
conteneurPrincipal.add(menuCampagne, "CAMPAGNE");
|
||||||
|
conteneurPrincipal.add(ecran, "JEU");
|
||||||
|
|
||||||
|
fenetre.setContentPane(conteneurPrincipal);
|
||||||
|
fenetre.pack();
|
||||||
|
fenetre.setLocationRelativeTo(null);
|
||||||
|
fenetre.setVisible(true);
|
||||||
|
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void afficherMenuCampagne() {
|
||||||
|
layout.show(conteneurPrincipal, "CAMPAGNE");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void afficherMenuPrincipal() {
|
||||||
|
layout.show(conteneurPrincipal, "MENU");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lancerNiveau(int numeroNiveau) {
|
||||||
|
System.out.println("Lancement du niveau " + numeroNiveau);
|
||||||
|
// Ici tu pourras configurer la difficulté selon le niveau
|
||||||
|
lancerPartie();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lancerPartie() {
|
||||||
|
resetPartie();
|
||||||
|
layout.show(conteneurPrincipal, "JEU");
|
||||||
|
ecran.setFocusable(true);
|
||||||
|
ecran.requestFocusInWindow();
|
||||||
|
horloge.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetPartie() {
|
||||||
|
if(horloge != null) {
|
||||||
|
horloge.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
horloge = new Timer(40, this);
|
||||||
|
|
||||||
|
demiCercleAvant = new Cercle(90, -180);
|
||||||
|
demiCercleArriere = new Cercle(90, 180);
|
||||||
|
|
||||||
|
laligne = new Ligne();
|
||||||
|
|
||||||
|
demiCercleArriere.setCouleur(new Color(0.8f, 0.0f, 0.0f));
|
||||||
|
demiCercleAvant.setCouleur(new Color(1.0f, 0.2f, 0.2f));
|
||||||
|
|
||||||
|
ecran.viderObjets();
|
||||||
ecran.ajouterObjet(demiCercleArriere);
|
ecran.ajouterObjet(demiCercleArriere);
|
||||||
ecran.ajouterObjet(demiCercleAvant);
|
ecran.ajouterObjet(demiCercleAvant);
|
||||||
ecran.ajouterObjet(laligne);
|
ecran.ajouterObjet(laligne);
|
||||||
ecran.addKeyListener(this); // Le jeu écoute le clavier
|
|
||||||
|
|
||||||
// Ajout des "cartes" au conteneur principal
|
ecran.setGameOver(false);
|
||||||
conteneurPrincipal.add(menu, "MENU");
|
|
||||||
conteneurPrincipal.add(ecran, "JEU");
|
|
||||||
|
|
||||||
// Configuration de la fenêtre
|
score = 0;
|
||||||
fenetre.setContentPane(conteneurPrincipal);
|
labScore.setText("<html><h3>score : 0</h3></html>");
|
||||||
fenetre.pack();
|
|
||||||
fenetre.setLocationRelativeTo(null); // Centrer à l'écran
|
|
||||||
fenetre.setVisible(true);
|
|
||||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
|
|
||||||
// Timer (40ms = 25 fps)
|
|
||||||
horloge = new Timer(40, this);
|
|
||||||
|
|
||||||
// Couleurs
|
|
||||||
demiCercleArriere.setCouleur(new Color(0.8f, 0.0f, 0.0f));
|
|
||||||
demiCercleAvant.setCouleur(new Color(1.0f, 0.2f, 0.2f));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Méthode appelée par le bouton PLAY du menu
|
|
||||||
public void lancerPartie() {
|
|
||||||
layout.show(conteneurPrincipal, "JEU");
|
|
||||||
ecran.setFocusable(true);
|
|
||||||
ecran.requestFocusInWindow(); // Indispensable pour capter le clavier
|
|
||||||
horloge.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
// CORRECTION ICI : Appel de la bonne méthode de ZoneDessin
|
|
||||||
ecran.traiterBoucleAnimation();
|
ecran.traiterBoucleAnimation();
|
||||||
|
|
||||||
// Logique de collision (réintégrée depuis le fichier original)
|
score ++;
|
||||||
double yLigne = laligne.getHauteurLigneA(400); // 400 est une valeur arbitraire pour tester au centre
|
|
||||||
double yCercle = demiCercleAvant.getY();
|
|
||||||
|
|
||||||
if (Math.abs(yLigne - yCercle) > 30) {
|
labScore.setText("<html><h3>score : " + score+"</h3></html>");
|
||||||
|
// Gestion collision simple
|
||||||
|
double hauteurLigne = laligne.getHauteurLigneA(400);
|
||||||
|
if (hauteurLigne != -1) {
|
||||||
|
// calcule de la distance entre le centre du cercle et la ligne
|
||||||
|
double distance = Math.abs(hauteurLigne - demiCercleAvant.getY());
|
||||||
|
|
||||||
|
// Si cette distance est strictement supérieure au rayon du bouclier,
|
||||||
|
// cela signifie que la ligne est sortie de la bulle !
|
||||||
|
if (distance > demiCercleAvant.getRayon()) {
|
||||||
|
gameOver();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Si on arrive au bout de la ligne
|
||||||
gameOver();
|
gameOver();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gameOver() {
|
public void gameOver() {
|
||||||
horloge.stop();
|
horloge.stop();
|
||||||
ecran.setGameOver(true);
|
ecran.setGameOver(true); // Affiche "Game Over" et le bouton Retour
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Gestion du Clavier ---
|
// Gestion touches...
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
int keyCode = e.getKeyCode();
|
if (e.getKeyCode() == 38) {
|
||||||
if (keyCode == 38) { // Flèche HAUT
|
|
||||||
demiCercleAvant.Monter();
|
demiCercleAvant.Monter();
|
||||||
demiCercleArriere.Monter();
|
demiCercleArriere.Monter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyReleased(KeyEvent e) {
|
public void keyReleased(KeyEvent e) {
|
||||||
int keyCode = e.getKeyCode();
|
if (e.getKeyCode() == 38) {
|
||||||
if (keyCode == 38) {
|
|
||||||
demiCercleAvant.ArreterMonter();
|
demiCercleAvant.ArreterMonter();
|
||||||
demiCercleArriere.ArreterMonter();
|
demiCercleArriere.ArreterMonter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Override public void keyTyped(KeyEvent e) {}
|
||||||
@Override
|
|
||||||
public void keyTyped(KeyEvent e) {}
|
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,9 @@ public class Ligne extends ObjetGraphique{// Hérite de la classe ObjetGraphique
|
|||||||
// nb de Segments qui composent la ligne
|
// nb de Segments qui composent la ligne
|
||||||
protected int nbSegments = 400;
|
protected int nbSegments = 400;
|
||||||
|
|
||||||
|
// amplitude maximale de l'inclinaison verticale des segments (dy)
|
||||||
|
protected double inclinaisonMax = 30.0;
|
||||||
|
|
||||||
// position du cercle, pour déterminer quel est le segment courant
|
// position du cercle, pour déterminer quel est le segment courant
|
||||||
protected double xCercle = 400; // à modifier
|
protected double xCercle = 400; // à modifier
|
||||||
|
|
||||||
@@ -49,7 +52,13 @@ public class Ligne extends ObjetGraphique{// Hérite de la classe ObjetGraphique
|
|||||||
for (int i=0; i<nbSegments; i++){
|
for (int i=0; i<nbSegments; i++){
|
||||||
// définition d'un nouveau segment
|
// définition d'un nouveau segment
|
||||||
dx = (Math.random()*20)+80;
|
dx = (Math.random()*20)+80;
|
||||||
dy = (Math.random()*60)-30;
|
// dy aléatoire dans [-inclinaisonMax, +inclinaisonMax]
|
||||||
|
dy = (Math.random() * (2.0 * inclinaisonMax)) - inclinaisonMax;
|
||||||
|
|
||||||
|
if (y + dy < 0 || y + dy > 600) {
|
||||||
|
dy = -dy;
|
||||||
|
}
|
||||||
|
|
||||||
s = new Segment(x,y,dx,dy);
|
s = new Segment(x,y,dx,dy);
|
||||||
s.setCouleur(new Color(0.2f,0.2f,0.2f));
|
s.setCouleur(new Color(0.2f,0.2f,0.2f));
|
||||||
|
|
||||||
@@ -59,6 +68,15 @@ public class Ligne extends ObjetGraphique{// Hérite de la classe ObjetGraphique
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setInclinaisonMax(double valeur) {
|
||||||
|
if (valeur < 0) valeur = -valeur;
|
||||||
|
this.inclinaisonMax = valeur;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getInclinaisonMax() {
|
||||||
|
return this.inclinaisonMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|||||||
98
src/linea/MenuCampagne.java
Normal file
98
src/linea/MenuCampagne.java
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
package linea;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class MenuCampagne extends JPanel {
|
||||||
|
|
||||||
|
public MenuCampagne(Jeu jeu) {
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
setBackground(new Color(45, 45, 45));
|
||||||
|
|
||||||
|
CardLayout cartes = new CardLayout();
|
||||||
|
JPanel panneauCartes = new JPanel(cartes);
|
||||||
|
|
||||||
|
JPanel listeCampagnes = new JPanel();
|
||||||
|
listeCampagnes.setLayout(new BoxLayout(listeCampagnes, BoxLayout.Y_AXIS));
|
||||||
|
listeCampagnes.setBackground(new Color(45, 45, 45));
|
||||||
|
|
||||||
|
JLabel titre = new JLabel("CAMPAGNES");
|
||||||
|
titre.setForeground(Color.WHITE);
|
||||||
|
titre.setFont(new Font("SansSerif", Font.BOLD, 40));
|
||||||
|
titre.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
|
||||||
|
JButton btnC1 = creerBouton("CAMPAGNE 1");
|
||||||
|
JButton btnC2 = creerBouton("CAMPAGNE 2");
|
||||||
|
JButton btnC3 = creerBouton("CAMPAGNE 3");
|
||||||
|
JButton btnRetour = creerBouton("RETOUR");
|
||||||
|
|
||||||
|
listeCampagnes.add(Box.createVerticalGlue());
|
||||||
|
listeCampagnes.add(titre);
|
||||||
|
listeCampagnes.add(Box.createRigidArea(new Dimension(0, 40)));
|
||||||
|
|
||||||
|
listeCampagnes.add(btnC1);
|
||||||
|
listeCampagnes.add(Box.createRigidArea(new Dimension(0, 10)));
|
||||||
|
listeCampagnes.add(btnC2);
|
||||||
|
listeCampagnes.add(Box.createRigidArea(new Dimension(0, 10)));
|
||||||
|
listeCampagnes.add(btnC3);
|
||||||
|
|
||||||
|
listeCampagnes.add(Box.createRigidArea(new Dimension(0, 30)));
|
||||||
|
listeCampagnes.add(btnRetour);
|
||||||
|
listeCampagnes.add(Box.createVerticalGlue());
|
||||||
|
|
||||||
|
// ---- Carte : sélection des niveaux ----
|
||||||
|
JPanel selectionNiveaux = new JPanel();
|
||||||
|
selectionNiveaux.setLayout(new BoxLayout(selectionNiveaux, BoxLayout.Y_AXIS));
|
||||||
|
selectionNiveaux.setBackground(new Color(45, 45, 45));
|
||||||
|
|
||||||
|
JLabel titreNiveaux = new JLabel("CHOISISSEZ UN NIVEAU");
|
||||||
|
titreNiveaux.setForeground(Color.WHITE);
|
||||||
|
titreNiveaux.setFont(new Font("SansSerif", Font.BOLD, 32));
|
||||||
|
titreNiveaux.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
|
||||||
|
JButton btnN1 = creerBouton("FACILE");
|
||||||
|
JButton btnN2 = creerBouton("MOYEN");
|
||||||
|
JButton btnN3 = creerBouton("DIFFICILE");
|
||||||
|
JButton btnRetourCampagnes = creerBouton("RETOUR AUX CAMPAGNES");
|
||||||
|
|
||||||
|
selectionNiveaux.add(Box.createVerticalGlue());
|
||||||
|
selectionNiveaux.add(titreNiveaux);
|
||||||
|
selectionNiveaux.add(Box.createRigidArea(new Dimension(0, 30)));
|
||||||
|
selectionNiveaux.add(btnN1);
|
||||||
|
selectionNiveaux.add(Box.createRigidArea(new Dimension(0, 10)));
|
||||||
|
selectionNiveaux.add(btnN2);
|
||||||
|
selectionNiveaux.add(Box.createRigidArea(new Dimension(0, 10)));
|
||||||
|
selectionNiveaux.add(btnN3);
|
||||||
|
selectionNiveaux.add(Box.createRigidArea(new Dimension(0, 30)));
|
||||||
|
selectionNiveaux.add(btnRetourCampagnes);
|
||||||
|
selectionNiveaux.add(Box.createVerticalGlue());
|
||||||
|
|
||||||
|
panneauCartes.add(listeCampagnes, "LISTE");
|
||||||
|
panneauCartes.add(selectionNiveaux, "NIVEAUX");
|
||||||
|
|
||||||
|
btnRetour.addActionListener(e -> jeu.afficherMenuPrincipal());
|
||||||
|
|
||||||
|
java.awt.event.ActionListener ouvrirNiveaux = e -> cartes.show(panneauCartes, "NIVEAUX");
|
||||||
|
btnC1.addActionListener(ouvrirNiveaux);
|
||||||
|
btnC2.addActionListener(ouvrirNiveaux);
|
||||||
|
btnC3.addActionListener(ouvrirNiveaux);
|
||||||
|
|
||||||
|
btnRetourCampagnes.addActionListener(e -> cartes.show(panneauCartes, "LISTE"));
|
||||||
|
|
||||||
|
btnN1.addActionListener(e -> jeu.lancerNiveau(1));
|
||||||
|
btnN2.addActionListener(e -> jeu.lancerNiveau(2));
|
||||||
|
btnN3.addActionListener(e -> jeu.lancerNiveau(3));
|
||||||
|
|
||||||
|
add(panneauCartes, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
private JButton creerBouton(String texte) {
|
||||||
|
JButton b = new JButton(texte);
|
||||||
|
b.setFont(new Font("SansSerif", Font.PLAIN, 18));
|
||||||
|
b.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
b.setMaximumSize(new Dimension(240, 45));
|
||||||
|
b.setFocusable(false);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,12 +3,12 @@ package linea;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
public class MenuPrincipal extends JPanel{
|
public class MenuPrincipal extends JPanel {
|
||||||
private JButton btnPlay;
|
private JButton btnPlay;
|
||||||
|
private JButton btnCampaign; // Nouveau bouton
|
||||||
private JButton btnSettings;
|
private JButton btnSettings;
|
||||||
private JButton btnQuit;
|
private JButton btnQuit;
|
||||||
|
|
||||||
|
|
||||||
public MenuPrincipal(Jeu jeu) {
|
public MenuPrincipal(Jeu jeu) {
|
||||||
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||||
setBackground(new Color(45, 45, 45)); // Gris foncé
|
setBackground(new Color(45, 45, 45)); // Gris foncé
|
||||||
@@ -19,22 +19,30 @@ public class MenuPrincipal extends JPanel{
|
|||||||
titre.setFont(new Font("SansSerif", Font.BOLD, 60));
|
titre.setFont(new Font("SansSerif", Font.BOLD, 60));
|
||||||
titre.setAlignmentX(Component.CENTER_ALIGNMENT);
|
titre.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
|
||||||
// Boutons
|
// Création des Boutons
|
||||||
btnPlay = creerBouton("PLAY");
|
btnPlay = creerBouton("PLAY");
|
||||||
|
btnCampaign = creerBouton("CAMPAGNES"); // Création
|
||||||
btnSettings = creerBouton("SETTINGS");
|
btnSettings = creerBouton("SETTINGS");
|
||||||
btnQuit = creerBouton("QUIT");
|
btnQuit = creerBouton("QUIT");
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
btnPlay.addActionListener(e -> jeu.lancerPartie());
|
btnPlay.addActionListener(e -> jeu.lancerPartie());
|
||||||
|
|
||||||
|
// Action pour aller vers le menu campagne
|
||||||
|
// (Assure-toi d'avoir cette méthode dans ta classe Jeu)
|
||||||
|
btnCampaign.addActionListener(e -> jeu.afficherMenuCampagne());
|
||||||
|
|
||||||
btnSettings.addActionListener(e -> JOptionPane.showMessageDialog(this, "Options bientôt disponibles !"));
|
btnSettings.addActionListener(e -> JOptionPane.showMessageDialog(this, "Options bientôt disponibles !"));
|
||||||
btnQuit.addActionListener(e -> System.exit(0));
|
btnQuit.addActionListener(e -> System.exit(0));
|
||||||
|
|
||||||
// Mise en page (espacement)
|
// Mise en page (espacement vertical)
|
||||||
add(Box.createVerticalGlue());
|
add(Box.createVerticalGlue());
|
||||||
add(titre);
|
add(titre);
|
||||||
add(Box.createRigidArea(new Dimension(0, 50)));
|
add(Box.createRigidArea(new Dimension(0, 50)));
|
||||||
add(btnPlay);
|
add(btnPlay);
|
||||||
add(Box.createRigidArea(new Dimension(0, 15)));
|
add(Box.createRigidArea(new Dimension(0, 15)));
|
||||||
|
add(btnCampaign); // Ajout à l'affichage
|
||||||
|
add(Box.createRigidArea(new Dimension(0, 15)));
|
||||||
add(btnSettings);
|
add(btnSettings);
|
||||||
add(Box.createRigidArea(new Dimension(0, 15)));
|
add(Box.createRigidArea(new Dimension(0, 15)));
|
||||||
add(btnQuit);
|
add(btnQuit);
|
||||||
@@ -46,7 +54,7 @@ public class MenuPrincipal extends JPanel{
|
|||||||
b.setFont(new Font("SansSerif", Font.PLAIN, 20));
|
b.setFont(new Font("SansSerif", Font.PLAIN, 20));
|
||||||
b.setAlignmentX(Component.CENTER_ALIGNMENT);
|
b.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
b.setMaximumSize(new Dimension(200, 50));
|
b.setMaximumSize(new Dimension(200, 50));
|
||||||
b.setFocusable(false); // Pour ne pas voler le focus du clavier plus tard
|
b.setFocusable(false);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
48
src/linea/Voiture.java
Normal file
48
src/linea/Voiture.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package linea;
|
||||||
|
|
||||||
|
import java.awt.BasicStroke;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.geom.Arc2D;
|
||||||
|
|
||||||
|
public class Voiture extends Cercle {
|
||||||
|
|
||||||
|
// On définit les couleurs directement ici pour simplifier
|
||||||
|
private Color couleurArriere = Color.GRAY;
|
||||||
|
private Color couleurAvant = Color.GRAY;
|
||||||
|
|
||||||
|
public Voiture() {
|
||||||
|
super();
|
||||||
|
this.rayon = 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void Afficher(Graphics g) {
|
||||||
|
Graphics2D g2D = (Graphics2D) g;
|
||||||
|
g2D.setStroke(new BasicStroke(5.0f));
|
||||||
|
|
||||||
|
// DESSINER LE DEMI-CERCLE ARRIERE (Au fond)
|
||||||
|
g2D.setColor(couleurArriere);
|
||||||
|
// Utilisation de rayon*2 pour la largeur et hauteur (cercle parfait)
|
||||||
|
g2D.draw(new Arc2D.Double(x - rayon, y - rayon, rayon * 2, rayon * 2, 90, 180, Arc2D.OPEN));
|
||||||
|
|
||||||
|
// DESSINER LA VOITURE (Au milieu)
|
||||||
|
g.setColor(new Color(150, 50, 200));
|
||||||
|
g.fillRect((int)x - 20, (int)y - 5, 40, 12);
|
||||||
|
|
||||||
|
g.setColor(Color.CYAN);
|
||||||
|
g.fillRect((int)x - 10, (int)y - 15, 20, 10);
|
||||||
|
|
||||||
|
g.setColor(Color.DARK_GRAY);
|
||||||
|
g.fillOval((int)x - 15, (int)y + 3, 10, 10);
|
||||||
|
g.fillOval((int)x + 5, (int)y + 3, 10, 10);
|
||||||
|
|
||||||
|
g.setColor(Color.YELLOW);
|
||||||
|
g.fillOval((int)x + 15, (int)y - 2, 6, 6);
|
||||||
|
|
||||||
|
// DESSINER LE DEMI-CERCLE AVANT (Par-dessus)
|
||||||
|
g2D.setColor(couleurAvant);
|
||||||
|
g2D.draw(new Arc2D.Double(x - rayon, y - rayon, rayon * 2, rayon * 2, 90, -180, Arc2D.OPEN));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,113 +2,76 @@ package linea;
|
|||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
public class ZoneDessin extends JPanel {
|
||||||
|
|
||||||
public class ZoneDessin extends JPanel { // hérite d'une classe du frameWork standard
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
protected ArrayList<ObjetGraphique> listeObjets = new ArrayList<ObjetGraphique>();
|
protected ArrayList<ObjetGraphique> listeObjets = new ArrayList<ObjetGraphique>();
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
// Etats du jeu
|
||||||
// PROPRIETES
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// un booleen qui permet d'arreter l'animation (suspendre)
|
|
||||||
protected boolean estArrete = false;
|
protected boolean estArrete = false;
|
||||||
|
|
||||||
protected boolean isGameOver = false;
|
protected boolean isGameOver = false;
|
||||||
|
|
||||||
|
// LE BOUTON DOIT ÊTRE PUBLIC POUR ÊTRE ACCESSIBLE DEPUIS JEU.JAVA
|
||||||
|
public JButton btnRetour;
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
// METHODES
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
// Constructeur de la classe
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
public ZoneDessin(){
|
public ZoneDessin(){
|
||||||
// on prépare la zone d'affichage
|
// Layout null pour positionner le bouton pixel par pixel
|
||||||
setLayout(new BorderLayout());
|
setLayout(null);
|
||||||
setPreferredSize(new Dimension(800, 600));
|
setPreferredSize(new Dimension(800, 600));
|
||||||
setBackground(new Color(100,100,100));
|
setBackground(new Color(100,100,100));
|
||||||
|
|
||||||
|
// 2. Création et configuration du bouton
|
||||||
|
btnRetour = new JButton("Back to Menu");
|
||||||
|
// x, y, largeur, hauteur (centré horizontalement pour une fenêtre de 800px)
|
||||||
|
btnRetour.setBounds(300, 350, 200, 50);
|
||||||
|
btnRetour.setFont(new Font("Arial", Font.BOLD, 16));
|
||||||
|
btnRetour.setFocusable(false); // Important pour ne pas gêner le clavier
|
||||||
|
btnRetour.setVisible(false); // Caché au début
|
||||||
|
|
||||||
|
this.add(btnRetour);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ... (méthodes ajouterObjet, viderObjets, arreter, demarrer restent pareilles) ...
|
||||||
|
public void ajouterObjet(ObjetGraphique unObjet) { this.listeObjets.add(unObjet); }
|
||||||
|
public void viderObjets() { this.listeObjets.clear(); }
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
// Ajout d'un objet graphique à la zonde de dessin
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
public void ajouterObjet(ObjetGraphique unObjet) {
|
|
||||||
this.listeObjets.add(unObjet);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
// Mettre en pause et redémarrer
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
public void arreter(){
|
|
||||||
estArrete = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void demarrer(){
|
|
||||||
estArrete = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
// Boucle d'animation :
|
|
||||||
// - appelée par exemple 25 fois par seconde
|
|
||||||
// - à chaque appel :
|
|
||||||
// - on anime (déplace) chaque objet
|
|
||||||
// - on redessine tout : appel à paintComponent, déclenché par repaint
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
public void traiterBoucleAnimation(){
|
public void traiterBoucleAnimation(){
|
||||||
if (estArrete==true) {
|
if (estArrete || isGameOver) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1. on déplace chaque objet graphique
|
|
||||||
// A FAIRE : décommenter lorsque cela devienda exécutable, et compléter
|
|
||||||
|
|
||||||
for (ObjetGraphique obj : listeObjets){
|
for (ObjetGraphique obj : listeObjets){
|
||||||
obj.Animer();
|
obj.Animer();
|
||||||
}
|
}
|
||||||
// 2. on demande à redessiner, ce qui déclenchera automatiquement
|
|
||||||
// l'appel à la méthode paintComponent, qui est ci-dessous
|
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
// Dessin, déclenché par le repaint() de la méthode ci-dessus
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
// On demande à la super-classe (JPanel) de se redessiner
|
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
// Puis on ajoute ce qui est spécifique à la classe
|
|
||||||
// on indique qu'il faut de l'antialiasing
|
|
||||||
Graphics2D g2D = (Graphics2D) g;
|
Graphics2D g2D = (Graphics2D) g;
|
||||||
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
|
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
|
||||||
for (ObjetGraphique obj : listeObjets){
|
for (ObjetGraphique obj : listeObjets){
|
||||||
obj.Afficher(g);
|
obj.Afficher(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Affichage de l'écran Game Over
|
||||||
if (isGameOver) {
|
if (isGameOver) {
|
||||||
g2D.setColor(new Color(0, 0, 0, 150)); // Fond noir transparent
|
g2D.setColor(new Color(0, 0, 0, 150)); // Fond sombre
|
||||||
g2D.fillRect(0, 0, getWidth(), getHeight());
|
g2D.fillRect(0, 0, getWidth(), getHeight());
|
||||||
|
|
||||||
g2D.setColor(Color.WHITE);
|
g2D.setColor(Color.WHITE);
|
||||||
g2D.setFont(new Font("Arial", Font.BOLD, 50));
|
g2D.setFont(new Font("Arial", Font.BOLD, 50));
|
||||||
String msg = "GAME OVER";
|
String msg = "GAME OVER";
|
||||||
int largeurTexte = g2D.getFontMetrics().stringWidth(msg);
|
int largeur = g2D.getFontMetrics().stringWidth(msg);
|
||||||
g2D.drawString(msg, (getWidth() - largeurTexte) / 2, getHeight() / 2);
|
g2D.drawString(msg, (getWidth() - largeur) / 2, getHeight() / 2 - 50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGameOver(boolean state) {
|
public void setGameOver(boolean state) {
|
||||||
this.isGameOver = state;
|
this.isGameOver = state;
|
||||||
|
// 3. C'est ici qu'on affiche ou cache le bouton
|
||||||
|
btnRetour.setVisible(state);
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user