diff --git a/projet_linea/bin/BoutonsManager$1.class b/projet_linea/bin/BoutonsManager$1.class new file mode 100644 index 0000000..3e2fe9f Binary files /dev/null and b/projet_linea/bin/BoutonsManager$1.class differ diff --git a/projet_linea/bin/BoutonsManager.class b/projet_linea/bin/BoutonsManager.class new file mode 100644 index 0000000..b0101f3 Binary files /dev/null and b/projet_linea/bin/BoutonsManager.class differ diff --git a/projet_linea/bin/CadreDeConnexion.class b/projet_linea/bin/CadreDeConnexion.class index 83b5d19..61efa2f 100644 Binary files a/projet_linea/bin/CadreDeConnexion.class and b/projet_linea/bin/CadreDeConnexion.class differ diff --git a/projet_linea/bin/Cercle.class b/projet_linea/bin/Cercle.class index 66ae0ba..bfdf302 100644 Binary files a/projet_linea/bin/Cercle.class and b/projet_linea/bin/Cercle.class differ diff --git a/projet_linea/bin/Jeu.class b/projet_linea/bin/Jeu.class index bfd28c1..7590d7a 100644 Binary files a/projet_linea/bin/Jeu.class and b/projet_linea/bin/Jeu.class differ diff --git a/projet_linea/bin/Segment.class b/projet_linea/bin/Segment.class index 04d2bb2..4a55c2a 100644 Binary files a/projet_linea/bin/Segment.class and b/projet_linea/bin/Segment.class differ diff --git a/projet_linea/src/BoutonsManager.java b/projet_linea/src/BoutonsManager.java new file mode 100644 index 0000000..3d4287a --- /dev/null +++ b/projet_linea/src/BoutonsManager.java @@ -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 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("Nouveau utilisateur :")); + createBox.add(newUserField); + createBox.add(Box.createVerticalStrut(15)); + createBox.add(new JLabel("Mot de passe :")); + 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; + } +} \ No newline at end of file diff --git a/projet_linea/src/CadreDeConnexion.java b/projet_linea/src/CadreDeConnexion.java index a959bd9..501567c 100644 --- a/projet_linea/src/CadreDeConnexion.java +++ b/projet_linea/src/CadreDeConnexion.java @@ -30,11 +30,7 @@ public class CadreDeConnexion extends JFrame { JPasswordField passField = new JPasswordField(15); passField.setMaximumSize(new Dimension(250, 30)); - 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); + JButton loginBtn = BoutonsManager.creerBoutonConnexion(userField, passField, this); // 4. Ajout des composants avec des espaces (Struts) box.add(titre); @@ -48,91 +44,11 @@ public class CadreDeConnexion extends JFrame { box.add(loginBtn); box.add(Box.createVerticalStrut(10)); - 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); + JButton createBtn = BoutonsManager.creerBoutonCreerCompte(this); box.add(createBtn); panel.add(box); // Ajoute la boîte au centre du GridBagLayout - // 5. Logique du bouton - loginBtn.addActionListener(e -> { - String user = userField.getText(); - String pass = new String(passField.getPassword()); - int userId = GestionBDD.verifierConnexion(user, pass); - - if (userId != -1) { - dispose(); - Jeu jeu = new Jeu(userId); - jeu.demarrer(); - } else { - JOptionPane.showMessageDialog(this, "Acces refuse"); - } - }); - - 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 = new JButton("Créer"); - createAccountBtn.setBackground(new Color(70, 130, 180)); - createAccountBtn.setForeground(Color.WHITE); - createAccountBtn.setFocusPainted(false); - createAccountBtn.setAlignmentX(Component.CENTER_ALIGNMENT); - - createBox.add(createTitre); - createBox.add(Box.createVerticalStrut(30)); - createBox.add(new JLabel("Nouvel utilisateur :")); - createBox.add(newUserField); - createBox.add(Box.createVerticalStrut(15)); - createBox.add(new JLabel("Mot de passe :")); - createBox.add(newPassField); - createBox.add(Box.createVerticalStrut(30)); - createBox.add(createAccountBtn); - - createPanel.add(createBox); - - createAccountBtn.addActionListener(e -> { - String u = newUserField.getText().trim(); - String p = new String(newPassField.getPassword()); - if (u.isEmpty() || p.isEmpty()) { - JOptionPane.showMessageDialog(createFrame, "Utilisateur et mot de passe requis"); - return; - } - - boolean ok = GestionBDD.creerUtilisateur(u, p); - if (ok) { - JOptionPane.showMessageDialog(createFrame, "Compte cree avec succes."); - createFrame.dispose(); - } else { - JOptionPane.showMessageDialog(createFrame, "Échec : le nom d'utilisateur existe deja ou erreur."); - } - }); - - createFrame.setVisible(true); - }); - setVisible(true); } } diff --git a/projet_linea/src/Cercle.java b/projet_linea/src/Cercle.java index cea411a..2d45f36 100644 --- a/projet_linea/src/Cercle.java +++ b/projet_linea/src/Cercle.java @@ -36,6 +36,9 @@ public class Cercle extends ObjetGraphique{ // il s'agit plutôt d'arcs de cercl //sol du cercle protected double sol = 600; + + // Mode triche : désactive la gravité + protected boolean modeTriche = false; //------------------------------------------------------------------------- // METHODES //------------------------------------------------------------------------- @@ -115,10 +118,12 @@ public class Cercle extends ObjetGraphique{ // il s'agit plutôt d'arcs de cercl void Animer() { // pas est à prendre comme un "delta t" - // chute libre - vitesse = vitesse + 9.81 * pas; + if (!modeTriche) { + // chute libre + vitesse = vitesse + 9.81 * pas; + } - // impulsion + // impulsion (toujours appliquée, même en triche ?) if (montee==true) { vitesse = vitesse - impulsion *pas; } @@ -147,6 +152,14 @@ public class Cercle extends ObjetGraphique{ // il s'agit plutôt d'arcs de cercl public void resetVitesse(){ 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 + } + } diff --git a/projet_linea/src/Jeu.java b/projet_linea/src/Jeu.java index a166073..61e828c 100644 --- a/projet_linea/src/Jeu.java +++ b/projet_linea/src/Jeu.java @@ -142,6 +142,8 @@ public class Jeu implements KeyListener, ActionListener{ if(keyCode==32){//touche espace modeTriche =!modeTriche; labTriche.setVisible(modeTriche); //afficher ou cacher le label + demiCercleAvant.setModeTriche(modeTriche); + demiCercleArriere.setModeTriche(modeTriche); } } @@ -198,7 +200,7 @@ public class Jeu implements KeyListener, ActionListener{ ecran.requestFocusInWindow(); 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); @@ -291,6 +293,13 @@ public class Jeu implements KeyListener, ActionListener{ this.ecran.traiterBoucleAnimation(); this.laLigne.actualiserSegCourant(); + // Mode triche : centrer le cercle sur le milieu du segment courant + if (modeTriche && this.laLigne.getSegCourant() != null) { + double milieuY = this.laLigne.getSegCourant().getMilieuY(); + this.demiCercleAvant.y = milieuY; + this.demiCercleArriere.y = milieuY; + } + // 2. On vérifie si la ligne traverse bien le cercle boolean verification = this.laLigne.estDansCercle(this.demiCercleAvant); diff --git a/projet_linea/src/Segment.java b/projet_linea/src/Segment.java index 9dd6abf..60374da 100644 --- a/projet_linea/src/Segment.java +++ b/projet_linea/src/Segment.java @@ -32,6 +32,11 @@ public class Segment extends ObjetGraphique { // Hérite de la classe ObjetGraph yLong = yyLong; } + // 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 //-------------------------------------------------------------------------