Compare commits

...

11 Commits

Author SHA1 Message Date
0eea417ad2 cercle qui marche 2026-02-23 11:00:08 +01:00
008e45bb68 test cercle 2026-02-23 10:59:57 +01:00
44ac782380 campagne fonctionne 2026-02-23 10:59:28 +01:00
26850ca823 animer bulle 2026-02-23 10:52:31 +01:00
7f63cdf089 fond et bulle modif pour la campagne 2026-02-23 10:51:50 +01:00
dce34ed607 classe campOcean 2026-02-23 10:50:31 +01:00
56d4764773 creation fond ocean 2026-02-23 10:43:36 +01:00
08e68ad1ba fix campagne 4 2026-02-23 09:24:24 +01:00
6feffb79d9 Maj 2026-02-23 09:19:11 +01:00
5a974ce7ac ligne et modif bouton niveaux 2026-02-23 09:17:36 +01:00
bbb26bcb3d suppresion de bordures rouges 2026-02-23 08:59:04 +01:00
5 changed files with 167 additions and 32 deletions

View 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();
}
}

36
src/linea/FondOcean.java Normal file
View 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;
}
}
}
}

View File

@@ -16,6 +16,9 @@ public class Ligne extends ObjetGraphique{// Hérite de la classe ObjetGraphique
// nb de Segments qui composent la ligne
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
protected double xCercle = 400; // à modifier
@@ -49,7 +52,8 @@ public class Ligne extends ObjetGraphique{// Hérite de la classe ObjetGraphique
for (int i=0; i<nbSegments; i++){
// définition d'un nouveau segment
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;
@@ -64,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;
}
//-------------------------------------------------------------------------

View File

@@ -1,13 +1,21 @@
package linea;
import java.awt.*;
import java.awt.event.ActionListener;
import javax.swing.*;
public class MenuCampagne extends JPanel {
public MenuCampagne(Jeu jeu) {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setBackground(new Color(45, 45, 45)); // Même gris foncé
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);
@@ -17,42 +25,73 @@ public class MenuCampagne extends JPanel {
JButton btnC1 = creerBouton("CAMPAGNE 1");
JButton btnC2 = creerBouton("CAMPAGNE 2");
JButton btnC3 = creerBouton("CAMPAGNE 3");
JButton btnC4 = creerBouton("CAMPAGNE 4");
JButton btnRetour = creerBouton("RETOUR");
btnC1.addActionListener(e -> System.out.println("Lancement Campagne 1..."));
listeCampagnes.add(Box.createVerticalGlue());
listeCampagnes.add(titre);
listeCampagnes.add(Box.createRigidArea(new Dimension(0, 40)));
btnC2.addActionListener(e -> {
CampagneAutoroute campagne = new CampagneAutoroute(jeu);
campagne.lancerNiveau1();
});
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());
add(Box.createVerticalGlue());
add(titre);
add(Box.createRigidArea(new Dimension(0, 40)));
java.awt.event.ActionListener ouvrirNiveaux = e -> cartes.show(panneauCartes, "NIVEAUX");
btnC1.addActionListener(ouvrirNiveaux);
btnC2.addActionListener(ouvrirNiveaux);
btnC3.addActionListener(ouvrirNiveaux);
add(btnC1);
add(Box.createRigidArea(new Dimension(0, 10)));
add(btnC2);
add(Box.createRigidArea(new Dimension(0, 10)));
add(btnC3);
add(Box.createRigidArea(new Dimension(0, 10)));
add(btnC4);
btnRetourCampagnes.addActionListener(e -> cartes.show(panneauCartes, "LISTE"));
add(Box.createRigidArea(new Dimension(0, 30))); // Espace plus grand avant le retour
add(btnRetour);
btnN1.addActionListener(e -> jeu.lancerNiveau(1));
btnN2.addActionListener(e -> jeu.lancerNiveau(2));
btnN3.addActionListener(e -> jeu.lancerNiveau(3));
add(Box.createVerticalGlue());
add(panneauCartes, BorderLayout.CENTER);
}
private JButton creerBouton(String texte) {
JButton b = new JButton(texte);
b.setFont(new Font("SansSerif", Font.PLAIN, 18)); // Légèrement plus petit si tu veux
b.setFont(new Font("SansSerif", Font.PLAIN, 18));
b.setAlignmentX(Component.CENTER_ALIGNMENT);
b.setMaximumSize(new Dimension(200, 45));
b.setMaximumSize(new Dimension(240, 45));
b.setFocusable(false);
return b;
}

View File

@@ -55,13 +55,6 @@ public class ZoneDessin extends JPanel {
obj.Afficher(g);
}
// bordures haut et bas
g2D.setColor(Color.RED);
int yTop = (int)(getHeight() * 0.05);
int yBottom = (int)(getHeight() * 0.95);
g2D.drawLine(0, yTop, getWidth(), yTop);
g2D.drawLine(0, yBottom, getWidth(), yBottom);
// Affichage de l'écran Game Over
if (isGameOver) {
g2D.setColor(new Color(0, 0, 0, 150)); // Fond sombre