création admin pour avoir Cheat Code
This commit is contained in:
@@ -48,7 +48,10 @@ public class GestionnaireBDD {
|
|||||||
"identifiant TEXT UNIQUE NOT NULL, " +
|
"identifiant TEXT UNIQUE NOT NULL, " +
|
||||||
"mot_de_passe TEXT 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());
|
System.out.println("Erreur lors de l'initialisation de la base de données principale : " + e.getMessage());
|
||||||
}
|
}
|
||||||
try (Statement stmtDiff = connDifficulte.createStatement()) {
|
try (Statement stmtDiff = connDifficulte.createStatement()) {
|
||||||
@@ -88,6 +91,14 @@ public class GestionnaireBDD {
|
|||||||
return -1;
|
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) {
|
public boolean creerCompte(String identifiant, String motDePasse) {
|
||||||
String checkSql = "SELECT id FROM utilisateurs WHERE identifiant = ?";
|
String checkSql = "SELECT id FROM utilisateurs WHERE identifiant = ?";
|
||||||
try (PreparedStatement checkPstmt = conn.prepareStatement(checkSql)) {
|
try (PreparedStatement checkPstmt = conn.prepareStatement(checkSql)) {
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ public class Jeu implements KeyListener, ActionListener {
|
|||||||
protected String identifiantUtilisateurConnecte;
|
protected String identifiantUtilisateurConnecte;
|
||||||
public int idCampagneActive = 0;
|
public int idCampagneActive = 0;
|
||||||
public int difficulteActive = 0;
|
public int difficulteActive = 0;
|
||||||
|
public boolean modeInvincible = false;
|
||||||
|
|
||||||
|
|
||||||
public Jeu() {
|
public Jeu() {
|
||||||
score = 0;
|
score = 0;
|
||||||
@@ -97,6 +99,8 @@ public class Jeu implements KeyListener, ActionListener {
|
|||||||
public void setUtilisateurConnecte(int id, String identifiant) {
|
public void setUtilisateurConnecte(int id, String identifiant) {
|
||||||
this.utilisateurIdConnecte = id;
|
this.utilisateurIdConnecte = id;
|
||||||
this.identifiantUtilisateurConnecte = identifiant;
|
this.identifiantUtilisateurConnecte = identifiant;
|
||||||
|
this.modeInvincible = bdd.estAdmin(id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void afficherLeaderboard() {
|
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
|
// calcule de la distance entre le centre du cercle et la ligne
|
||||||
double distance = Math.abs(hauteurLigne - demiCercleAvant.getY());
|
double distance = Math.abs(hauteurLigne - demiCercleAvant.getY());
|
||||||
if (distance > demiCercleAvant.getRayon()) {
|
if (distance > demiCercleAvant.getRayon()) {
|
||||||
gameOver();
|
if (!modeInvincible) gameOver();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
victoire();
|
victoire();
|
||||||
|
|||||||
Reference in New Issue
Block a user