updateBoule/immortel
This commit is contained in:
@@ -1,13 +1,29 @@
|
||||
package linea;
|
||||
|
||||
import java.awt.GridLayout;
|
||||
import java.util.List;
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
public class LineaAppli {
|
||||
|
||||
private static class SelectionJeu {
|
||||
final int idCompte;
|
||||
final boolean modeCampagne;
|
||||
|
||||
SelectionJeu(int idCompte, boolean modeCampagne) {
|
||||
this.idCompte = idCompte;
|
||||
this.modeCampagne = modeCampagne;
|
||||
}
|
||||
}
|
||||
|
||||
private static String choisirPseudo(DatabaseConnection db, String message, int messageType) {
|
||||
List<String> pseudos = db.getPseudos();
|
||||
if (pseudos.isEmpty()) {
|
||||
@@ -50,7 +66,38 @@ public class LineaAppli {
|
||||
if (result == JOptionPane.OK_OPTION) {
|
||||
return list.getSelectedIndex() + 1;
|
||||
}
|
||||
return 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static int choisirNiveauCampagne(DatabaseConnection db, int idCompte) {
|
||||
int niveauMaxDebloque = db.getNiveauDebloqueCampagne(idCompte);
|
||||
if (niveauMaxDebloque < 1) {
|
||||
niveauMaxDebloque = 1;
|
||||
}
|
||||
|
||||
String[] niveaux = new String[niveauMaxDebloque];
|
||||
for (int i = 1; i <= niveauMaxDebloque; i++) {
|
||||
niveaux[i - 1] = genererLabelNiveau(i);
|
||||
}
|
||||
|
||||
JList<String> list = new JList<>(niveaux);
|
||||
list.setSelectedIndex(niveauMaxDebloque - 1);
|
||||
list.setVisibleRowCount(15);
|
||||
JScrollPane scrollPane = new JScrollPane(list);
|
||||
scrollPane.setPreferredSize(new java.awt.Dimension(350, 350));
|
||||
|
||||
int result = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
scrollPane,
|
||||
"🏆 Campagne - Niveaux débloqués (1 à " + niveauMaxDebloque + ")",
|
||||
JOptionPane.OK_CANCEL_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE
|
||||
);
|
||||
|
||||
if (result == JOptionPane.OK_OPTION) {
|
||||
return list.getSelectedIndex() + 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static String genererLabelNiveau(int niveau) {
|
||||
@@ -129,6 +176,63 @@ public class LineaAppli {
|
||||
}
|
||||
}
|
||||
|
||||
private static SelectionJeu choisirCompteEtModeRapide(DatabaseConnection db) {
|
||||
while (true) {
|
||||
List<String> pseudos = db.getPseudos();
|
||||
|
||||
JPanel panel = new JPanel(new GridLayout(0, 1, 8, 8));
|
||||
panel.add(new JLabel("Compte :"));
|
||||
|
||||
String[] optionsCompte = new String[pseudos.size() + 2];
|
||||
optionsCompte[0] = "Sans compte";
|
||||
for (int i = 0; i < pseudos.size(); i++) {
|
||||
optionsCompte[i + 1] = pseudos.get(i);
|
||||
}
|
||||
optionsCompte[optionsCompte.length - 1] = "Gérer les comptes...";
|
||||
|
||||
JComboBox<String> comboCompte = new JComboBox<>(optionsCompte);
|
||||
panel.add(comboCompte);
|
||||
|
||||
panel.add(new JLabel("Mode :"));
|
||||
JRadioButton modeClassique = new JRadioButton("Classique", true);
|
||||
JRadioButton modeCampagne = new JRadioButton("Campagne");
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
group.add(modeClassique);
|
||||
group.add(modeCampagne);
|
||||
|
||||
JPanel panelMode = new JPanel(new GridLayout(1, 2, 8, 0));
|
||||
panelMode.add(modeClassique);
|
||||
panelMode.add(modeCampagne);
|
||||
panel.add(panelMode);
|
||||
|
||||
int result = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
panel,
|
||||
"Jouer rapidement",
|
||||
JOptionPane.OK_CANCEL_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE
|
||||
);
|
||||
|
||||
if (result != JOptionPane.OK_OPTION) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String choixCompte = (String) comboCompte.getSelectedItem();
|
||||
if (choixCompte == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ("Gérer les comptes...".equals(choixCompte)) {
|
||||
menuComptes(db);
|
||||
continue;
|
||||
}
|
||||
|
||||
int idCompte = "Sans compte".equals(choixCompte) ? -1 : db.getIdParPseudo(choixCompte);
|
||||
boolean campagne = modeCampagne.isSelected();
|
||||
return new SelectionJeu(idCompte, campagne);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Classe de base de l'application, rien à modifier ici
|
||||
//-------------------------------------------------------------------------
|
||||
@@ -140,31 +244,37 @@ public class LineaAppli {
|
||||
db.createTables();
|
||||
|
||||
while (true) {
|
||||
Object[] options = {"Comptes", "Sans compte", "Quitter"};
|
||||
int choix = JOptionPane.showOptionDialog(null,
|
||||
"Choisissez une action :",
|
||||
"Menu", JOptionPane.DEFAULT_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
|
||||
|
||||
if (choix == JOptionPane.CLOSED_OPTION || choix == 2) {
|
||||
SelectionJeu selection = choisirCompteEtModeRapide(db);
|
||||
if (selection == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (choix) {
|
||||
case 1 -> {
|
||||
int niveau = choisirNiveau();
|
||||
new Jeu(db, -1, niveau).demarrer();
|
||||
if (!selection.modeCampagne) {
|
||||
int niveau = choisirNiveau();
|
||||
if (niveau > 0) {
|
||||
new Jeu(db, selection.idCompte, niveau).demarrer();
|
||||
return;
|
||||
}
|
||||
case 0 -> {
|
||||
Integer idCompte = menuComptes(db);
|
||||
if (idCompte != null) {
|
||||
int niveau = choisirNiveau();
|
||||
new Jeu(db, idCompte, niveau).demarrer();
|
||||
return;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (selection.idCompte > 0) {
|
||||
int niveau = choisirNiveauCampagne(db, selection.idCompte);
|
||||
if (niveau > 0) {
|
||||
new Jeu(db, selection.idCompte, niveau, true).demarrer();
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"Campagne sans compte : progression non sauvegardée.",
|
||||
"Campagne",
|
||||
JOptionPane.INFORMATION_MESSAGE
|
||||
);
|
||||
new Jeu(db, -1, 1, true).demarrer();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user