2025-03-06 14:24:29 +00:00
|
|
|
package controleur;
|
2025-03-17 13:24:32 +00:00
|
|
|
import modele.Jeu;
|
|
|
|
|
import controleur.GLOBAL;
|
|
|
|
|
import modele.JeuClient;
|
|
|
|
|
import modele.JeuServeur;
|
2025-03-11 08:28:09 +00:00
|
|
|
import outils.connexion.AsyncResponse;
|
|
|
|
|
import outils.connexion.ClientSocket;
|
|
|
|
|
import outils.connexion.Connection;
|
|
|
|
|
import outils.connexion.ServeurSocket;
|
|
|
|
|
import vue.Arene;
|
|
|
|
|
import vue.ChoixJoueur;
|
2025-03-06 14:24:29 +00:00
|
|
|
import vue.EntreeJeu;
|
|
|
|
|
|
2025-03-11 08:28:09 +00:00
|
|
|
public class Controle implements AsyncResponse {
|
2025-03-06 14:24:29 +00:00
|
|
|
private EntreeJeu frmEntreeJeu ;
|
2025-03-11 10:13:51 +00:00
|
|
|
private ChoixJoueur frmChoixJoueur;
|
|
|
|
|
private Arene frmArene;
|
2025-03-17 13:24:32 +00:00
|
|
|
private Jeu leJeu;
|
2025-03-06 14:24:29 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructeur
|
|
|
|
|
*/
|
|
|
|
|
private Controle() {
|
2025-03-11 08:28:09 +00:00
|
|
|
this.frmEntreeJeu = new EntreeJeu(this) ;
|
2025-03-06 14:24:29 +00:00
|
|
|
this.frmEntreeJeu.setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
new Controle();
|
|
|
|
|
}
|
2025-03-11 08:28:09 +00:00
|
|
|
|
|
|
|
|
public void evenementEntreeJeu(String info) {
|
|
|
|
|
//
|
|
|
|
|
if(info.contains("serveur")) {
|
|
|
|
|
System.out.println("srv");
|
|
|
|
|
//
|
2025-03-17 13:24:32 +00:00
|
|
|
new ServeurSocket(this, GLOBAL.PORT);
|
2025-03-17 16:11:47 +00:00
|
|
|
|
|
|
|
|
this.frmArene = new Arene();
|
|
|
|
|
this.frmArene.setVisible(true);
|
|
|
|
|
|
2025-03-17 13:24:32 +00:00
|
|
|
this.leJeu = new JeuServeur(this);
|
2025-03-17 16:11:47 +00:00
|
|
|
((JeuServeur)this.leJeu).constructionMurs();
|
2025-03-11 08:28:09 +00:00
|
|
|
|
|
|
|
|
frmEntreeJeu.dispose();
|
|
|
|
|
}else {
|
|
|
|
|
System.out.println("ip");
|
|
|
|
|
//
|
2025-03-17 13:24:32 +00:00
|
|
|
new ClientSocket(this, info, GLOBAL.PORT);
|
2025-03-11 08:28:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void reception(Connection connection, String ordre, Object info) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
switch (ordre){
|
|
|
|
|
case "connexion":
|
2025-03-17 13:24:32 +00:00
|
|
|
if(!(this.leJeu instanceof JeuServeur)) {
|
2025-03-11 08:28:09 +00:00
|
|
|
frmEntreeJeu.dispose();
|
2025-03-17 13:24:32 +00:00
|
|
|
this.leJeu = new JeuClient(this);
|
|
|
|
|
this.leJeu.connexion(connection);
|
|
|
|
|
|
2025-03-11 10:13:51 +00:00
|
|
|
this.frmArene = new Arene();
|
|
|
|
|
this.frmChoixJoueur = new ChoixJoueur(this);
|
|
|
|
|
this.frmChoixJoueur.setVisible(true);
|
2025-03-17 13:24:32 +00:00
|
|
|
}else {
|
|
|
|
|
this.leJeu.connexion(connection);
|
2025-03-11 08:28:09 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2025-03-17 13:24:32 +00:00
|
|
|
case "reception":
|
|
|
|
|
leJeu.reception(connection, info);
|
2025-03-11 08:28:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
2025-03-11 10:13:51 +00:00
|
|
|
public void evenementChoixJoueur(String pseudo, int numPerso) {
|
|
|
|
|
//
|
|
|
|
|
this.frmChoixJoueur.dispose();
|
|
|
|
|
this.frmArene.setVisible(true);
|
2025-03-17 13:24:32 +00:00
|
|
|
String pseudoNumPerso = "pseudo" + GLOBAL.separateur + pseudo + GLOBAL.separateur + numPerso;
|
|
|
|
|
((JeuClient)this.leJeu).envoi(pseudoNumPerso);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void envoi(Connection connection, Object obj) {
|
|
|
|
|
connection.envoi(obj);
|
2025-03-11 10:13:51 +00:00
|
|
|
}
|
2025-03-17 16:11:47 +00:00
|
|
|
|
|
|
|
|
public void evenementJeuServeur(String ordre, Object info) {
|
|
|
|
|
switch(ordre) {
|
|
|
|
|
case "ajout mur":
|
|
|
|
|
this.frmArene.ajoutMurs(info);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-06 14:24:29 +00:00
|
|
|
|
|
|
|
|
}
|