diff --git a/src/linea/GestionnaireBDD.java b/src/linea/GestionnaireBDD.java index 812f575..d417834 100644 --- a/src/linea/GestionnaireBDD.java +++ b/src/linea/GestionnaireBDD.java @@ -48,7 +48,10 @@ public class GestionnaireBDD { "identifiant TEXT UNIQUE NOT NULL, " + "mot_de_passe TEXT NOT NULL)"); - } catch (SQLException e) { + try { stmt.execute("ALTER TABLE utilisateurs ADD COLUMN is_admin INTEGER DEFAULT 0"); } catch (SQLException e) {} + stmt.execute("INSERT OR IGNORE INTO utilisateurs(identifiant, mot_de_passe, is_admin) VALUES('admin', 'admin', 1)"); + + } catch (SQLException e) { System.out.println("Erreur lors de l'initialisation de la base de données principale : " + e.getMessage()); } try (Statement stmtDiff = connDifficulte.createStatement()) { @@ -88,6 +91,14 @@ public class GestionnaireBDD { return -1; } + public boolean estAdmin(int userId) { + try (PreparedStatement p = conn.prepareStatement("SELECT is_admin FROM utilisateurs WHERE id = ?")) { + p.setInt(1, userId); + ResultSet rs = p.executeQuery(); + return rs.next() && rs.getInt("is_admin") == 1; + } catch (SQLException e) { return false; } + } + public boolean creerCompte(String identifiant, String motDePasse) { String checkSql = "SELECT id FROM utilisateurs WHERE identifiant = ?"; try (PreparedStatement checkPstmt = conn.prepareStatement(checkSql)) { diff --git a/src/linea/Jeu.java b/src/linea/Jeu.java index 3b35abb..777f5c1 100644 --- a/src/linea/Jeu.java +++ b/src/linea/Jeu.java @@ -37,6 +37,8 @@ public class Jeu implements KeyListener, ActionListener { protected String identifiantUtilisateurConnecte; public int idCampagneActive = 0; public int difficulteActive = 0; + public boolean modeInvincible = false; + public Jeu() { score = 0; @@ -97,6 +99,8 @@ public class Jeu implements KeyListener, ActionListener { public void setUtilisateurConnecte(int id, String identifiant) { this.utilisateurIdConnecte = id; this.identifiantUtilisateurConnecte = identifiant; + this.modeInvincible = bdd.estAdmin(id); + } public void afficherLeaderboard() { @@ -253,7 +257,7 @@ public class Jeu implements KeyListener, ActionListener { // calcule de la distance entre le centre du cercle et la ligne double distance = Math.abs(hauteurLigne - demiCercleAvant.getY()); if (distance > demiCercleAvant.getRayon()) { - gameOver(); + if (!modeInvincible) gameOver(); } } else { victoire();