init 14: add niveau.java
This commit is contained in:
53
linea/linea/Niveau.java
Normal file
53
linea/linea/Niveau.java
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package linea;
|
||||||
|
|
||||||
|
public class Niveau {
|
||||||
|
// Propriétés d'un niveau
|
||||||
|
private int id;
|
||||||
|
private String nom;
|
||||||
|
private int vitesseLigne;
|
||||||
|
private int nbSegments;
|
||||||
|
private String image;
|
||||||
|
private int multiplicateurScore;
|
||||||
|
private String couleurCercle;
|
||||||
|
|
||||||
|
// Constructeur de la classe Niveau
|
||||||
|
public Niveau(int id, String nom, int vitesseLigne, int nbSegments, String image, int multiplicateurScore, String couleurCercle) {
|
||||||
|
this.id = id;
|
||||||
|
this.nom = nom;
|
||||||
|
this.vitesseLigne = vitesseLigne;
|
||||||
|
this.nbSegments = nbSegments;
|
||||||
|
this.image = image;
|
||||||
|
this.multiplicateurScore = multiplicateurScore;
|
||||||
|
this.couleurCercle = couleurCercle;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters pour les propriétés du niveau
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNom() {
|
||||||
|
return nom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVitesseLigne() {
|
||||||
|
return vitesseLigne;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNbSegments() {
|
||||||
|
return nbSegments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImage() {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMultiplicateurScore() {
|
||||||
|
return multiplicateurScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCouleurCercle() {
|
||||||
|
return couleurCercle;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package linea;
|
|||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
|
||||||
@@ -119,5 +120,32 @@ public class NiveauxDataConnect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// Méthode pour récupérer les niveaux depuis la base de données
|
||||||
|
// Elle retourne un niveau en fonction de son id
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
public static Niveau recupererNiveau(Connection conn, int id) {
|
||||||
|
Niveau niveauRecup = null;
|
||||||
|
String sql = "SELECT * FROM niveau WHERE id = ?;";
|
||||||
|
|
||||||
|
try (Statement stmt = conn.createStatement();
|
||||||
|
ResultSet rs = stmt.executeQuery(sql)) {
|
||||||
|
while (rs.next()) {
|
||||||
|
int id1 = rs.getInt("id");
|
||||||
|
String nom = rs.getString("nom");
|
||||||
|
int vitesse_ligne = rs.getInt("vitesse_ligne");
|
||||||
|
int nb_segments = rs.getInt("nb_segments");
|
||||||
|
String image = rs.getString("image");
|
||||||
|
int multiplicateur_score = rs.getInt("multiplicateur_score");
|
||||||
|
String couleur_cercle = rs.getString("couleur_cercle");
|
||||||
|
niveauRecup = new Niveau(id1, nom, vitesse_ligne, nb_segments, image, multiplicateur_score, couleur_cercle);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.err.println("Erreur lors de la récupération des niveaux : " + e.getMessage());
|
||||||
|
}
|
||||||
|
return niveauRecup;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user