Phase 6 : fenêtre ChoixJoueur
This commit is contained in:
parent
d948887a72
commit
cb4d3e79ee
2 changed files with 116 additions and 23 deletions
|
|
@ -10,6 +10,8 @@ import vue.EntreeJeu;
|
|||
public class Controle implements AsyncResponse {
|
||||
private EntreeJeu frmEntreeJeu ;
|
||||
public String type;
|
||||
private ChoixJoueur frmChoixJoueur;
|
||||
private Arene frmArene;
|
||||
|
||||
/**
|
||||
* Constructeur
|
||||
|
|
@ -40,9 +42,6 @@ public class Controle implements AsyncResponse {
|
|||
type = "client";
|
||||
//
|
||||
new ClientSocket(this, info, 6666);
|
||||
|
||||
|
||||
//frmEntreeJeu.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -53,12 +52,17 @@ public class Controle implements AsyncResponse {
|
|||
case "connexion":
|
||||
if(type.equals("client")) {
|
||||
frmEntreeJeu.dispose();
|
||||
Arene frmArene = new Arene();
|
||||
ChoixJoueur frmChoixJoueur = new ChoixJoueur();
|
||||
frmChoixJoueur.setVisible(true);
|
||||
this.frmArene = new Arene();
|
||||
this.frmChoixJoueur = new ChoixJoueur(this);
|
||||
this.frmChoixJoueur.setVisible(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void evenementChoixJoueur(String pseudo, int numPerso) {
|
||||
//
|
||||
this.frmChoixJoueur.dispose();
|
||||
this.frmArene.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,18 +6,30 @@ import java.nio.charset.StandardCharsets;
|
|||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import controleur.Controle;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.ImageIcon;
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class ChoixJoueur extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JPanel contentPane;
|
||||
private Controle control;
|
||||
private JLabel lblPersonnage;
|
||||
private int persoNum = 1;
|
||||
private int nbPerso = 3;
|
||||
private JTextField txtPseudo;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
|
|
@ -26,7 +38,7 @@ public class ChoixJoueur extends JFrame {
|
|||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public ChoixJoueur() {
|
||||
public ChoixJoueur(Controle ctrl) {
|
||||
setTitle("Choice");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.getContentPane().setPreferredSize(new Dimension(400, 275));
|
||||
|
|
@ -38,27 +50,34 @@ public class ChoixJoueur extends JFrame {
|
|||
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("");
|
||||
String chemin = "fonds/fondchoix.jpg";
|
||||
URL ressourceURL = getClass().getClassLoader().getResource(chemin);
|
||||
|
||||
if (ressourceURL != null) {
|
||||
String ressource = URLDecoder.decode(ressourceURL.getPath(), StandardCharsets.UTF_8);
|
||||
lblNewLabel.setIcon(new ImageIcon(ressource));
|
||||
} else {
|
||||
System.out.println("❌ Image non trouvée !");
|
||||
}
|
||||
|
||||
lblNewLabel.setBounds(0, 0, 396, 261);
|
||||
contentPane.add(lblNewLabel);
|
||||
lblPersonnage = new JLabel("");
|
||||
lblPersonnage.setBounds(141, 98, 121, 122);
|
||||
lblPersonnage.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
contentPane.add(lblPersonnage);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("");
|
||||
lblNewLabel_1.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if(persoNum+1 <= nbPerso) {
|
||||
persoNum++;
|
||||
affichePerso(persoNum);
|
||||
} else {
|
||||
persoNum = 1;
|
||||
affichePerso(persoNum);
|
||||
}
|
||||
System.out.println("Suivant");
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
sourisNormale();
|
||||
}
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
sourisDoigt();
|
||||
}
|
||||
});
|
||||
lblNewLabel_1.setBackground(new Color(128, 255, 0));
|
||||
lblNewLabel_1.setBounds(293, 108, 93, 81);
|
||||
|
|
@ -68,8 +87,23 @@ public class ChoixJoueur extends JFrame {
|
|||
lblNewLabel_1_1.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if(persoNum-1 >= 1) {
|
||||
persoNum--;
|
||||
affichePerso(persoNum);
|
||||
} else {
|
||||
persoNum = 3;
|
||||
affichePerso(persoNum);
|
||||
}
|
||||
System.out.println("Précédent");
|
||||
}
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
sourisDoigt();
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
sourisNormale();
|
||||
}
|
||||
});
|
||||
lblNewLabel_1_1.setBackground(new Color(128, 255, 0));
|
||||
lblNewLabel_1_1.setBounds(10, 96, 93, 81);
|
||||
|
|
@ -79,13 +113,68 @@ public class ChoixJoueur extends JFrame {
|
|||
lblNewLabel_2.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
Arene arena = new Arene();
|
||||
arena.setVisible(true);
|
||||
ChoixJoueur.this.dispose();
|
||||
|
||||
if(txtPseudo.getText().length() == 0) {
|
||||
JOptionPane.showMessageDialog(null, "La saisie du pseudo est obligatoire !");
|
||||
txtPseudo.requestFocus();
|
||||
}else {
|
||||
ctrl.evenementChoixJoueur(txtPseudo.getText(), nbPerso);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
sourisDoigt();
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
sourisNormale();
|
||||
}
|
||||
});
|
||||
lblNewLabel_2.setBounds(293, 200, 103, 61);
|
||||
contentPane.add(lblNewLabel_2);
|
||||
}
|
||||
|
||||
txtPseudo = new JTextField();
|
||||
txtPseudo.setColumns(10);
|
||||
txtPseudo.setBounds(141, 235, 121, 25);
|
||||
contentPane.add(txtPseudo);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("");
|
||||
lblNewLabel.setBounds(0, 0, 396, 261);
|
||||
contentPane.add(lblNewLabel);
|
||||
|
||||
affichePerso(persoNum);
|
||||
|
||||
URL ressourceURL = getClass().getClassLoader().getResource(chemin);
|
||||
|
||||
if (ressourceURL != null) {
|
||||
String ressource = URLDecoder.decode(ressourceURL.getPath(), StandardCharsets.UTF_8);
|
||||
lblNewLabel.setIcon(new ImageIcon(ressource));
|
||||
} else {
|
||||
System.out.println("❌ Image non trouvée !");
|
||||
}
|
||||
|
||||
control = ctrl;
|
||||
|
||||
}
|
||||
|
||||
public void affichePerso(int numPerso) {
|
||||
String chemin = "personnages/perso"+ numPerso+ "marche1d1.gif";
|
||||
URL ressourceURL = getClass().getClassLoader().getResource(chemin);
|
||||
|
||||
if (ressourceURL != null) {
|
||||
String ressource = URLDecoder.decode(ressourceURL.getPath(), StandardCharsets.UTF_8);
|
||||
lblPersonnage.setIcon(new ImageIcon(ressource));
|
||||
} else {
|
||||
System.out.println("❌ Image non trouvée !");
|
||||
}
|
||||
}
|
||||
|
||||
public void sourisNormale() {
|
||||
//
|
||||
contentPane.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
}
|
||||
public void sourisDoigt() {
|
||||
//
|
||||
contentPane.setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue