création admin pour avoir Cheat Code
This commit is contained in:
@@ -48,6 +48,9 @@ public class GestionnaireBDD {
|
||||
"identifiant TEXT UNIQUE NOT NULL, " +
|
||||
"mot_de_passe TEXT NOT NULL)");
|
||||
|
||||
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());
|
||||
}
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user