Phase 7
This commit is contained in:
parent
cb4d3e79ee
commit
ba3ddf99a4
8 changed files with 91 additions and 22 deletions
|
|
@ -1,4 +1,8 @@
|
|||
package controleur;
|
||||
import modele.Jeu;
|
||||
import controleur.GLOBAL;
|
||||
import modele.JeuClient;
|
||||
import modele.JeuServeur;
|
||||
import outils.connexion.AsyncResponse;
|
||||
import outils.connexion.ClientSocket;
|
||||
import outils.connexion.Connection;
|
||||
|
|
@ -9,9 +13,9 @@ import vue.EntreeJeu;
|
|||
|
||||
public class Controle implements AsyncResponse {
|
||||
private EntreeJeu frmEntreeJeu ;
|
||||
public String type;
|
||||
private ChoixJoueur frmChoixJoueur;
|
||||
private Arene frmArene;
|
||||
private Jeu leJeu;
|
||||
|
||||
/**
|
||||
* Constructeur
|
||||
|
|
@ -30,18 +34,17 @@ public class Controle implements AsyncResponse {
|
|||
//
|
||||
if(info.contains("serveur")) {
|
||||
System.out.println("srv");
|
||||
type = "serveur";
|
||||
//
|
||||
new ServeurSocket(this, 6666);
|
||||
new ServeurSocket(this, GLOBAL.PORT);
|
||||
this.leJeu = new JeuServeur(this);
|
||||
|
||||
Arene areneJeu = new Arene();
|
||||
areneJeu.setVisible(true);
|
||||
frmEntreeJeu.dispose();
|
||||
}else {
|
||||
System.out.println("ip");
|
||||
type = "client";
|
||||
//
|
||||
new ClientSocket(this, info, 6666);
|
||||
new ClientSocket(this, info, GLOBAL.PORT);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -50,19 +53,32 @@ public class Controle implements AsyncResponse {
|
|||
// TODO Auto-generated method stub
|
||||
switch (ordre){
|
||||
case "connexion":
|
||||
if(type.equals("client")) {
|
||||
if(!(this.leJeu instanceof JeuServeur)) {
|
||||
frmEntreeJeu.dispose();
|
||||
this.leJeu = new JeuClient(this);
|
||||
this.leJeu.connexion(connection);
|
||||
|
||||
this.frmArene = new Arene();
|
||||
this.frmChoixJoueur = new ChoixJoueur(this);
|
||||
this.frmChoixJoueur.setVisible(true);
|
||||
}else {
|
||||
this.leJeu.connexion(connection);
|
||||
}
|
||||
break;
|
||||
case "reception":
|
||||
leJeu.reception(connection, info);
|
||||
}
|
||||
}
|
||||
public void evenementChoixJoueur(String pseudo, int numPerso) {
|
||||
//
|
||||
this.frmChoixJoueur.dispose();
|
||||
this.frmArene.setVisible(true);
|
||||
String pseudoNumPerso = "pseudo" + GLOBAL.separateur + pseudo + GLOBAL.separateur + numPerso;
|
||||
((JeuClient)this.leJeu).envoi(pseudoNumPerso);
|
||||
}
|
||||
|
||||
public void envoi(Connection connection, Object obj) {
|
||||
connection.envoi(obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
12
src/controleur/GLOBAL.java
Normal file
12
src/controleur/GLOBAL.java
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package controleur;
|
||||
|
||||
public interface GLOBAL {
|
||||
int PORT = 6666;
|
||||
|
||||
int nbPerso = 3;
|
||||
|
||||
String separateur = "~";
|
||||
|
||||
String cheminFonds = "fonds/";
|
||||
String cheminPersos = "personnages/";
|
||||
}
|
||||
|
|
@ -1,19 +1,24 @@
|
|||
package modele;
|
||||
|
||||
import controleur.Controle;
|
||||
import outils.connexion.Connection;
|
||||
/**
|
||||
* Informations et méthodes communes aux jeux client et serveur
|
||||
*
|
||||
*/
|
||||
public abstract class Jeu {
|
||||
|
||||
protected Controle controle;
|
||||
|
||||
/**
|
||||
* Réception d'une connexion (pour communiquer avec un ordinateur distant)
|
||||
*/
|
||||
public abstract void connexion() ;
|
||||
public abstract void connexion(Connection connection) ;
|
||||
|
||||
/**
|
||||
* Réception d'une information provenant de l'ordinateur distant
|
||||
*/
|
||||
public abstract void reception() ;
|
||||
public abstract void reception(Connection connection, Object info) ;
|
||||
|
||||
/**
|
||||
* Déconnexion de l'ordinateur distant
|
||||
|
|
@ -23,7 +28,8 @@ public abstract class Jeu {
|
|||
/**
|
||||
* Envoi d'une information vers un ordinateur distant
|
||||
*/
|
||||
public void envoi() {
|
||||
public void envoi(Connection connection, Object infos) {
|
||||
this.controle.envoi(connection, infos);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,31 @@
|
|||
package modele;
|
||||
|
||||
import controleur.Controle;
|
||||
import outils.connexion.Connection;
|
||||
|
||||
/**
|
||||
* Gestion du jeu côté client
|
||||
*
|
||||
*/
|
||||
public class JeuClient extends Jeu {
|
||||
|
||||
private Connection connection;
|
||||
|
||||
/**
|
||||
* Controleur
|
||||
*/
|
||||
public JeuClient() {
|
||||
|
||||
public JeuClient(Controle control) {
|
||||
this.controle = control;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connexion() {
|
||||
public void connexion(Connection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reception() {
|
||||
public void reception(Connection connection, Object info) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -27,7 +36,8 @@ public class JeuClient extends Jeu {
|
|||
* Envoi d'une information vers le serveur
|
||||
* fais appel une fois à l'envoi dans la classe Jeu
|
||||
*/
|
||||
public void envoi() {
|
||||
public void envoi(String infos) {
|
||||
super.envoi(this.connection, infos);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
package modele;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import controleur.Controle;
|
||||
import controleur.GLOBAL;
|
||||
import outils.connexion.Connection;
|
||||
|
||||
/**
|
||||
* Gestion du jeu côté serveur
|
||||
|
|
@ -14,20 +19,32 @@ public class JeuServeur extends Jeu {
|
|||
/**
|
||||
* Collection de joueurs
|
||||
*/
|
||||
private ArrayList<Joueur> lesJoueurs = new ArrayList<Joueur>() ;
|
||||
private Hashtable<Connection, Joueur> lesJoueurs = new Hashtable<Connection, Joueur>() ;
|
||||
|
||||
|
||||
private Connection connection;
|
||||
|
||||
/**
|
||||
* Constructeur
|
||||
*/
|
||||
public JeuServeur() {
|
||||
public JeuServeur(Controle control) {
|
||||
this.controle = control;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connexion() {
|
||||
public void connexion(Connection connection) {
|
||||
this.lesJoueurs.put(connection, new Joueur());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reception() {
|
||||
public void reception(Connection connection, Object info) {
|
||||
String splitted[] = ((String)info).split(GLOBAL.separateur);
|
||||
switch(splitted[0]) {
|
||||
case "pseudo":
|
||||
String pseudo = splitted[1];
|
||||
int numPerso = Integer.parseInt(splitted[2]);
|
||||
this.lesJoueurs.get(connection).initPerso(pseudo, numPerso);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -56,7 +56,11 @@ public class Joueur extends Objet {
|
|||
/**
|
||||
* Initialisation d'un joueur (pseudo et numéro, calcul de la 1ère position, affichage, création de la boule)
|
||||
*/
|
||||
public void initPerso() {
|
||||
public void initPerso(String pseudo, int numPerso) {
|
||||
this.pseudo = pseudo;
|
||||
this.numPerso = numPerso;
|
||||
|
||||
System.out.println("joueur "+pseudo+" - num perso "+numPerso+" créé");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ import javax.swing.ImageIcon;
|
|||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import controleur.GLOBAL;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JScrollPane;
|
||||
|
|
@ -43,7 +46,7 @@ public class Arene extends JFrame {
|
|||
contentPane.setLayout(null);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("");
|
||||
String chemin = "fonds/fondarene.jpg";
|
||||
String chemin = GLOBAL.cheminFonds + "fondarene.jpg";
|
||||
URL ressourceURL = getClass().getClassLoader().getResource(chemin);
|
||||
|
||||
if (ressourceURL != null) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import javax.swing.SwingConstants;
|
|||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import controleur.Controle;
|
||||
import controleur.GLOBAL;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
|
|
@ -50,7 +51,7 @@ public class ChoixJoueur extends JFrame {
|
|||
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
String chemin = "fonds/fondchoix.jpg";
|
||||
String chemin = GLOBAL.cheminFonds + "fondchoix.jpg";
|
||||
|
||||
lblPersonnage = new JLabel("");
|
||||
lblPersonnage.setBounds(141, 98, 121, 122);
|
||||
|
|
@ -158,7 +159,7 @@ public class ChoixJoueur extends JFrame {
|
|||
}
|
||||
|
||||
public void affichePerso(int numPerso) {
|
||||
String chemin = "personnages/perso"+ numPerso+ "marche1d1.gif";
|
||||
String chemin = GLOBAL.cheminPersos + "perso"+ numPerso+ "marche1d1.gif";
|
||||
URL ressourceURL = getClass().getClassLoader().getResource(chemin);
|
||||
|
||||
if (ressourceURL != null) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue