Phase jsp

This commit is contained in:
Erwann PHILIPPE 2025-03-27 17:15:08 +01:00
parent 0a250955b2
commit 1e9789684f
3 changed files with 45 additions and 10 deletions

View file

@ -41,7 +41,7 @@ public class Controle implements AsyncResponse {
// //
new ServeurSocket(this, GLOBAL.PORT); new ServeurSocket(this, GLOBAL.PORT);
this.frmArene = new Arene(); this.frmArene = new Arene(this);
this.frmArene.setVisible(true); this.frmArene.setVisible(true);
this.leJeu = new JeuServeur(this); this.leJeu = new JeuServeur(this);
@ -65,7 +65,7 @@ public class Controle implements AsyncResponse {
this.leJeu = new JeuClient(this); this.leJeu = new JeuClient(this);
this.leJeu.connexion(connection); this.leJeu.connexion(connection);
this.frmArene = new Arene(); this.frmArene = new Arene(this);
this.frmChoixJoueur = new ChoixJoueur(this); this.frmChoixJoueur = new ChoixJoueur(this);
this.frmChoixJoueur.setVisible(true); this.frmChoixJoueur.setVisible(true);
}else { }else {
@ -116,5 +116,13 @@ public class Controle implements AsyncResponse {
break; break;
} }
} }
public void evenementArene(String ordre, Object info) {
switch(ordre) {
case "tchat":
((JeuClient)this.leJeu).envoi("tchat" + GLOBAL.separateur + info);
break;
}
}
} }

View file

@ -172,6 +172,10 @@ public class Joueur extends Objet {
return false; return false;
} }
public String getSpeudo() {
return this.pseudo;
}
/** /**
* vrai si la vie est à 0 * vrai si la vie est à 0
* @return true si vie = 0 * @return true si vie = 0

View file

@ -11,6 +11,7 @@ import javax.swing.JFrame;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import controleur.Controle;
import controleur.GLOBAL; import controleur.GLOBAL;
import modele.Mur; import modele.Mur;
@ -19,14 +20,18 @@ import javax.swing.JTextField;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants; import javax.swing.ScrollPaneConstants;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class Arene extends JFrame { public class Arene extends JFrame {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private JPanel contentPane; private JPanel contentPane;
private JTextField textField; private JTextField txtSaisie;
private JPanel jpnMur; private JPanel jpnMur;
public JPanel jpnJeu; public JPanel jpnJeu;
public JTextArea txtChat;
private Controle controle;
/** /**
* Launch the application. * Launch the application.
@ -35,7 +40,7 @@ public class Arene extends JFrame {
/** /**
* Create the frame. * Create the frame.
*/ */
public Arene() { public Arene(Controle controle) {
setTitle("Arene"); setTitle("Arene");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().setPreferredSize(new Dimension(800, 729)); this.getContentPane().setPreferredSize(new Dimension(800, 729));
@ -77,18 +82,27 @@ public class Arene extends JFrame {
lblNewLabel.setBounds(0, 0, 792, 590); lblNewLabel.setBounds(0, 0, 792, 590);
contentPane.add(lblNewLabel); contentPane.add(lblNewLabel);
textField = new JTextField(); txtSaisie = new JTextField();
textField.setBounds(0, 591, 800, 30); txtSaisie.setBounds(0, 591, 800, 30);
contentPane.add(textField); contentPane.add(txtSaisie);
textField.setColumns(10); txtSaisie.setColumns(10);
txtSaisie.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if(!Arene.this.txtSaisie.equals("") && e.getKeyCode() == KeyEvent.VK_ENTER) {
controle.evenementArene("tchat", Arene.this.getMessage());
}
}
});
JScrollPane scrollPane = new JScrollPane(); JScrollPane scrollPane = new JScrollPane();
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setBounds(0, 620, 800, 98); scrollPane.setBounds(0, 620, 800, 98);
contentPane.add(scrollPane); contentPane.add(scrollPane);
JTextArea textArea = new JTextArea(); txtChat = new JTextArea();
scrollPane.setViewportView(textArea); scrollPane.setViewportView(txtChat);
} }
public void ajoutMurs(Object portougal) { public void ajoutMurs(Object portougal) {
jpnMur.add((JLabel)portougal); jpnMur.add((JLabel)portougal);
@ -117,4 +131,13 @@ public class Arene extends JFrame {
this.jpnJeu.add(jpnJeu); this.jpnJeu.add(jpnJeu);
this.jpnJeu.repaint(); this.jpnJeu.repaint();
} }
public String getMessage() {
return this.txtSaisie.getText();
}
public void setMessage(String msg) {
this.txtChat.setText(msg);
}
public void ajoutTchat(String Staline) {
this.txtChat.setText(this.txtChat.getText() + Staline + "\r\n");
}
} }