update mode TRiche by ISmael

This commit is contained in:
2026-03-27 15:34:53 +01:00
15 changed files with 209 additions and 21 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,149 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
public class BoutonsManager {
// Méthode pour créer le bouton des scores utilisateur
public static JButton creerBoutonScores(JFrame fenetre, int utilisateurId) {
JButton boutonScores = new JButton("Voir mes scores");
// Style
boutonScores.setBackground(Color.BLACK);
boutonScores.setForeground(Color.WHITE);
// Position
boutonScores.setBounds(300, 20, 160, 30);
// Action au clic
boutonScores.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
List<Integer> scores = GestionBDD.recupererScoresUtilisateur(utilisateurId);
int meilleurScore = GestionBDD.recupererMeilleurScoreUtilisateur(utilisateurId);
StringBuilder message = new StringBuilder();
message.append("Meilleur score : ").append(meilleurScore).append("\n\n");
message.append("Tous les scores :\n");
for (int score : scores) {
message.append(score).append("\n");
}
JOptionPane.showMessageDialog(
fenetre,
message.toString(),
"Mes Scores",
JOptionPane.INFORMATION_MESSAGE
);
}
});
return boutonScores;
}
// Méthode pour créer le bouton de connexion
public static JButton creerBoutonConnexion(JTextField userField, JPasswordField passField, JFrame cadre) {
JButton loginBtn = new JButton("Entrer");
loginBtn.setBackground(new Color(70, 130, 180)); // Bleu acier
loginBtn.setForeground(Color.WHITE);
loginBtn.setFocusPainted(false);
loginBtn.setAlignmentX(Component.CENTER_ALIGNMENT);
loginBtn.addActionListener(e -> {
String user = userField.getText();
String pass = new String(passField.getPassword());
int userId = GestionBDD.verifierConnexion(user, pass);
if (userId != -1) {
cadre.dispose();
Jeu jeu = new Jeu(userId);
jeu.demarrer();
} else {
JOptionPane.showMessageDialog(cadre, "Acces refuse");
}
});
return loginBtn;
}
// Méthode pour créer le bouton "Créer un compte"
public static JButton creerBoutonCreerCompte(JFrame cadre) {
JButton createBtn = new JButton("Créer un compte");
createBtn.setBackground(new Color(70, 130, 180));
createBtn.setForeground(Color.WHITE);
createBtn.setFocusPainted(false);
createBtn.setAlignmentX(Component.CENTER_ALIGNMENT);
createBtn.addActionListener(evt -> {
JFrame createFrame = new JFrame("Creation de compte");
createFrame.setSize(800, 600);
createFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
createFrame.setLocationRelativeTo(null);
JPanel createPanel = new JPanel(new GridBagLayout());
createPanel.setBackground(new Color(30, 30, 30));
createFrame.add(createPanel);
Box createBox = Box.createVerticalBox();
JLabel createTitre = new JLabel("CREATION DE COMPTE");
createTitre.setForeground(Color.WHITE);
createTitre.setFont(new Font("Arial", Font.BOLD, 24));
createTitre.setAlignmentX(Component.CENTER_ALIGNMENT);
JTextField newUserField = new JTextField(15);
newUserField.setMaximumSize(new Dimension(250, 30));
JPasswordField newPassField = new JPasswordField(15);
newPassField.setMaximumSize(new Dimension(250, 30));
JButton createAccountBtn = creerBoutonCreerCompteFinal(newUserField, newPassField, createFrame);
createBox.add(createTitre);
createBox.add(Box.createVerticalStrut(30));
createBox.add(new JLabel("<html><font color='white'>Nouveau utilisateur :</font></html>"));
createBox.add(newUserField);
createBox.add(Box.createVerticalStrut(15));
createBox.add(new JLabel("<html><font color='white'>Mot de passe :</font></html>"));
createBox.add(newPassField);
createBox.add(Box.createVerticalStrut(30));
createBox.add(createAccountBtn);
createPanel.add(createBox);
createFrame.setVisible(true);
});
return createBtn;
}
// Méthode pour créer le bouton "Créer" dans la fenêtre de création de compte
private static JButton creerBoutonCreerCompteFinal(JTextField newUserField, JPasswordField newPassField, JFrame createFrame) {
JButton createAccountBtn = new JButton("Créer");
createAccountBtn.setBackground(new Color(70, 130, 180));
createAccountBtn.setForeground(Color.WHITE);
createAccountBtn.setFocusPainted(false);
createAccountBtn.setAlignmentX(Component.CENTER_ALIGNMENT);
createAccountBtn.addActionListener(e -> {
String newUser = newUserField.getText();
String newPass = new String(newPassField.getPassword());
if (!newUser.isEmpty() && !newPass.isEmpty()) {
boolean success = GestionBDD.creerUtilisateur(newUser, newPass);
if (success) {
JOptionPane.showMessageDialog(createFrame, "Compte créé avec succès !");
createFrame.dispose();
} else {
JOptionPane.showMessageDialog(createFrame, "Erreur lors de la création du compte.");
}
} else {
JOptionPane.showMessageDialog(createFrame, "Veuillez remplir tous les champs.");
}
});
return createAccountBtn;
}
}

View File

@@ -5,10 +5,12 @@ import javax.swing.*;
public class CadreDeConnexion extends JFrame { public class CadreDeConnexion extends JFrame {
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Méthode peremttant de charger(récupérer) l'image îcone depuis Ressources // Méthode peremttant de charger(récupérer) l'image îcone depuis Ressources
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
private Image chargerImageDepuisRessource(String cheminRessource) { private Image chargerImageDepuisRessource(String cheminRessource) {
// Cette méthode doit seulement charger l'image, pas rappeler elle-même.
try { try {
URL url = getClass().getResource(cheminRessource); URL url = getClass().getResource(cheminRessource);
if (url != null) { if (url != null) {
@@ -28,10 +30,10 @@ public class CadreDeConnexion extends JFrame {
// 1. On change l'icône de CETTE fenêtre (this) // 1. On change l'icône de CETTE fenêtre (this)
Image imageConnexion = chargerImageDepuisRessource("/images/icone.png"); Image imageConnexion = chargerImageDepuisRessource("/images/icone.png");
// Si l'image est différent de null, on modifie l'icone de notre application
// Et on l'applique comme image de fond
if (imageConnexion != null) { if (imageConnexion != null) {
// On applique la même image comme icône de la fenêtre
this.setIconImage(imageConnexion); this.setIconImage(imageConnexion);
// On prépare aussi le fond pour le panneau de connexion
panelBackground = new Background(imageConnexion); panelBackground = new Background(imageConnexion);
} }
@@ -41,10 +43,11 @@ public class CadreDeConnexion extends JFrame {
setDefaultCloseOperation(EXIT_ON_CLOSE); setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null); // Centre la fenêtre setLocationRelativeTo(null); // Centre la fenêtre
// 3. Style du panneau principal (Gris foncé) // 2. Style du panneau principal (Gris foncé)
// JPanel panel = new JPanel(new GridBagLayout()); // On utilise ZoneDessin pour pouvoir dessiner l'image en fond
JPanel panel = new ZoneDessin(panelBackground); JPanel panel = new ZoneDessin(panelBackground);
panel.setLayout(new GridBagLayout()); panel.setLayout(new GridBagLayout());
setContentPane(panel);
// Conteneur pour les éléments (pour les empiler verticalement) // Conteneur pour les éléments (pour les empiler verticalement)
Box box = Box.createVerticalBox(); Box box = Box.createVerticalBox();
@@ -61,11 +64,7 @@ public class CadreDeConnexion extends JFrame {
JPasswordField passField = new JPasswordField(15); JPasswordField passField = new JPasswordField(15);
passField.setMaximumSize(new Dimension(250, 30)); passField.setMaximumSize(new Dimension(250, 30));
JButton loginBtn = new JButton("Entrer"); JButton loginBtn = BoutonsManager.creerBoutonConnexion(userField, passField, this);
loginBtn.setBackground(new Color(70, 130, 180)); // Bleu acier
loginBtn.setForeground(Color.WHITE);
loginBtn.setFocusPainted(false);
loginBtn.setAlignmentX(Component.CENTER_ALIGNMENT);
// 5. Ajout des composants avec des espaces (Struts) // 5. Ajout des composants avec des espaces (Struts)
box.add(titre); box.add(titre);
@@ -79,17 +78,12 @@ public class CadreDeConnexion extends JFrame {
box.add(loginBtn); box.add(loginBtn);
box.add(Box.createVerticalStrut(10)); box.add(Box.createVerticalStrut(10));
JButton createBtn = new JButton("Créer un compte"); JButton createBtn = BoutonsManager.creerBoutonCreerCompte(this);
createBtn.setBackground(new Color(70, 130, 180));
createBtn.setForeground(Color.WHITE);
createBtn.setFocusPainted(false);
createBtn.setAlignmentX(Component.CENTER_ALIGNMENT);
box.add(createBtn); box.add(createBtn);
panel.add(box); // Ajoute la boîte au centre du GridBagLayout panel.add(box); // Ajoute la boîte au centre du GridBagLayout
setContentPane(panel); // Branche enfin le panneau personnalisé à la fenêtre
// 6. Logique du bouton // 5. Logique du bouton
loginBtn.addActionListener(e -> { loginBtn.addActionListener(e -> {
String user = userField.getText(); String user = userField.getText();
String pass = new String(passField.getPassword()); String pass = new String(passField.getPassword());
@@ -110,14 +104,17 @@ public class CadreDeConnexion extends JFrame {
createFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); createFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
createFrame.setLocationRelativeTo(null); createFrame.setLocationRelativeTo(null);
// On recharge la même image pour la fenêtre de création de compte
// afin de lui donner à la fois l'icône et le fond d'écran.
Background panelBackgroundCreation = null;
Image imageCreation = chargerImageDepuisRessource("/images/icone.png"); Image imageCreation = chargerImageDepuisRessource("/images/icone.png");
if (imageCreation != null) { if (imageCreation != null) {
createFrame.setIconImage(imageCreation); createFrame.setIconImage(imageCreation);
panelBackgroundCreation = new Background(imageCreation);
} }
Background panelBackgroundCreation = (imageCreation != null) ? new Background(imageCreation) : null;
// Même principe que pour la page de connexion : le fond est dessiné par ZoneDessin
JPanel createPanel = new ZoneDessin(panelBackgroundCreation); JPanel createPanel = new ZoneDessin(panelBackgroundCreation);
// JPanel createPanel = new JPanel(new GridBagLayout());
createPanel.setLayout(new GridBagLayout()); createPanel.setLayout(new GridBagLayout());
createFrame.setContentPane(createPanel); createFrame.setContentPane(createPanel);

View File

@@ -37,6 +37,9 @@ public class Cercle extends ObjetGraphique{ // il s'agit plutôt d'arcs de cercl
//sol du cercle //sol du cercle
protected double sol = 600; protected double sol = 600;
// Mode triche : désactive la gravité
protected boolean modeTriche = false;
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// METHODES // METHODES
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@@ -76,7 +79,7 @@ public class Cercle extends ObjetGraphique{ // il s'agit plutôt d'arcs de cercl
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Méthod epour mettre à jour la gravité du cercle depuis la classe // Méthode pour mettre à jour la gravité du cercle depuis la classe
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
public void setGravite(double nouvelleGravite) { public void setGravite(double nouvelleGravite) {
this.gravite = nouvelleGravite; this.gravite = nouvelleGravite;
@@ -125,7 +128,7 @@ public class Cercle extends ObjetGraphique{ // il s'agit plutôt d'arcs de cercl
// chute libre // chute libre
vitesse = vitesse + gravite * pas; vitesse = vitesse + gravite * pas;
// impulsion // impulsion (toujours appliquée, même en triche ?)
if (montee==true) { if (montee==true) {
vitesse = vitesse - impulsion *pas; vitesse = vitesse - impulsion *pas;
} }
@@ -155,6 +158,14 @@ public class Cercle extends ObjetGraphique{ // il s'agit plutôt d'arcs de cercl
vitesse = 0; vitesse = 0;
} }
// Méthode pour activer/désactiver le mode triche
public void setModeTriche(boolean triche) {
this.modeTriche = triche;
if (triche) {
this.vitesse = 0; // Réinitialiser la vitesse quand on active le triche
}
}
} }

View File

@@ -62,6 +62,10 @@ public class Jeu implements KeyListener, ActionListener{
// Constructeur de la classe // Constructeur de la classe
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
public Jeu(int utilisateurId){ public Jeu(int utilisateurId){
// Créer les tables de la base de données si elles n'existent pas
GestionBDD.creerTableUtilisateurSiAbsente();
GestionBDD.creerTableScoreSiAbsente();
JFrame fenetre = new JFrame(); JFrame fenetre = new JFrame();
this.utilisateurId = utilisateurId; this.utilisateurId = utilisateurId;
@@ -139,6 +143,8 @@ public class Jeu implements KeyListener, ActionListener{
if(keyCode==32){//touche espace if(keyCode==32){//touche espace
modeTriche =!modeTriche; modeTriche =!modeTriche;
labTriche.setVisible(modeTriche); //afficher ou cacher le label labTriche.setVisible(modeTriche); //afficher ou cacher le label
demiCercleAvant.setModeTriche(modeTriche);
demiCercleArriere.setModeTriche(modeTriche);
} }
} }
@@ -195,7 +201,7 @@ public class Jeu implements KeyListener, ActionListener{
ecran.requestFocusInWindow(); ecran.requestFocusInWindow();
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
javax.swing.JButton boutonscores = BoutonScoresUtilisateur.creerBouton(fenetre, utilisateurId); javax.swing.JButton boutonscores = BoutonsManager.creerBoutonScores(fenetre, utilisateurId);
this.ecran.add(boutonscores); this.ecran.add(boutonscores);
@@ -300,6 +306,16 @@ public class Jeu implements KeyListener, ActionListener{
this.ecran.traiterBoucleAnimation(); this.ecran.traiterBoucleAnimation();
this.laLigne.actualiserSegCourant(); this.laLigne.actualiserSegCourant();
// Mode triche : Le cercle suit la ligne
// On utilisera le calcul pour déterminer si la ligne traverse le cercle
if (modeTriche && this.laLigne.getSegCourant() != null) {
// double yPoint = this.getSegCourant().y + (this.SegCourant.yLong / this.SegCourant.xLong) * (this.xCercle - this.SegCourant.x);
double yPointTricheArrire = this.laLigne.getSegCourant().getY() + (this.laLigne.getSegCourant().getYLong() / this.laLigne.getSegCourant().getXLong()) * (this.demiCercleArriere.getX() - this.laLigne.getSegCourant().getX());
double yPointTricheAvant = this.laLigne.getSegCourant().getY() + (this.laLigne.getSegCourant().getYLong() / this.laLigne.getSegCourant().getXLong()) * (this.demiCercleAvant.getX() - this.laLigne.getSegCourant().getX());
this.demiCercleAvant.y = yPointTricheArrire ;
this.demiCercleArriere.y = yPointTricheAvant;
}
// 2. On vérifie si la ligne traverse bien le cercle // 2. On vérifie si la ligne traverse bien le cercle
boolean verification = this.laLigne.estDansCercle(this.demiCercleAvant); boolean verification = this.laLigne.estDansCercle(this.demiCercleAvant);

View File

@@ -173,6 +173,7 @@ public class Ligne extends ObjetGraphique{// Hérite de la classe ObjetGraphique
} }
return dansCercle; return dansCercle;
} }
public Segment getSegCourant() { public Segment getSegCourant() {
return this.SegCourant; return this.SegCourant;
} }

View File

@@ -9,4 +9,5 @@ public class LineaAppli {
} }
} }

View File

@@ -32,6 +32,19 @@ public class Segment extends ObjetGraphique { // Hérite de la classe ObjetGraph
yLong = yyLong; yLong = yyLong;
} }
public double getYLong(){
return this.yLong;
}
public double getXLong(){
return this.xLong;
}
// Méthode pour obtenir la position Y au milieu du segment
public double getMilieuY() {
return y + yLong / 2;
}
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Redéfinition de la méthode Afficher, spécifiquement pour la classe // Redéfinition de la méthode Afficher, spécifiquement pour la classe
//------------------------------------------------------------------------- //-------------------------------------------------------------------------