فهرست منبع

Remise formatage Linux

Loquicom 6 سال پیش
والد
کامیت
c811c4781a

+ 30 - 30
client/file/css/map.css

@@ -1,31 +1,31 @@
-table{
-	border-collapse: collapse;
-}
-
-td, img, tr{
-	border-collapse: collapse;
-	margin: 0px;
-	padding: 0px;
-	border: none;
-	position: relative;
-}
-
-img{
-	vertical-align:bottom
-}
-
-#game{
-  	position: absolute;
-	top: 50%; left: 50%;
-  	transform: translate(-50%, -50%);
-}
-
-#hud{
-	position: absolute;
-	z-index: 10;
-	margin-top: 1.5em;
-	margin-left: 1.5em;
-	font-size: 2em;
-	font-style: arial;
-	color: white;
+table{
+	border-collapse: collapse;
+}
+
+td, img, tr{
+	border-collapse: collapse;
+	margin: 0px;
+	padding: 0px;
+	border: none;
+	position: relative;
+}
+
+img{
+	vertical-align:bottom
+}
+
+#game{
+  	position: absolute;
+	top: 50%; left: 50%;
+  	transform: translate(-50%, -50%);
+}
+
+#hud{
+	position: absolute;
+	z-index: 10;
+	margin-top: 1.5em;
+	margin-left: 1.5em;
+	font-size: 2em;
+	font-style: arial;
+	color: white;
 }

+ 14 - 14
client/file/css/menu.css

@@ -1,14 +1,14 @@
- button{
-	width: 100%;
-	color: black;
-	height: 10em;
-}
-
-body{
-	margin-top: 50vh;
-  	transform: translateY(-50%);
-}
-
-#select{
-	border: 5px blue solid;
-}
+ button{
+	width: 100%;
+	color: black;
+	height: 10em;
+}
+
+body{
+	margin-top: 50vh;
+  	transform: translateY(-50%);
+}
+
+#select{
+	border: 5px blue solid;
+}

+ 102 - 102
client/src/bs/Create.java

@@ -1,102 +1,102 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package bs;
-
-import bswfx.BomberStudent;
-import bswfx.ScreenManager;
-import javafx.scene.input.KeyCode;
-import javafx.scene.input.KeyEvent;
-import org.json.JSONArray;
-import org.json.JSONObject;
-
-/**
- *
- * @author loquicom
- */
-public class Create {
-
-    public static final int NAME_MODE = 0;
-    public static final int CHOOSE_MODE = 1;
-
-    protected int mode = NAME_MODE;
-    protected String name = "";
-    protected JSONArray maps;
-    protected int selected = 0;
-
-    public Create() {
-        ScreenManager.setScreen(ScreenManager.CREATE_SCREEN);
-    }
-
-    public int getMode() {
-        return this.mode;
-    }
-
-    public void changeMode(int mode) {
-        if (mode == CHOOSE_MODE) {
-            BomberStudent.bsc.send("GET", "game/list");
-            JSONObject res = BomberStudent.bsc.receive();
-            this.maps = res.getJSONArray("maps");
-        }
-        this.mode = mode;
-    }
-
-    public void generateName(KeyEvent ke) {
-        if (ke.getCode() == KeyCode.BACK_SPACE) {
-            if (this.name.length() > 0) {
-                this.name = this.name.substring(0, this.name.length() - 1);
-            }
-        } else {
-            this.name += ke.getText();
-        }
-    }
-
-    public void up() {
-        if (this.selected == 0) {
-            this.selected = this.maps.length();
-        }
-        this.selected--;
-    }
-
-    public void down() {
-        if (this.selected == this.maps.length() - 1) {
-            this.selected = -1;
-        }
-        this.selected++;
-    }
-
-    public void createGame() {
-        JSONObject param = new JSONObject();
-        param.put("name", this.name);
-        param.put("map", this.maps.getString(this.selected));
-        BomberStudent.bsc.send("POST", "game/create", param);
-        JSONObject res = BomberStudent.bsc.receive();
-        if (res.getInt("status") != 201) {
-            System.err.println("Impossible de créer la partie");
-            BomberStudent.end();
-        }
-        //Creation game
-        BomberStudent.game = new Game(res);
-        ScreenManager.setScreen(ScreenManager.GAME_SCREEN);
-    }
-
-    public String toHtml() {
-        if (this.mode == NAME_MODE) {
-            return "<div style=\"margin-top: 48vh\"><h1 style=\"font-family: Arial\"><div style=\"text-align: center\">Entrez un nom :<br>" + this.name + "</div></h1></div>";
-        } else {
-            String html = "<!DOCTYPE html><html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"file:" + System.getProperty("user.dir") + "/file/css/menu.css\"></head><body>";
-            for (int i = 0; i < this.maps.length(); i++) {
-                html += "<button id=\"id" + i + "\" disabled>" + this.maps.getString(i) + "</button>";
-            }
-            html += "</body></html>";
-            return html.replaceAll("id" + this.selected, "select");
-        }
-    }
-
-    public void show() {
-        BomberStudent.wfx.loadHtml(this.toHtml());
-    }
-
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package bs;
+
+import bswfx.BomberStudent;
+import bswfx.ScreenManager;
+import javafx.scene.input.KeyCode;
+import javafx.scene.input.KeyEvent;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+/**
+ *
+ * @author loquicom
+ */
+public class Create {
+
+    public static final int NAME_MODE = 0;
+    public static final int CHOOSE_MODE = 1;
+
+    protected int mode = NAME_MODE;
+    protected String name = "";
+    protected JSONArray maps;
+    protected int selected = 0;
+
+    public Create() {
+        ScreenManager.setScreen(ScreenManager.CREATE_SCREEN);
+    }
+
+    public int getMode() {
+        return this.mode;
+    }
+
+    public void changeMode(int mode) {
+        if (mode == CHOOSE_MODE) {
+            BomberStudent.bsc.send("GET", "game/list");
+            JSONObject res = BomberStudent.bsc.receive();
+            this.maps = res.getJSONArray("maps");
+        }
+        this.mode = mode;
+    }
+
+    public void generateName(KeyEvent ke) {
+        if (ke.getCode() == KeyCode.BACK_SPACE) {
+            if (this.name.length() > 0) {
+                this.name = this.name.substring(0, this.name.length() - 1);
+            }
+        } else {
+            this.name += ke.getText();
+        }
+    }
+
+    public void up() {
+        if (this.selected == 0) {
+            this.selected = this.maps.length();
+        }
+        this.selected--;
+    }
+
+    public void down() {
+        if (this.selected == this.maps.length() - 1) {
+            this.selected = -1;
+        }
+        this.selected++;
+    }
+
+    public void createGame() {
+        JSONObject param = new JSONObject();
+        param.put("name", this.name);
+        param.put("map", this.maps.getString(this.selected));
+        BomberStudent.bsc.send("POST", "game/create", param);
+        JSONObject res = BomberStudent.bsc.receive();
+        if (res.getInt("status") != 201) {
+            System.err.println("Impossible de créer la partie");
+            BomberStudent.end();
+        }
+        //Creation game
+        BomberStudent.game = new Game(res);
+        ScreenManager.setScreen(ScreenManager.GAME_SCREEN);
+    }
+
+    public String toHtml() {
+        if (this.mode == NAME_MODE) {
+            return "<div style=\"margin-top: 48vh\"><h1 style=\"font-family: Arial\"><div style=\"text-align: center\">Entrez un nom :<br>" + this.name + "</div></h1></div>";
+        } else {
+            String html = "<!DOCTYPE html><html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"file:" + System.getProperty("user.dir") + "/file/css/menu.css\"></head><body>";
+            for (int i = 0; i < this.maps.length(); i++) {
+                html += "<button id=\"id" + i + "\" disabled>" + this.maps.getString(i) + "</button>";
+            }
+            html += "</body></html>";
+            return html.replaceAll("id" + this.selected, "select");
+        }
+    }
+
+    public void show() {
+        BomberStudent.wfx.loadHtml(this.toHtml());
+    }
+
+}

+ 570 - 570
client/src/bs/Game.java

@@ -1,570 +1,570 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package bs;
-
-import bswfx.BomberStudent;
-import bswfx.ScreenManager;
-import java.util.HashMap;
-import org.json.JSONArray;
-import org.json.JSONObject;
-import wfx.WebFx;
-
-/**
- *
- * @author loquicom
- */
-public class Game {
-
-    protected HashMap<Integer, Player> player = new HashMap<>();
-    protected int mainPlayer;
-    protected int width;
-    protected int height;
-    protected String map[][];
-
-    public Game(JSONObject jo) {
-        //Recup la map
-        JSONObject joMap = jo.getJSONObject("map");
-        this.width = joMap.getInt("width");
-        this.height = joMap.getInt("height");
-        this.map = this.parseMap(joMap.getString("content"));
-        //Creation joueur principale
-        JSONObject joPlayer = jo.getJSONObject("player");
-        Player p = new Player(joPlayer, jo.getString("startPos"));
-        this.player.put(joPlayer.getInt("id"), p);
-        this.map[p.getX()][p.getY()] = "" + p.getId();
-        this.mainPlayer = p.getId();
-        //Creation autre joueurs
-        if (jo.has("players")) {
-            JSONArray ja = jo.getJSONArray("players");
-            for (int i = 0; i < ja.length(); i++) {
-                joPlayer = ja.getJSONObject(i);
-                int id = joPlayer.getInt("id");
-                if (id != this.mainPlayer) {
-                    p = new Player(id, joPlayer.getString("pos"));
-                    this.player.put(id, p);
-                    this.map[p.getX()][p.getY()] = "" + id;
-                }
-            }
-        }
-    }
-
-    /* --- Méthodes jeu --- */
-    public void join(int id, String pos) {
-        Player p = new Player(id, pos);
-        this.player.put(id, p);
-        this.map[p.getX()][p.getY()] = "" + id;
-    }
-
-    public boolean move(int player, int dir) {
-        //Recup le joueur
-        Player p = this.player.get(player);
-        if (p == null) {
-            return false;
-        }
-        //Calcul nouvelle coord
-        int x = p.getX();
-        int y = p.getY();
-        switch (dir) {
-            case Player.UP:
-                if (y > 0) {
-                    y--;
-                }
-                break;
-            case Player.LEFT:
-                if (x > 0) {
-                    x--;
-                }
-                break;
-            case Player.DOWN:
-                if (y < this.height - 1) {
-                    y++;
-                }
-                break;
-            case Player.RIGHT:
-                if (x < this.width - 1) {
-                    x++;
-                }
-                break;
-            default:
-                return false;
-        }
-        //Regarde si le joueur marche sur un objet
-        switch (this.map[x][y]) {
-            case "cb":
-                this.getObject(Player.CLASSIC);
-                break;
-            case "mb":
-                this.getObject(Player.MINE);
-                break;
-            case "rb":
-                this.getObject(Player.REMOTE);
-                break;
-            case "bu":
-                this.getObject(Player.BOMBUP);
-                break;
-            case "bd":
-                this.getObject(Player.BOMBDOWN);
-                break;
-            case "f":
-                this.getObject(Player.FIREPOWER);
-                break;
-            case "s":
-                this.getObject(Player.SCOOTER);
-                break;
-            case "bl":
-                this.getObject(Player.BROKENLEG);
-                break;
-            case "i":
-                this.getObject(Player.MAJOR);
-                break;
-            case "lm":
-                this.getObject(Player.LIFEMAX);
-                break;
-            case "lu":
-                this.getObject(Player.LIFEUP);
-                break;
-        }
-        //Deplacement
-        p.setDir(dir);
-        this.map[x][y] = "" + p.getId();
-        this.map[p.getX()][p.getY()] = "_";
-        //Met à jour le joueur
-        p.setX(x);
-        p.setY(y);
-        return true;
-    }
-
-    public boolean newBomb(int type, String coord) {
-        //Recup la position
-        int pos[] = this.parseCoord(coord);
-        //Met la bombe sur la map
-        switch (type) {
-            case Player.CLASSIC:
-                this.map[pos[0]][pos[1]] = "b";
-                break;
-            case Player.MINE:
-                this.map[pos[0]][pos[1]] = "m";
-                break;
-            case Player.REMOTE:
-                this.map[pos[0]][pos[1]] = "r";
-                break;
-            default:
-                return false;
-        }
-        return true;
-    }
-
-    public void removeBomb(String coord) {
-        int pos[] = this.parseCoord(coord);
-        if (this.map[pos[0]][pos[1]].equals("b") || this.map[pos[0]][pos[1]].equals("m") || this.map[pos[0]][pos[1]].equals("r")) {
-            this.map[pos[0]][pos[1]] = "_";
-        }
-    }
-
-    public boolean newObject(int type, String coord) {
-        //Recup la position
-        int pos[] = this.parseCoord(coord);
-        //Met la bombe sur la map
-        switch (type) {
-            case Player.CLASSIC:
-                this.map[pos[0]][pos[1]] = "cb";
-                break;
-            case Player.MINE:
-                this.map[pos[0]][pos[1]] = "mb";
-                break;
-            case Player.REMOTE:
-                this.map[pos[0]][pos[1]] = "rb";
-                break;
-            case Player.BOMBUP:
-                this.map[pos[0]][pos[1]] = "bu";
-                break;
-            case Player.BOMBDOWN:
-                this.map[pos[0]][pos[1]] = "bd";
-                break;
-            case Player.FIREPOWER:
-                this.map[pos[0]][pos[1]] = "f";
-                break;
-            case Player.SCOOTER:
-                this.map[pos[0]][pos[1]] = "s";
-                break;
-            case Player.BROKENLEG:
-                this.map[pos[0]][pos[1]] = "bl";
-                break;
-            case Player.MAJOR:
-                this.map[pos[0]][pos[1]] = "i";
-                break;
-            case Player.LIFEUP:
-                this.map[pos[0]][pos[1]] = "lu";
-                break;
-            case Player.LIFEMAX:
-                this.map[pos[0]][pos[1]] = "lm";
-                break;
-            default:
-                return false;
-        }
-        return true;
-    }
-
-    public boolean getObject(int type) {
-        JSONObject param = new JSONObject();
-        //Creation json en fonction type
-        switch (type) {
-            case Player.CLASSIC:
-                param.put("type", "bomb");
-                param.put("class", "classic");
-                break;
-            case Player.MINE:
-                param.put("type", "bomb");
-                param.put("class", "mine");
-                break;
-            case Player.REMOTE:
-                param.put("type", "bomb");
-                param.put("class", "remote");
-                break;
-            case Player.BOMBUP:
-                param.put("type", "bonusMalus");
-                param.put("class", "bomb_up");
-                break;
-            case Player.BOMBDOWN:
-                param.put("type", "bonusMalus");
-                param.put("class", "bomb_down");
-                break;
-            case Player.FIREPOWER:
-                param.put("type", "bonusMalus");
-                param.put("class", "fire_power");
-                break;
-            case Player.SCOOTER:
-                param.put("type", "bonusMalus");
-                param.put("class", "scooter");
-                break;
-            case Player.BROKENLEG:
-                param.put("type", "bonusMalus");
-                param.put("class", "broken_legs");
-                break;
-            case Player.MAJOR:
-                param.put("type", "bonusMalus");
-                param.put("class", "major");
-                break;
-            case Player.LIFEUP:
-                param.put("type", "bonusMalus");
-                param.put("class", "life_up");
-                break;
-            case Player.LIFEMAX:
-                param.put("type", "bonusMalus");
-                param.put("class", "life_max");
-                break;
-            default:
-                return false;
-        }
-        //Envoi
-        if (!BomberStudent.bsc.send("POST", "object/new", param)) {
-            return false;
-        }
-        //Reception
-        JSONObject res = BomberStudent.bsc.receive();
-        if (res.getInt("status") != 201) {
-            return false;
-        }
-        //MaJ joueur
-        Player p = this.player.get(this.mainPlayer);
-        p.setLife(res.getInt("life"));
-        p.setMaxLife(res.getInt("maxLife"));
-        p.setSpeed(res.getInt("speed"));
-        p.setBomb(res.getInt("currentNbClassicBomb"));
-        p.setMine(res.getInt("currentNbMine"));
-        p.setRemote(res.getInt("currentNbRemoteBomb"));
-        p.setMaxBomb(res.getInt("maxNbBomb"));
-        //Ajout bonus
-        if (type == Player.FIREPOWER) {
-            p.setFirepower(p.getFirepower() + 1);
-        } else if (type == Player.MAJOR) {
-            p.setMajor(true);
-        }
-        return true;
-    }
-
-    public void updateMap(String mapContent) {
-        String map[][] = this.parseMap(mapContent);
-        //Compare les 2 cartes
-        for (int i = 0; i < height; i++) {
-            for (int j = 0; j < width; j++) {
-                if (this.map[j][i].equals("*")) {
-                    this.map[j][i] = map[j][i];
-                }
-            }
-        }
-    }
-
-    public void updateLife(int newLife) {
-        Player p = this.player.get(this.mainPlayer);
-        //Si non invincible
-        if (!p.isMajor()) {
-            if (newLife > 0) {
-                p.setLife(newLife);
-            } else {
-                this.gameOver();
-            }
-        }
-    }
-
-    public boolean quit(int id) {
-        //Recup joueur
-        Player p = this.player.get(id);
-        if (p == null) {
-            return false;
-        }
-        //Le retire
-        this.player.remove(id);
-        this.map[p.getX()][p.getY()] = "_";
-        return true;
-    }
-    
-    public void gameOver(){
-        //Quitte la partie
-        BomberStudent.bsc.send("POST", "game/quit");
-        //Change l'ecran
-        ScreenManager.setScreen(ScreenManager.END_SCREEN);
-        WebFx.wait.set(true);
-        BomberStudent.wfx.loadHtml("<div style=\"margin-top: 48vh\"><h1 style=\"font-family: Arial\"><div style=\"text-align: center\">GAME OVER<br>Press any key...</div></h1></div>");
-        BomberStudent.waitWfx();
-        BomberStudent.menu = new Menu();
-        BomberStudent.menu.show();
-    }
-    
-    public void explosion(JSONArray explo){
-        int x, y;
-        JSONObject pos;
-        //Ajout explosion map
-        for(int i = 0; i < explo.length(); i++){
-            pos = explo.getJSONObject(i);
-            x = pos.getInt("x");
-            y = pos.getInt("y");
-            this.map[x][y] = "e" + this.map[x][y];
-        }
-        //Timer pour la retirer
-        Thread t = new Thread(new Runnable() {
-            @Override
-            public void run() {
-                try{
-                    Thread.sleep(1000);
-                } catch (Exception ex) {
-                    
-                }
-                BomberStudent.game.removeExplosion();
-                BomberStudent.updateWindow();
-            }
-        });
-        t.start();
-    }
-    
-    public void removeExplosion(){
-        for (int i = 0; i < height; i++) {
-            for (int j = 0; j < width; j++) {
-                if(this.map[j][i].charAt(0) == 'e'){
-                    this.map[j][i] = this.map[j][i].substring(1);
-                }
-            }
-        }
-    }
-
-    /* --- Méthodes affichage --- */
-    public String toHtml() {
-        Player pl = this.player.get(this.mainPlayer);
-        String html = "<!DOCTYPE html><html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"file:" + System.getProperty("user.dir") + "/file/css/map.css\"></head><body><div id=\"game\">";
-        html += "<div id=\"hud\">" + pl.getLife() + "/" + pl.getMaxLife() + "</div>";
-        html += "<table><tbody>";
-        for (int i = 0; i < height; i++) {
-            html += "<tr>";
-            for (int j = 0; j < width; j++) {
-                html += "<td><img src=\"file:" + System.getProperty("user.dir") + "/";
-                switch (this.map[j][i].charAt(0)) {
-                    case 'e':
-                        html += "file/sprite/explosion.png";
-                        break;
-                    case '_':
-                        html += "file/sprite/sol.png";
-                        break;
-                    case '-':
-                        html += "file/sprite/limite.png";
-                        break;
-                    case '*':
-                        html += "file/sprite/mur.png";
-                        break;
-                    case 'b':
-                        switch (this.map[j][i]) {
-                            case "bu":
-                                html += "file/sprite/bomb_up.png";
-                                break;
-                            case "bd":
-                                html += "file/sprite/bomb_down.png";
-                                break;
-                            case "bl":
-                                html += "file/sprite/broken_leg.png";
-                                break;
-                            default:
-                                html += "file/sprite/bomb.png";
-                                break;
-                        }
-                        break;
-                    case 'm':
-                        switch (this.map[j][i]) {
-                            case "mb":
-                                html += "file/sprite/mine_bomb.png";
-                                break;
-                            default:
-                                html += "file/sprite/mine.png";
-                                break;
-                        }
-                        break;
-                    case 'r':
-                        switch (this.map[j][i]) {
-                            case "rb":
-                                html += "file/sprite/remote_bomb.png";
-                                break;
-                            default:
-                                html += "file/sprite/remote.png";
-                                break;
-                        }
-                        break;
-                    case 'c':
-                        html += "file/sprite/classic_bomb.png";
-                        break;
-                    case 'f':
-                        html += "file/sprite/fire_power.png";
-                        break;
-                    case 's':
-                        html += "file/sprite/scooter.png";
-                        break;
-                    case 'i':
-                        html += "file/sprite/major.png";
-                        break;
-                    case 'l':
-                        switch (this.map[j][i]) {
-                            case "lu":
-                                html += "file/sprite/life_up.png";
-                                break;
-                            default:
-                                html += "file/sprite/life_max.png";
-                                break;
-                        }
-                        break;
-                    case '0':
-                    case '1':
-                    case '2':
-                    case '3':
-                    case '4':
-                    case '5':
-                    case '6':
-                    case '7':
-                    case '8':
-                    case '9':
-                        Player p = this.player.get(Integer.parseInt(this.map[j][i]));
-                        if (p.isMain()) {
-                            html += "file/sprite/player_";
-                            if(p.isMajor()){
-                                html += "m";
-                            }
-                            switch(p.dir){
-                                case Player.UP:
-                                    html += "u.png";
-                                    break;
-                                case Player.LEFT:
-                                    html += "l.png";
-                                    break;
-                                case Player.DOWN:
-                                    html += "d.png";
-                                    break;
-                                case Player.RIGHT:
-                                    html += "r.png";
-                                    break;
-                            }
-                        } else {
-                            html += "file/sprite/other_";
-                            switch(p.dir){
-                                case Player.UP:
-                                    html += "u.png";
-                                    break;
-                                case Player.LEFT:
-                                    html += "l.png";
-                                    break;
-                                case Player.DOWN:
-                                    html += "d.png";
-                                    break;
-                                case Player.RIGHT:
-                                    html += "r.png";
-                                    break;
-                            }
-                        }
-                        break;
-                }
-                html += "\"></td>";
-            }
-            html += "</tr>";
-        }
-        html += "</tbody></table></div></body></html>";
-        return html;
-    }
-
-    public void showMap() {
-        for (int i = 0; i < height; i++) {
-            for (int j = 0; j < width; j++) {
-                System.out.print(this.map[j][i]);
-            }
-            System.out.println("");
-        }
-    }
-
-    /* --- Getter/Setter --- */
-    public Player getPlayer(int index) {
-        return this.player.get(index);
-    }
-
-    public int getMainPlayerId() {
-        return this.mainPlayer;
-    }
-
-    public int getHeight() {
-        return this.height;
-    }
-
-    public int getWidth() {
-        return this.width;
-    }
-
-    /* --- Methodes privée --- */
-    private String[][] parseMap(String mapContent) {
-        String[][] map = new String[this.width][this.height];
-        for (int i = 0; i < this.height; i++) {
-            for (int j = 0; j < this.width; j++) {
-                map[j][i] = "" + mapContent.charAt((i * this.width) + j);
-            }
-        }
-        return map;
-    }
-
-    private int[] parseCoord(String coord) {
-        int res[] = new int[2];
-        //Cherche le separateur
-        int pos = 0;
-        while (pos < coord.length()) {
-            if (coord.charAt(pos) == ',') {
-                break;
-            }
-            pos++;
-        }
-        //Si pas de separateur
-        if (pos == coord.length()) {
-            return null;
-        }
-        //Recup les 2 string + extraction int
-        String substr1 = coord.substring(0, pos);
-        String substr2 = coord.substring(pos + 1);
-        res[0] = Integer.parseInt(substr1);
-        res[1] = Integer.parseInt(substr2);
-        return res;
-    }
-
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package bs;
+
+import bswfx.BomberStudent;
+import bswfx.ScreenManager;
+import java.util.HashMap;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import wfx.WebFx;
+
+/**
+ *
+ * @author loquicom
+ */
+public class Game {
+
+    protected HashMap<Integer, Player> player = new HashMap<>();
+    protected int mainPlayer;
+    protected int width;
+    protected int height;
+    protected String map[][];
+
+    public Game(JSONObject jo) {
+        //Recup la map
+        JSONObject joMap = jo.getJSONObject("map");
+        this.width = joMap.getInt("width");
+        this.height = joMap.getInt("height");
+        this.map = this.parseMap(joMap.getString("content"));
+        //Creation joueur principale
+        JSONObject joPlayer = jo.getJSONObject("player");
+        Player p = new Player(joPlayer, jo.getString("startPos"));
+        this.player.put(joPlayer.getInt("id"), p);
+        this.map[p.getX()][p.getY()] = "" + p.getId();
+        this.mainPlayer = p.getId();
+        //Creation autre joueurs
+        if (jo.has("players")) {
+            JSONArray ja = jo.getJSONArray("players");
+            for (int i = 0; i < ja.length(); i++) {
+                joPlayer = ja.getJSONObject(i);
+                int id = joPlayer.getInt("id");
+                if (id != this.mainPlayer) {
+                    p = new Player(id, joPlayer.getString("pos"));
+                    this.player.put(id, p);
+                    this.map[p.getX()][p.getY()] = "" + id;
+                }
+            }
+        }
+    }
+
+    /* --- Méthodes jeu --- */
+    public void join(int id, String pos) {
+        Player p = new Player(id, pos);
+        this.player.put(id, p);
+        this.map[p.getX()][p.getY()] = "" + id;
+    }
+
+    public boolean move(int player, int dir) {
+        //Recup le joueur
+        Player p = this.player.get(player);
+        if (p == null) {
+            return false;
+        }
+        //Calcul nouvelle coord
+        int x = p.getX();
+        int y = p.getY();
+        switch (dir) {
+            case Player.UP:
+                if (y > 0) {
+                    y--;
+                }
+                break;
+            case Player.LEFT:
+                if (x > 0) {
+                    x--;
+                }
+                break;
+            case Player.DOWN:
+                if (y < this.height - 1) {
+                    y++;
+                }
+                break;
+            case Player.RIGHT:
+                if (x < this.width - 1) {
+                    x++;
+                }
+                break;
+            default:
+                return false;
+        }
+        //Regarde si le joueur marche sur un objet
+        switch (this.map[x][y]) {
+            case "cb":
+                this.getObject(Player.CLASSIC);
+                break;
+            case "mb":
+                this.getObject(Player.MINE);
+                break;
+            case "rb":
+                this.getObject(Player.REMOTE);
+                break;
+            case "bu":
+                this.getObject(Player.BOMBUP);
+                break;
+            case "bd":
+                this.getObject(Player.BOMBDOWN);
+                break;
+            case "f":
+                this.getObject(Player.FIREPOWER);
+                break;
+            case "s":
+                this.getObject(Player.SCOOTER);
+                break;
+            case "bl":
+                this.getObject(Player.BROKENLEG);
+                break;
+            case "i":
+                this.getObject(Player.MAJOR);
+                break;
+            case "lm":
+                this.getObject(Player.LIFEMAX);
+                break;
+            case "lu":
+                this.getObject(Player.LIFEUP);
+                break;
+        }
+        //Deplacement
+        p.setDir(dir);
+        this.map[x][y] = "" + p.getId();
+        this.map[p.getX()][p.getY()] = "_";
+        //Met à jour le joueur
+        p.setX(x);
+        p.setY(y);
+        return true;
+    }
+
+    public boolean newBomb(int type, String coord) {
+        //Recup la position
+        int pos[] = this.parseCoord(coord);
+        //Met la bombe sur la map
+        switch (type) {
+            case Player.CLASSIC:
+                this.map[pos[0]][pos[1]] = "b";
+                break;
+            case Player.MINE:
+                this.map[pos[0]][pos[1]] = "m";
+                break;
+            case Player.REMOTE:
+                this.map[pos[0]][pos[1]] = "r";
+                break;
+            default:
+                return false;
+        }
+        return true;
+    }
+
+    public void removeBomb(String coord) {
+        int pos[] = this.parseCoord(coord);
+        if (this.map[pos[0]][pos[1]].equals("b") || this.map[pos[0]][pos[1]].equals("m") || this.map[pos[0]][pos[1]].equals("r")) {
+            this.map[pos[0]][pos[1]] = "_";
+        }
+    }
+
+    public boolean newObject(int type, String coord) {
+        //Recup la position
+        int pos[] = this.parseCoord(coord);
+        //Met la bombe sur la map
+        switch (type) {
+            case Player.CLASSIC:
+                this.map[pos[0]][pos[1]] = "cb";
+                break;
+            case Player.MINE:
+                this.map[pos[0]][pos[1]] = "mb";
+                break;
+            case Player.REMOTE:
+                this.map[pos[0]][pos[1]] = "rb";
+                break;
+            case Player.BOMBUP:
+                this.map[pos[0]][pos[1]] = "bu";
+                break;
+            case Player.BOMBDOWN:
+                this.map[pos[0]][pos[1]] = "bd";
+                break;
+            case Player.FIREPOWER:
+                this.map[pos[0]][pos[1]] = "f";
+                break;
+            case Player.SCOOTER:
+                this.map[pos[0]][pos[1]] = "s";
+                break;
+            case Player.BROKENLEG:
+                this.map[pos[0]][pos[1]] = "bl";
+                break;
+            case Player.MAJOR:
+                this.map[pos[0]][pos[1]] = "i";
+                break;
+            case Player.LIFEUP:
+                this.map[pos[0]][pos[1]] = "lu";
+                break;
+            case Player.LIFEMAX:
+                this.map[pos[0]][pos[1]] = "lm";
+                break;
+            default:
+                return false;
+        }
+        return true;
+    }
+
+    public boolean getObject(int type) {
+        JSONObject param = new JSONObject();
+        //Creation json en fonction type
+        switch (type) {
+            case Player.CLASSIC:
+                param.put("type", "bomb");
+                param.put("class", "classic");
+                break;
+            case Player.MINE:
+                param.put("type", "bomb");
+                param.put("class", "mine");
+                break;
+            case Player.REMOTE:
+                param.put("type", "bomb");
+                param.put("class", "remote");
+                break;
+            case Player.BOMBUP:
+                param.put("type", "bonusMalus");
+                param.put("class", "bomb_up");
+                break;
+            case Player.BOMBDOWN:
+                param.put("type", "bonusMalus");
+                param.put("class", "bomb_down");
+                break;
+            case Player.FIREPOWER:
+                param.put("type", "bonusMalus");
+                param.put("class", "fire_power");
+                break;
+            case Player.SCOOTER:
+                param.put("type", "bonusMalus");
+                param.put("class", "scooter");
+                break;
+            case Player.BROKENLEG:
+                param.put("type", "bonusMalus");
+                param.put("class", "broken_legs");
+                break;
+            case Player.MAJOR:
+                param.put("type", "bonusMalus");
+                param.put("class", "major");
+                break;
+            case Player.LIFEUP:
+                param.put("type", "bonusMalus");
+                param.put("class", "life_up");
+                break;
+            case Player.LIFEMAX:
+                param.put("type", "bonusMalus");
+                param.put("class", "life_max");
+                break;
+            default:
+                return false;
+        }
+        //Envoi
+        if (!BomberStudent.bsc.send("POST", "object/new", param)) {
+            return false;
+        }
+        //Reception
+        JSONObject res = BomberStudent.bsc.receive();
+        if (res.getInt("status") != 201) {
+            return false;
+        }
+        //MaJ joueur
+        Player p = this.player.get(this.mainPlayer);
+        p.setLife(res.getInt("life"));
+        p.setMaxLife(res.getInt("maxLife"));
+        p.setSpeed(res.getInt("speed"));
+        p.setBomb(res.getInt("currentNbClassicBomb"));
+        p.setMine(res.getInt("currentNbMine"));
+        p.setRemote(res.getInt("currentNbRemoteBomb"));
+        p.setMaxBomb(res.getInt("maxNbBomb"));
+        //Ajout bonus
+        if (type == Player.FIREPOWER) {
+            p.setFirepower(p.getFirepower() + 1);
+        } else if (type == Player.MAJOR) {
+            p.setMajor(true);
+        }
+        return true;
+    }
+
+    public void updateMap(String mapContent) {
+        String map[][] = this.parseMap(mapContent);
+        //Compare les 2 cartes
+        for (int i = 0; i < height; i++) {
+            for (int j = 0; j < width; j++) {
+                if (this.map[j][i].equals("*")) {
+                    this.map[j][i] = map[j][i];
+                }
+            }
+        }
+    }
+
+    public void updateLife(int newLife) {
+        Player p = this.player.get(this.mainPlayer);
+        //Si non invincible
+        if (!p.isMajor()) {
+            if (newLife > 0) {
+                p.setLife(newLife);
+            } else {
+                this.gameOver();
+            }
+        }
+    }
+
+    public boolean quit(int id) {
+        //Recup joueur
+        Player p = this.player.get(id);
+        if (p == null) {
+            return false;
+        }
+        //Le retire
+        this.player.remove(id);
+        this.map[p.getX()][p.getY()] = "_";
+        return true;
+    }
+    
+    public void gameOver(){
+        //Quitte la partie
+        BomberStudent.bsc.send("POST", "game/quit");
+        //Change l'ecran
+        ScreenManager.setScreen(ScreenManager.END_SCREEN);
+        WebFx.wait.set(true);
+        BomberStudent.wfx.loadHtml("<div style=\"margin-top: 48vh\"><h1 style=\"font-family: Arial\"><div style=\"text-align: center\">GAME OVER<br>Press any key...</div></h1></div>");
+        BomberStudent.waitWfx();
+        BomberStudent.menu = new Menu();
+        BomberStudent.menu.show();
+    }
+    
+    public void explosion(JSONArray explo){
+        int x, y;
+        JSONObject pos;
+        //Ajout explosion map
+        for(int i = 0; i < explo.length(); i++){
+            pos = explo.getJSONObject(i);
+            x = pos.getInt("x");
+            y = pos.getInt("y");
+            this.map[x][y] = "e" + this.map[x][y];
+        }
+        //Timer pour la retirer
+        Thread t = new Thread(new Runnable() {
+            @Override
+            public void run() {
+                try{
+                    Thread.sleep(1000);
+                } catch (Exception ex) {
+                    
+                }
+                BomberStudent.game.removeExplosion();
+                BomberStudent.updateWindow();
+            }
+        });
+        t.start();
+    }
+    
+    public void removeExplosion(){
+        for (int i = 0; i < height; i++) {
+            for (int j = 0; j < width; j++) {
+                if(this.map[j][i].charAt(0) == 'e'){
+                    this.map[j][i] = this.map[j][i].substring(1);
+                }
+            }
+        }
+    }
+
+    /* --- Méthodes affichage --- */
+    public String toHtml() {
+        Player pl = this.player.get(this.mainPlayer);
+        String html = "<!DOCTYPE html><html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"file:" + System.getProperty("user.dir") + "/file/css/map.css\"></head><body><div id=\"game\">";
+        html += "<div id=\"hud\">" + pl.getLife() + "/" + pl.getMaxLife() + "</div>";
+        html += "<table><tbody>";
+        for (int i = 0; i < height; i++) {
+            html += "<tr>";
+            for (int j = 0; j < width; j++) {
+                html += "<td><img src=\"file:" + System.getProperty("user.dir") + "/";
+                switch (this.map[j][i].charAt(0)) {
+                    case 'e':
+                        html += "file/sprite/explosion.png";
+                        break;
+                    case '_':
+                        html += "file/sprite/sol.png";
+                        break;
+                    case '-':
+                        html += "file/sprite/limite.png";
+                        break;
+                    case '*':
+                        html += "file/sprite/mur.png";
+                        break;
+                    case 'b':
+                        switch (this.map[j][i]) {
+                            case "bu":
+                                html += "file/sprite/bomb_up.png";
+                                break;
+                            case "bd":
+                                html += "file/sprite/bomb_down.png";
+                                break;
+                            case "bl":
+                                html += "file/sprite/broken_leg.png";
+                                break;
+                            default:
+                                html += "file/sprite/bomb.png";
+                                break;
+                        }
+                        break;
+                    case 'm':
+                        switch (this.map[j][i]) {
+                            case "mb":
+                                html += "file/sprite/mine_bomb.png";
+                                break;
+                            default:
+                                html += "file/sprite/mine.png";
+                                break;
+                        }
+                        break;
+                    case 'r':
+                        switch (this.map[j][i]) {
+                            case "rb":
+                                html += "file/sprite/remote_bomb.png";
+                                break;
+                            default:
+                                html += "file/sprite/remote.png";
+                                break;
+                        }
+                        break;
+                    case 'c':
+                        html += "file/sprite/classic_bomb.png";
+                        break;
+                    case 'f':
+                        html += "file/sprite/fire_power.png";
+                        break;
+                    case 's':
+                        html += "file/sprite/scooter.png";
+                        break;
+                    case 'i':
+                        html += "file/sprite/major.png";
+                        break;
+                    case 'l':
+                        switch (this.map[j][i]) {
+                            case "lu":
+                                html += "file/sprite/life_up.png";
+                                break;
+                            default:
+                                html += "file/sprite/life_max.png";
+                                break;
+                        }
+                        break;
+                    case '0':
+                    case '1':
+                    case '2':
+                    case '3':
+                    case '4':
+                    case '5':
+                    case '6':
+                    case '7':
+                    case '8':
+                    case '9':
+                        Player p = this.player.get(Integer.parseInt(this.map[j][i]));
+                        if (p.isMain()) {
+                            html += "file/sprite/player_";
+                            if(p.isMajor()){
+                                html += "m";
+                            }
+                            switch(p.dir){
+                                case Player.UP:
+                                    html += "u.png";
+                                    break;
+                                case Player.LEFT:
+                                    html += "l.png";
+                                    break;
+                                case Player.DOWN:
+                                    html += "d.png";
+                                    break;
+                                case Player.RIGHT:
+                                    html += "r.png";
+                                    break;
+                            }
+                        } else {
+                            html += "file/sprite/other_";
+                            switch(p.dir){
+                                case Player.UP:
+                                    html += "u.png";
+                                    break;
+                                case Player.LEFT:
+                                    html += "l.png";
+                                    break;
+                                case Player.DOWN:
+                                    html += "d.png";
+                                    break;
+                                case Player.RIGHT:
+                                    html += "r.png";
+                                    break;
+                            }
+                        }
+                        break;
+                }
+                html += "\"></td>";
+            }
+            html += "</tr>";
+        }
+        html += "</tbody></table></div></body></html>";
+        return html;
+    }
+
+    public void showMap() {
+        for (int i = 0; i < height; i++) {
+            for (int j = 0; j < width; j++) {
+                System.out.print(this.map[j][i]);
+            }
+            System.out.println("");
+        }
+    }
+
+    /* --- Getter/Setter --- */
+    public Player getPlayer(int index) {
+        return this.player.get(index);
+    }
+
+    public int getMainPlayerId() {
+        return this.mainPlayer;
+    }
+
+    public int getHeight() {
+        return this.height;
+    }
+
+    public int getWidth() {
+        return this.width;
+    }
+
+    /* --- Methodes privée --- */
+    private String[][] parseMap(String mapContent) {
+        String[][] map = new String[this.width][this.height];
+        for (int i = 0; i < this.height; i++) {
+            for (int j = 0; j < this.width; j++) {
+                map[j][i] = "" + mapContent.charAt((i * this.width) + j);
+            }
+        }
+        return map;
+    }
+
+    private int[] parseCoord(String coord) {
+        int res[] = new int[2];
+        //Cherche le separateur
+        int pos = 0;
+        while (pos < coord.length()) {
+            if (coord.charAt(pos) == ',') {
+                break;
+            }
+            pos++;
+        }
+        //Si pas de separateur
+        if (pos == coord.length()) {
+            return null;
+        }
+        //Recup les 2 string + extraction int
+        String substr1 = coord.substring(0, pos);
+        String substr2 = coord.substring(pos + 1);
+        res[0] = Integer.parseInt(substr1);
+        res[1] = Integer.parseInt(substr2);
+        return res;
+    }
+
+}

+ 81 - 81
client/src/bs/Join.java

@@ -1,81 +1,81 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package bs;
-
-import bswfx.ScreenManager;
-import org.json.JSONArray;
-import bswfx.BomberStudent;
-import org.json.JSONObject;
-
-/**
- *
- * @author loquicom
- */
-public class Join {
-
-    protected JSONArray games;
-    protected int selected = 0;
-
-    public Join() {
-        ScreenManager.setScreen(ScreenManager.JOIN_SCREEN);
-        BomberStudent.bsc.send("GET", "game/list");
-        JSONObject res = BomberStudent.bsc.receive();
-        if (!res.has("games")) {
-            BomberStudent.menu = new Menu();
-            BomberStudent.menu.show();
-        } else {
-            this.games = res.getJSONArray("games");
-            if (this.games.length() == 0) {
-                BomberStudent.menu = new Menu();
-                BomberStudent.menu.show();
-            }
-        }
-    }
-
-    public void up() {
-        if (this.selected == 0) {
-            this.selected = this.games.length();
-        }
-        this.selected--;
-    }
-
-    public void down() {
-        if (this.selected == this.games.length() - 1) {
-            this.selected = -1;
-        }
-        this.selected++;
-    }
-
-    public void connect() {
-        JSONObject game = this.games.getJSONObject(this.selected);
-        JSONObject param = new JSONObject();
-        param.put("name", game.getString("name"));
-        BomberStudent.bsc.send("POST", "game/join", param);
-        JSONObject res = BomberStudent.bsc.receive();
-        if (res.getInt("status") != 201) {
-            System.err.println("Impossible de rejoindre la partie");
-            BomberStudent.end();
-        }
-        //Creation game
-        BomberStudent.game = new Game(res);
-        ScreenManager.setScreen(ScreenManager.GAME_SCREEN);
-    }
-
-    public String toHtml() {
-        String html = "<!DOCTYPE html><html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"file:" + System.getProperty("user.dir") + "/file/css/menu.css\"></head><body>";
-        for (int i = 0; i < this.games.length(); i++) {
-            JSONObject jo = this.games.getJSONObject(i);
-            html += "<button id=\"id" + i + "\" disabled>" + jo.getString("name") + " - " + jo.getString("map") + " (" + jo.getInt("nbPlayer") + "j.)</button>";
-        }
-        html += "</body></html>";
-        return html.replaceAll("id" + this.selected, "select");
-    }
-
-    public void show() {
-        BomberStudent.wfx.loadHtml(this.toHtml());
-    }
-
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package bs;
+
+import bswfx.ScreenManager;
+import org.json.JSONArray;
+import bswfx.BomberStudent;
+import org.json.JSONObject;
+
+/**
+ *
+ * @author loquicom
+ */
+public class Join {
+
+    protected JSONArray games;
+    protected int selected = 0;
+
+    public Join() {
+        ScreenManager.setScreen(ScreenManager.JOIN_SCREEN);
+        BomberStudent.bsc.send("GET", "game/list");
+        JSONObject res = BomberStudent.bsc.receive();
+        if (!res.has("games")) {
+            BomberStudent.menu = new Menu();
+            BomberStudent.menu.show();
+        } else {
+            this.games = res.getJSONArray("games");
+            if (this.games.length() == 0) {
+                BomberStudent.menu = new Menu();
+                BomberStudent.menu.show();
+            }
+        }
+    }
+
+    public void up() {
+        if (this.selected == 0) {
+            this.selected = this.games.length();
+        }
+        this.selected--;
+    }
+
+    public void down() {
+        if (this.selected == this.games.length() - 1) {
+            this.selected = -1;
+        }
+        this.selected++;
+    }
+
+    public void connect() {
+        JSONObject game = this.games.getJSONObject(this.selected);
+        JSONObject param = new JSONObject();
+        param.put("name", game.getString("name"));
+        BomberStudent.bsc.send("POST", "game/join", param);
+        JSONObject res = BomberStudent.bsc.receive();
+        if (res.getInt("status") != 201) {
+            System.err.println("Impossible de rejoindre la partie");
+            BomberStudent.end();
+        }
+        //Creation game
+        BomberStudent.game = new Game(res);
+        ScreenManager.setScreen(ScreenManager.GAME_SCREEN);
+    }
+
+    public String toHtml() {
+        String html = "<!DOCTYPE html><html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"file:" + System.getProperty("user.dir") + "/file/css/menu.css\"></head><body>";
+        for (int i = 0; i < this.games.length(); i++) {
+            JSONObject jo = this.games.getJSONObject(i);
+            html += "<button id=\"id" + i + "\" disabled>" + jo.getString("name") + " - " + jo.getString("map") + " (" + jo.getInt("nbPlayer") + "j.)</button>";
+        }
+        html += "</body></html>";
+        return html.replaceAll("id" + this.selected, "select");
+    }
+
+    public void show() {
+        BomberStudent.wfx.loadHtml(this.toHtml());
+    }
+
+}

+ 59 - 59
client/src/bs/Menu.java

@@ -1,59 +1,59 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package bs;
-
-import bswfx.BomberStudent;
-import bswfx.ScreenManager;
-
-/**
- *
- * @author loquicom
- */
-public class Menu {
-    
-    public static final int CREATE = 0;
-    public static final int JOIN = 1;
-    public static final int QUIT = 2;
-    
-    protected int selected = 0;
-    
-    public Menu(){
-        ScreenManager.setScreen(ScreenManager.MENU_SCREEN);
-    }
-    
-    public int getAction(){
-        return this.selected;
-    }
-    
-    public void up(){
-        if(this.selected == 0){
-            this.selected = 3;
-        }
-        this.selected--;
-    }
-    
-    public void down(){
-        if(this.selected == 2){
-            this.selected = -1;
-        }
-        this.selected++;
-    }
-    
-    public String toHtml(){
-        String html = "<!DOCTYPE html><html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"file:" + System.getProperty("user.dir") + "/file/css/menu.css\"></head><body>";
-        html += "<button id=\"id0\" disabled>Créer</button>";
-        html += "<button id=\"id1\" disabled>Rejoindre</button>";
-        html += "<button id=\"id2\" disabled>Quitter</button>";
-        html += "</body></html>";
-        html = html.replaceAll("id" + this.selected, "select");
-        return html;
-    }
-    
-    public void show(){
-        BomberStudent.wfx.loadHtml(this.toHtml());
-    }
-    
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package bs;
+
+import bswfx.BomberStudent;
+import bswfx.ScreenManager;
+
+/**
+ *
+ * @author loquicom
+ */
+public class Menu {
+    
+    public static final int CREATE = 0;
+    public static final int JOIN = 1;
+    public static final int QUIT = 2;
+    
+    protected int selected = 0;
+    
+    public Menu(){
+        ScreenManager.setScreen(ScreenManager.MENU_SCREEN);
+    }
+    
+    public int getAction(){
+        return this.selected;
+    }
+    
+    public void up(){
+        if(this.selected == 0){
+            this.selected = 3;
+        }
+        this.selected--;
+    }
+    
+    public void down(){
+        if(this.selected == 2){
+            this.selected = -1;
+        }
+        this.selected++;
+    }
+    
+    public String toHtml(){
+        String html = "<!DOCTYPE html><html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"file:" + System.getProperty("user.dir") + "/file/css/menu.css\"></head><body>";
+        html += "<button id=\"id0\" disabled>Créer</button>";
+        html += "<button id=\"id1\" disabled>Rejoindre</button>";
+        html += "<button id=\"id2\" disabled>Quitter</button>";
+        html += "</body></html>";
+        html = html.replaceAll("id" + this.selected, "select");
+        return html;
+    }
+    
+    public void show(){
+        BomberStudent.wfx.loadHtml(this.toHtml());
+    }
+    
+}

+ 305 - 305
client/src/bs/Player.java

@@ -1,305 +1,305 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package bs;
-
-import bswfx.BomberStudent;
-import org.json.JSONObject;
-
-/**
- *
- * @author loquicom
- */
-public class Player {
-    
-    //Deplacement
-    public static final int UP = 0;
-    public static final int LEFT = 1; 
-    public static final int DOWN = 2;
-    public static final int RIGHT = 3;
-    //Type de bombe
-    public static final int CLASSIC = 0;
-    public static final int MINE = 1;
-    public static final int REMOTE = 2;
-    //Objet
-    public static final int BOMBUP = 3;
-    public static final int BOMBDOWN = 4;
-    public static final int FIREPOWER = 5;
-    public static final int SCOOTER = 6;
-    public static final int BROKENLEG = 7;
-    public static final int MAJOR = 8;
-    public static final int LIFEUP = 9;
-    public static final int LIFEMAX = 10;
-    
-    protected boolean main;
-    protected int id;
-    protected int dir;
-    protected int x;
-    protected int y;
-    protected int life;
-    protected int maxLife;
-    protected int speed;
-    protected int maxBomb;
-    protected int bomb;
-    protected int mine;
-    protected int remote;
-    protected int firepower;
-    protected boolean major;
-    
-    public Player(int id, String pos){
-        int coord[] = parseCoord(pos);
-        //SetUp les valeurs
-        this.main = false;
-        this.id = id;
-        this.dir = RIGHT;
-        this.x = coord[0];
-        this.y = coord[1];
-    }
-    
-    public Player(JSONObject jo, String pos){
-        int coord[] = parseCoord(pos);
-        //SetUp les valeurs
-        this.main = true;
-        this.id = jo.getInt("id");
-        this.dir = RIGHT;
-        this.x = coord[0];
-        this.y = coord[1];
-        this.life = jo.getInt("life");
-        this.maxLife = jo.getInt("maxLife");
-        this.speed = jo.getInt("speed");
-        this.maxBomb = jo.getInt("maxNbBomb");
-        this.bomb = jo.getInt("currentNbClassicBomb");
-        this.mine = jo.getInt("currentNbMine");
-        this.remote = jo.getInt("currentNbRemoteBomb");
-        this.firepower = 0;
-        this.major = false;
-    }
-    
-    /* --- Méthodes --- */
-    
-    public boolean move(int dir){
-        JSONObject jo = new JSONObject();
-        switch(dir){
-            case UP:
-                jo.put("move", "up");
-                return BomberStudent.bsc.send("POST", "player/move", jo);
-            case LEFT:
-                jo.put("move", "left");
-                return BomberStudent.bsc.send("POST", "player/move", jo);      
-            case DOWN:
-                jo.put("move", "down");
-                return BomberStudent.bsc.send("POST", "player/move", jo);
-            case RIGHT:
-                jo.put("move", "right");
-                return BomberStudent.bsc.send("POST", "player/move", jo);
-            default:
-                return false;
-        }
-    }
-    
-    public boolean attack(int type){
-        JSONObject jo = new JSONObject();
-        //Calcul position
-        int x = this.x;
-        int y = this.y;
-        switch(this.dir){
-            case UP:
-                if(y == 0){
-                    return false;
-                }
-                y--;
-                break;
-            case LEFT:
-                if(x == 0){
-                    return false;
-                }
-                x--;
-                break;   
-            case DOWN:
-                if(y == BomberStudent.game.getHeight() - 1){
-                    return false;
-                }
-                y++;
-                break;
-            case RIGHT:
-                if(x == BomberStudent.game.getWidth() - 1){
-                    return false;
-                }
-                x++;
-                break;
-            default:
-                return false;
-        }
-        jo.put("pos", x + "," + y);
-        //Regarde le type
-        switch(type){
-            case CLASSIC:
-                jo.put("class", "classic");
-                break;
-            case MINE:
-                jo.put("class", "mine");
-                break;
-            case REMOTE:
-                jo.put("class", "remote");
-                break;
-            default:
-                return false;
-        }
-        //Si il a un bonus
-        jo.put("bonus", this.firepower > 0);
-        //Envoi
-        if(!BomberStudent.bsc.send("POST", "attack/bomb", jo)){
-            return false;
-        }
-        JSONObject res = BomberStudent.bsc.receive();
-        if(res.getInt("status") == 201){
-            if(type == MINE){
-                BomberStudent.game.newBomb(MINE, x + "," + y);
-                BomberStudent.updateWindow();
-            }
-            return true;
-        }
-        return false;
-    }
-
-    /* --- Getter/Setter --- */
-    
-    public boolean isMain() {
-        return main;
-    }
-
-    public int getId() {
-        return id;
-    }
-    
-    public int getDir(){
-        return dir;
-    }
-
-    public int getX() {
-        return x;
-    }
-
-    public int getY() {
-        return y;
-    }
-
-    public int getLife() {
-        return life;
-    }
-
-    public int getMaxLife() {
-        return maxLife;
-    }
-
-    public int getSpeed() {
-        return speed;
-    }
-
-    public int getMaxBomb() {
-        return maxBomb;
-    }
-
-    public int getBomb() {
-        return bomb;
-    }
-
-    public int getMine() {
-        return mine;
-    }
-
-    public int getRemote() {
-        return remote;
-    }
-
-    public int getFirepower() {
-        return firepower;
-    }
-
-    public boolean isMajor() {
-        return major;
-    }
-
-    public void setMain(boolean main) {
-        this.main = main;
-    }
-
-    public void setId(int id) {
-        this.id = id;
-    }
-    
-    public void setDir(int dir){
-        this.dir = dir;
-    }
-
-    public void setX(int x) {
-        this.x = x;
-    }
-
-    public void setY(int y) {
-        this.y = y;
-    }
-
-    public void setLife(int life) {
-        this.life = life;
-    }
-
-    public void setMaxLife(int maxLife) {
-        this.maxLife = maxLife;
-    }
-
-    public void setSpeed(int speed) {
-        this.speed = speed;
-    }
-
-    public void setMaxBomb(int maxBomb) {
-        this.maxBomb = maxBomb;
-    }
-
-    public void setBomb(int bomb) {
-        this.bomb = bomb;
-    }
-
-    public void setMine(int mine) {
-        this.mine = mine;
-    }
-
-    public void setRemote(int remote) {
-        this.remote = remote;
-    }
-
-    public void setFirepower(int firepower) {
-        this.firepower = firepower;
-    }
-
-    public void setMajor(boolean major) {
-        this.major = major;
-    }
-    
-    /* --- Methodes privées --- */
-    
-    private int[] parseCoord(String coord){
-        int res[] = new int[2];
-        //Cherche le separateur
-        int pos = 0;
-        while(pos < coord.length()){
-            if(coord.charAt(pos) == ','){
-                break;
-            }
-            pos++;
-        }
-        //Si pas de separateur
-        if(pos == coord.length()){
-            return null;
-        }
-        //Recup les 2 string + extraction int
-        String substr1 = coord.substring(0, pos);
-        String substr2 = coord.substring(pos + 1);
-        res[0] = Integer.parseInt(substr1);
-        res[1] = Integer.parseInt(substr2);
-        return res;
-    }
-    
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package bs;
+
+import bswfx.BomberStudent;
+import org.json.JSONObject;
+
+/**
+ *
+ * @author loquicom
+ */
+public class Player {
+    
+    //Deplacement
+    public static final int UP = 0;
+    public static final int LEFT = 1; 
+    public static final int DOWN = 2;
+    public static final int RIGHT = 3;
+    //Type de bombe
+    public static final int CLASSIC = 0;
+    public static final int MINE = 1;
+    public static final int REMOTE = 2;
+    //Objet
+    public static final int BOMBUP = 3;
+    public static final int BOMBDOWN = 4;
+    public static final int FIREPOWER = 5;
+    public static final int SCOOTER = 6;
+    public static final int BROKENLEG = 7;
+    public static final int MAJOR = 8;
+    public static final int LIFEUP = 9;
+    public static final int LIFEMAX = 10;
+    
+    protected boolean main;
+    protected int id;
+    protected int dir;
+    protected int x;
+    protected int y;
+    protected int life;
+    protected int maxLife;
+    protected int speed;
+    protected int maxBomb;
+    protected int bomb;
+    protected int mine;
+    protected int remote;
+    protected int firepower;
+    protected boolean major;
+    
+    public Player(int id, String pos){
+        int coord[] = parseCoord(pos);
+        //SetUp les valeurs
+        this.main = false;
+        this.id = id;
+        this.dir = RIGHT;
+        this.x = coord[0];
+        this.y = coord[1];
+    }
+    
+    public Player(JSONObject jo, String pos){
+        int coord[] = parseCoord(pos);
+        //SetUp les valeurs
+        this.main = true;
+        this.id = jo.getInt("id");
+        this.dir = RIGHT;
+        this.x = coord[0];
+        this.y = coord[1];
+        this.life = jo.getInt("life");
+        this.maxLife = jo.getInt("maxLife");
+        this.speed = jo.getInt("speed");
+        this.maxBomb = jo.getInt("maxNbBomb");
+        this.bomb = jo.getInt("currentNbClassicBomb");
+        this.mine = jo.getInt("currentNbMine");
+        this.remote = jo.getInt("currentNbRemoteBomb");
+        this.firepower = 0;
+        this.major = false;
+    }
+    
+    /* --- Méthodes --- */
+    
+    public boolean move(int dir){
+        JSONObject jo = new JSONObject();
+        switch(dir){
+            case UP:
+                jo.put("move", "up");
+                return BomberStudent.bsc.send("POST", "player/move", jo);
+            case LEFT:
+                jo.put("move", "left");
+                return BomberStudent.bsc.send("POST", "player/move", jo);      
+            case DOWN:
+                jo.put("move", "down");
+                return BomberStudent.bsc.send("POST", "player/move", jo);
+            case RIGHT:
+                jo.put("move", "right");
+                return BomberStudent.bsc.send("POST", "player/move", jo);
+            default:
+                return false;
+        }
+    }
+    
+    public boolean attack(int type){
+        JSONObject jo = new JSONObject();
+        //Calcul position
+        int x = this.x;
+        int y = this.y;
+        switch(this.dir){
+            case UP:
+                if(y == 0){
+                    return false;
+                }
+                y--;
+                break;
+            case LEFT:
+                if(x == 0){
+                    return false;
+                }
+                x--;
+                break;   
+            case DOWN:
+                if(y == BomberStudent.game.getHeight() - 1){
+                    return false;
+                }
+                y++;
+                break;
+            case RIGHT:
+                if(x == BomberStudent.game.getWidth() - 1){
+                    return false;
+                }
+                x++;
+                break;
+            default:
+                return false;
+        }
+        jo.put("pos", x + "," + y);
+        //Regarde le type
+        switch(type){
+            case CLASSIC:
+                jo.put("class", "classic");
+                break;
+            case MINE:
+                jo.put("class", "mine");
+                break;
+            case REMOTE:
+                jo.put("class", "remote");
+                break;
+            default:
+                return false;
+        }
+        //Si il a un bonus
+        jo.put("bonus", this.firepower > 0);
+        //Envoi
+        if(!BomberStudent.bsc.send("POST", "attack/bomb", jo)){
+            return false;
+        }
+        JSONObject res = BomberStudent.bsc.receive();
+        if(res.getInt("status") == 201){
+            if(type == MINE){
+                BomberStudent.game.newBomb(MINE, x + "," + y);
+                BomberStudent.updateWindow();
+            }
+            return true;
+        }
+        return false;
+    }
+
+    /* --- Getter/Setter --- */
+    
+    public boolean isMain() {
+        return main;
+    }
+
+    public int getId() {
+        return id;
+    }
+    
+    public int getDir(){
+        return dir;
+    }
+
+    public int getX() {
+        return x;
+    }
+
+    public int getY() {
+        return y;
+    }
+
+    public int getLife() {
+        return life;
+    }
+
+    public int getMaxLife() {
+        return maxLife;
+    }
+
+    public int getSpeed() {
+        return speed;
+    }
+
+    public int getMaxBomb() {
+        return maxBomb;
+    }
+
+    public int getBomb() {
+        return bomb;
+    }
+
+    public int getMine() {
+        return mine;
+    }
+
+    public int getRemote() {
+        return remote;
+    }
+
+    public int getFirepower() {
+        return firepower;
+    }
+
+    public boolean isMajor() {
+        return major;
+    }
+
+    public void setMain(boolean main) {
+        this.main = main;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+    
+    public void setDir(int dir){
+        this.dir = dir;
+    }
+
+    public void setX(int x) {
+        this.x = x;
+    }
+
+    public void setY(int y) {
+        this.y = y;
+    }
+
+    public void setLife(int life) {
+        this.life = life;
+    }
+
+    public void setMaxLife(int maxLife) {
+        this.maxLife = maxLife;
+    }
+
+    public void setSpeed(int speed) {
+        this.speed = speed;
+    }
+
+    public void setMaxBomb(int maxBomb) {
+        this.maxBomb = maxBomb;
+    }
+
+    public void setBomb(int bomb) {
+        this.bomb = bomb;
+    }
+
+    public void setMine(int mine) {
+        this.mine = mine;
+    }
+
+    public void setRemote(int remote) {
+        this.remote = remote;
+    }
+
+    public void setFirepower(int firepower) {
+        this.firepower = firepower;
+    }
+
+    public void setMajor(boolean major) {
+        this.major = major;
+    }
+    
+    /* --- Methodes privées --- */
+    
+    private int[] parseCoord(String coord){
+        int res[] = new int[2];
+        //Cherche le separateur
+        int pos = 0;
+        while(pos < coord.length()){
+            if(coord.charAt(pos) == ','){
+                break;
+            }
+            pos++;
+        }
+        //Si pas de separateur
+        if(pos == coord.length()){
+            return null;
+        }
+        //Recup les 2 string + extraction int
+        String substr1 = coord.substring(0, pos);
+        String substr2 = coord.substring(pos + 1);
+        res[0] = Integer.parseInt(substr1);
+        res[1] = Integer.parseInt(substr2);
+        return res;
+    }
+    
+}

+ 31 - 31
client/src/bswfx/ScreenManager.java

@@ -1,31 +1,31 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package bswfx;
-
-/**
- *
- * @author loquicom
- */
-public class ScreenManager {
-    
-    public static final int LOADING_SCREEN = 0;
-    public static final int GAME_SCREEN = 1;
-    public static final int END_SCREEN = 2;
-    public static final int MENU_SCREEN = 3;
-    public static final int CREATE_SCREEN = 4;
-    public static final int JOIN_SCREEN = 5;
-    
-    protected static int screen = LOADING_SCREEN;
-    
-    public static int getScreen(){
-        return ScreenManager.screen;
-    }
-    
-    public static void setScreen(int screen){
-        ScreenManager.screen = screen;
-    }
-    
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package bswfx;
+
+/**
+ *
+ * @author loquicom
+ */
+public class ScreenManager {
+    
+    public static final int LOADING_SCREEN = 0;
+    public static final int GAME_SCREEN = 1;
+    public static final int END_SCREEN = 2;
+    public static final int MENU_SCREEN = 3;
+    public static final int CREATE_SCREEN = 4;
+    public static final int JOIN_SCREEN = 5;
+    
+    protected static int screen = LOADING_SCREEN;
+    
+    public static int getScreen(){
+        return ScreenManager.screen;
+    }
+    
+    public static void setScreen(int screen){
+        ScreenManager.screen = screen;
+    }
+    
+}

+ 29 - 29
client/src/bswfx/handler/HandlerAttackAffect.java

@@ -1,29 +1,29 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package bswfx.handler;
-
-import org.json.JSONObject;
-import rsx.BomberStudentHandler;
-import bswfx.BomberStudent;
-
-/**
- *
- * @author loquicom
- */
-public class HandlerAttackAffect implements BomberStudentHandler{
-
-    @Override
-    public boolean handle(JSONObject json) {
-        //Verif param
-        if(!( json.has("life") )){
-            return false;
-        }
-        //MaJ la vie
-        BomberStudent.game.updateLife(json.getInt("life"));
-        return true;
-    }
-    
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package bswfx.handler;
+
+import org.json.JSONObject;
+import rsx.BomberStudentHandler;
+import bswfx.BomberStudent;
+
+/**
+ *
+ * @author loquicom
+ */
+public class HandlerAttackAffect implements BomberStudentHandler{
+
+    @Override
+    public boolean handle(JSONObject json) {
+        //Verif param
+        if(!( json.has("life") )){
+            return false;
+        }
+        //MaJ la vie
+        BomberStudent.game.updateLife(json.getInt("life"));
+        return true;
+    }
+    
+}

+ 47 - 47
client/src/bswfx/handler/HandlerAttackBomb.java

@@ -1,47 +1,47 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package bswfx.handler;
-
-import bs.Player;
-import org.json.JSONObject;
-import rsx.BomberStudentHandler;
-import bswfx.BomberStudent;
-
-/**
- *
- * @author loquicom
- */
-public class HandlerAttackBomb implements BomberStudentHandler{
-
-    @Override
-    public boolean handle(JSONObject json) {
-        //Verif json
-        if(!( json.has("pos") && json.has("class") )){
-            return false;
-        }
-        //Recup le type
-        int type;
-        switch(json.getString("class")){
-            case "classic":
-                type = Player.CLASSIC;
-                break;
-            case "mine":
-                return true;
-            case "remote":
-                type = Player.REMOTE;
-                break;
-            default:
-                return false;
-        }
-        //Ajoute sur la map
-        if(BomberStudent.game.newBomb(type, json.getString("pos"))){
-            BomberStudent.updateWindow();
-            return true;
-        }
-        return false;
-    }
-    
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package bswfx.handler;
+
+import bs.Player;
+import org.json.JSONObject;
+import rsx.BomberStudentHandler;
+import bswfx.BomberStudent;
+
+/**
+ *
+ * @author loquicom
+ */
+public class HandlerAttackBomb implements BomberStudentHandler{
+
+    @Override
+    public boolean handle(JSONObject json) {
+        //Verif json
+        if(!( json.has("pos") && json.has("class") )){
+            return false;
+        }
+        //Recup le type
+        int type;
+        switch(json.getString("class")){
+            case "classic":
+                type = Player.CLASSIC;
+                break;
+            case "mine":
+                return true;
+            case "remote":
+                type = Player.REMOTE;
+                break;
+            default:
+                return false;
+        }
+        //Ajoute sur la map
+        if(BomberStudent.game.newBomb(type, json.getString("pos"))){
+            BomberStudent.updateWindow();
+            return true;
+        }
+        return false;
+    }
+    
+}

+ 94 - 94
client/src/bswfx/handler/HandlerAttackExplose.java

@@ -1,94 +1,94 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package bswfx.handler;
-
-import bs.Player;
-import org.json.JSONObject;
-import rsx.BomberStudentHandler;
-import bswfx.BomberStudent;
-import org.json.JSONArray;
-
-/**
- *
- * @author loquicom
- */
-public class HandlerAttackExplose implements BomberStudentHandler {
-
-    @Override
-    public boolean handle(JSONObject json) {
-        //Verif param
-        if (!(json.has("pos") && json.has("map") && json.has("explosion") )) {
-            return false;
-        }
-        //Retire les bombes explosées
-        BomberStudent.game.removeBomb(json.getString("pos"));
-        if (json.has("chain")) {
-            JSONArray ja = json.getJSONArray("chain");
-            for (int i = 0; i < ja.length(); i++) {
-                JSONObject jo = ja.getJSONObject(i);
-                BomberStudent.game.removeBomb(jo.getString("pos"));
-            }
-        }
-        //Met à jour la map
-        BomberStudent.game.updateMap(json.getString("map"));
-        //Ajoute les bombes / bonus
-        if (json.has("bomb")) {
-            JSONArray ja = json.getJSONArray("bomb");
-            for (int i = 0; i < ja.length(); i++) {
-                JSONObject jo = ja.getJSONObject(i);
-                switch (jo.getString("type")) {
-                    case "classic":
-                        BomberStudent.game.newObject(Player.CLASSIC, jo.getString("pos"));
-                        break;
-                    case "mine":
-                        BomberStudent.game.newObject(Player.MINE, jo.getString("pos"));
-                        break;
-                    case "remote":
-                        BomberStudent.game.newObject(Player.REMOTE, jo.getString("pos"));
-                        break;
-                }
-            }
-        }
-        if (json.has("bonusMalus")) {
-            JSONArray ja = json.getJSONArray("bonusMalus");
-            for (int i = 0; i < ja.length(); i++) {
-                JSONObject jo = ja.getJSONObject(i);
-                switch (jo.getString("type")) {
-                    case "bomb_up":
-                        BomberStudent.game.newObject(Player.BOMBUP, jo.getString("pos"));
-                        break;
-                    case "bomb_down":
-                        BomberStudent.game.newObject(Player.BOMBDOWN, jo.getString("pos"));
-                        break;
-                    case "fire_power":
-                        BomberStudent.game.newObject(Player.FIREPOWER, jo.getString("pos"));
-                        break;
-                    case "scooter":
-                        BomberStudent.game.newObject(Player.SCOOTER, jo.getString("pos"));
-                        break;
-                    case "broken_legs":
-                        BomberStudent.game.newObject(Player.BROKENLEG, jo.getString("pos"));
-                        break;
-                    case "major":
-                        BomberStudent.game.newObject(Player.MAJOR, jo.getString("pos"));
-                        break;
-                    case "life_up":
-                        BomberStudent.game.newObject(Player.LIFEUP, jo.getString("pos"));
-                        break;
-                    case "life_max":
-                        BomberStudent.game.newObject(Player.LIFEMAX, jo.getString("pos"));
-                        break;
-                }
-            }
-        }
-        //Gére l'affichage des explosions
-        BomberStudent.game.explosion(json.getJSONArray("explosion"));
-        //MaJ affichage
-        BomberStudent.updateWindow();
-        return true;
-    }
-
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package bswfx.handler;
+
+import bs.Player;
+import org.json.JSONObject;
+import rsx.BomberStudentHandler;
+import bswfx.BomberStudent;
+import org.json.JSONArray;
+
+/**
+ *
+ * @author loquicom
+ */
+public class HandlerAttackExplose implements BomberStudentHandler {
+
+    @Override
+    public boolean handle(JSONObject json) {
+        //Verif param
+        if (!(json.has("pos") && json.has("map") && json.has("explosion") )) {
+            return false;
+        }
+        //Retire les bombes explosées
+        BomberStudent.game.removeBomb(json.getString("pos"));
+        if (json.has("chain")) {
+            JSONArray ja = json.getJSONArray("chain");
+            for (int i = 0; i < ja.length(); i++) {
+                JSONObject jo = ja.getJSONObject(i);
+                BomberStudent.game.removeBomb(jo.getString("pos"));
+            }
+        }
+        //Met à jour la map
+        BomberStudent.game.updateMap(json.getString("map"));
+        //Ajoute les bombes / bonus
+        if (json.has("bomb")) {
+            JSONArray ja = json.getJSONArray("bomb");
+            for (int i = 0; i < ja.length(); i++) {
+                JSONObject jo = ja.getJSONObject(i);
+                switch (jo.getString("type")) {
+                    case "classic":
+                        BomberStudent.game.newObject(Player.CLASSIC, jo.getString("pos"));
+                        break;
+                    case "mine":
+                        BomberStudent.game.newObject(Player.MINE, jo.getString("pos"));
+                        break;
+                    case "remote":
+                        BomberStudent.game.newObject(Player.REMOTE, jo.getString("pos"));
+                        break;
+                }
+            }
+        }
+        if (json.has("bonusMalus")) {
+            JSONArray ja = json.getJSONArray("bonusMalus");
+            for (int i = 0; i < ja.length(); i++) {
+                JSONObject jo = ja.getJSONObject(i);
+                switch (jo.getString("type")) {
+                    case "bomb_up":
+                        BomberStudent.game.newObject(Player.BOMBUP, jo.getString("pos"));
+                        break;
+                    case "bomb_down":
+                        BomberStudent.game.newObject(Player.BOMBDOWN, jo.getString("pos"));
+                        break;
+                    case "fire_power":
+                        BomberStudent.game.newObject(Player.FIREPOWER, jo.getString("pos"));
+                        break;
+                    case "scooter":
+                        BomberStudent.game.newObject(Player.SCOOTER, jo.getString("pos"));
+                        break;
+                    case "broken_legs":
+                        BomberStudent.game.newObject(Player.BROKENLEG, jo.getString("pos"));
+                        break;
+                    case "major":
+                        BomberStudent.game.newObject(Player.MAJOR, jo.getString("pos"));
+                        break;
+                    case "life_up":
+                        BomberStudent.game.newObject(Player.LIFEUP, jo.getString("pos"));
+                        break;
+                    case "life_max":
+                        BomberStudent.game.newObject(Player.LIFEMAX, jo.getString("pos"));
+                        break;
+                }
+            }
+        }
+        //Gére l'affichage des explosions
+        BomberStudent.game.explosion(json.getJSONArray("explosion"));
+        //MaJ affichage
+        BomberStudent.updateWindow();
+        return true;
+    }
+
+}

+ 27 - 27
client/src/bswfx/handler/HandlerMajorEnd.java

@@ -1,27 +1,27 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package bswfx.handler;
-
-import bs.Player;
-import org.json.JSONObject;
-import rsx.BomberStudentHandler;
-import bswfx.BomberStudent;
-
-/**
- *
- * @author loquicom
- */
-public class HandlerMajorEnd implements BomberStudentHandler{
-
-    @Override
-    public boolean handle(JSONObject json) {
-        Player p = BomberStudent.game.getPlayer(BomberStudent.game.getMainPlayerId());
-        p.setMajor(false);
-        BomberStudent.updateWindow();
-        return true;
-    }
-    
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package bswfx.handler;
+
+import bs.Player;
+import org.json.JSONObject;
+import rsx.BomberStudentHandler;
+import bswfx.BomberStudent;
+
+/**
+ *
+ * @author loquicom
+ */
+public class HandlerMajorEnd implements BomberStudentHandler{
+
+    @Override
+    public boolean handle(JSONObject json) {
+        Player p = BomberStudent.game.getPlayer(BomberStudent.game.getMainPlayerId());
+        p.setMajor(false);
+        BomberStudent.updateWindow();
+        return true;
+    }
+    
+}

+ 30 - 30
client/src/bswfx/handler/HandlerPlayerJoin.java

@@ -1,30 +1,30 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package bswfx.handler;
-
-import org.json.JSONObject;
-import rsx.BomberStudentHandler;
-import bswfx.BomberStudent;
-
-/**
- *
- * @author loquicom
- */
-public class HandlerPlayerJoin implements BomberStudentHandler{
-
-    @Override
-    public boolean handle(JSONObject json) {
-        //Verif param
-        if(!( json.has("id") && json.has("pos") )){
-            return false;
-        }
-        //Ajout
-        BomberStudent.game.join(json.getInt("id"), json.getString("pos"));
-        BomberStudent.updateWindow();
-        return true;
-    }
-    
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package bswfx.handler;
+
+import org.json.JSONObject;
+import rsx.BomberStudentHandler;
+import bswfx.BomberStudent;
+
+/**
+ *
+ * @author loquicom
+ */
+public class HandlerPlayerJoin implements BomberStudentHandler{
+
+    @Override
+    public boolean handle(JSONObject json) {
+        //Verif param
+        if(!( json.has("id") && json.has("pos") )){
+            return false;
+        }
+        //Ajout
+        BomberStudent.game.join(json.getInt("id"), json.getString("pos"));
+        BomberStudent.updateWindow();
+        return true;
+    }
+    
+}

+ 51 - 51
client/src/bswfx/handler/HandlerPlayerMove.java

@@ -1,51 +1,51 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package bswfx.handler;
-
-import bs.Player;
-import org.json.JSONObject;
-import rsx.BomberStudentHandler;
-import bswfx.BomberStudent;
-
-/**
- *
- * @author loquicom
- */
-public class HandlerPlayerMove implements BomberStudentHandler{
-
-    @Override
-    public boolean handle(JSONObject json) {
-        //Verif param
-        if(!( json.has("player") && json.has("dir") )){
-            return false;
-        }
-        //Lecture direction
-        int dir;
-        switch(json.getString("dir")){
-            case "up":
-                dir = Player.UP;
-                break;
-            case "left":
-                dir = Player.LEFT;
-                break;
-            case "down":
-                dir = Player.DOWN;
-                break;
-            case "right":
-                dir = Player.RIGHT;
-                break;
-            default:
-                return false;
-        }
-        //Deplacement
-        if(BomberStudent.game.move(json.getInt("player"), dir)){
-            BomberStudent.updateWindow();
-            return true;
-        }
-        return false;
-    }
-    
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package bswfx.handler;
+
+import bs.Player;
+import org.json.JSONObject;
+import rsx.BomberStudentHandler;
+import bswfx.BomberStudent;
+
+/**
+ *
+ * @author loquicom
+ */
+public class HandlerPlayerMove implements BomberStudentHandler{
+
+    @Override
+    public boolean handle(JSONObject json) {
+        //Verif param
+        if(!( json.has("player") && json.has("dir") )){
+            return false;
+        }
+        //Lecture direction
+        int dir;
+        switch(json.getString("dir")){
+            case "up":
+                dir = Player.UP;
+                break;
+            case "left":
+                dir = Player.LEFT;
+                break;
+            case "down":
+                dir = Player.DOWN;
+                break;
+            case "right":
+                dir = Player.RIGHT;
+                break;
+            default:
+                return false;
+        }
+        //Deplacement
+        if(BomberStudent.game.move(json.getInt("player"), dir)){
+            BomberStudent.updateWindow();
+            return true;
+        }
+        return false;
+    }
+    
+}

+ 32 - 32
client/src/bswfx/handler/HandlerPlayerQuit.java

@@ -1,32 +1,32 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package bswfx.handler;
-
-import org.json.JSONObject;
-import rsx.BomberStudentHandler;
-import bswfx.BomberStudent;
-
-/**
- *
- * @author loquicom
- */
-public class HandlerPlayerQuit implements BomberStudentHandler{
-
-    @Override
-    public boolean handle(JSONObject json) {
-        //Verif param
-        if(!( json.has("player") )){
-            return false;
-        }
-        //Retire le joueur
-        if(BomberStudent.game.quit(json.getInt("player"))){
-            BomberStudent.updateWindow();
-            return true;
-        }
-        return false;
-    }
-    
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package bswfx.handler;
+
+import org.json.JSONObject;
+import rsx.BomberStudentHandler;
+import bswfx.BomberStudent;
+
+/**
+ *
+ * @author loquicom
+ */
+public class HandlerPlayerQuit implements BomberStudentHandler{
+
+    @Override
+    public boolean handle(JSONObject json) {
+        //Verif param
+        if(!( json.has("player") )){
+            return false;
+        }
+        //Retire le joueur
+        if(BomberStudent.game.quit(json.getInt("player"))){
+            BomberStudent.updateWindow();
+            return true;
+        }
+        return false;
+    }
+    
+}

+ 26 - 26
client/src/bswfx/handler/HandlerServerEnd.java

@@ -1,26 +1,26 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package bswfx.handler;
-
-import org.json.JSONObject;
-import rsx.BomberStudentHandler;
-import bswfx.BomberStudent;
-
-/**
- *
- * @author loquicom
- */
-public class HandlerServerEnd implements BomberStudentHandler{
-
-    @Override
-    public boolean handle(JSONObject json) {
-        BomberStudent.wfx.alert("Déconnexion", "La connexion avec le serveur a été perdue");
-        BomberStudent.waitWfx();
-        BomberStudent.end();
-        return true;
-    }
-    
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package bswfx.handler;
+
+import org.json.JSONObject;
+import rsx.BomberStudentHandler;
+import bswfx.BomberStudent;
+
+/**
+ *
+ * @author loquicom
+ */
+public class HandlerServerEnd implements BomberStudentHandler{
+
+    @Override
+    public boolean handle(JSONObject json) {
+        BomberStudent.wfx.alert("Déconnexion", "La connexion avec le serveur a été perdue");
+        BomberStudent.waitWfx();
+        BomberStudent.end();
+        return true;
+    }
+    
+}

+ 216 - 216
client/src/rsx/BomberStudentClient.java

@@ -1,216 +1,216 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package rsx;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.HashMap;
-import org.json.JSONException;
-import org.json.JSONObject;
-import rsx.tcp.TcpClient;
-import rsx.udp.Broadcast;
-
-/**
- * Connexion à un server BomberStudent
- *
- * @author Arthur Brandao
- */
-public class BomberStudentClient {
-
-    /**
-     * Port pour le boradcast UDP
-     */
-    protected int portUdp;
-
-    /**
-     * Port pour la socket TCP
-     */
-    protected int portTcp;
-
-    /**
-     * Class pour broadcast
-     */
-    protected Broadcast finder;
-
-    /**
-     * Class pour le client TCP
-     */
-    protected TcpClient socket;
-
-    /**
-     * Si le client est conecter à un serveur en TCP
-     */
-    protected boolean connect;
-
-    /**
-     * Class de gestion des requetes serveurs
-     */
-    protected BomberStudentRequest request;
-
-    /**
-     * Liste des handlers pour gerer les requetes du serveur
-     */
-    protected HashMap<String, BomberStudentHandler> handlers = new HashMap<>();
-
-    /* --- Constructeurs --- */
-    /**
-     * Creation d'un client BomberStudent Le port 18624 est utilisé pour le
-     * broadcast udp Le port 18642 est utilisé pour la socket TCP
-     */
-    public BomberStudentClient() {
-        this.portUdp = 18624;
-        this.portTcp = 18642;
-        this.finder = new Broadcast(this.portUdp);
-    }
-
-    /**
-     * Creation d'un client BomberStudent
-     *
-     * @param portUdp Le port pour le broadcast UDP
-     * @param portTcp Le port pour la socket TCP
-     */
-    public BomberStudentClient(int portUdp, int portTcp) {
-        this.portUdp = portUdp;
-        this.portTcp = portTcp;
-        this.finder = new Broadcast(this.portUdp);
-    }
-
-    /* --- Methodes --- */
-    /**
-     * Ajoute un handler
-     *
-     * @param ressource Le nom de la ressource associè au handler
-     * @param handler Le handler
-     */
-    public void addHandler(String ressource, BomberStudentHandler handler) {
-        this.handlers.put(ressource, handler);
-    }
-
-    /**
-     * Cherche un serveur par broadcast
-     *
-     * @return Le nombre de serveur trouvé
-     */
-    public int findServer() {
-        this.finder.search("i'm a bomberstudent server");
-        return this.finder.getServers().size();
-    }
-
-    /**
-     * Selectionne un serveur pour s'y connecter
-     *
-     * @param index Le numero du serveur dans la liste
-     * @return Reussite
-     */
-    public boolean selectServer(int index) {
-        ArrayList<InetAddress> serv = this.finder.getServers();
-        if (!(index >= 0 && index < serv.size())) {
-            System.err.println("Index invalide");
-            return false;
-        }
-        //Lancement gestionnaire des requetes serveur
-        try {
-            this.request = new BomberStudentRequest(serv.get(index), this.portTcp + 1, handlers);
-            this.request.start();
-        } catch (IOException ex) {
-            return false;
-        }
-        //Creation socket d'envoi
-        this.socket = new TcpClient(serv.get(index), this.portTcp);
-        if (this.socket.connect()) {
-            this.connect = true;
-            return true;
-        }
-        return false;
-    }
-
-    /**
-     * Envoi requete sur le serveur
-     *
-     * @param method Methode d'envoi (POST ou GET)
-     * @param ressource Ressource demandée
-     * @return Reussite
-     */
-    public boolean send(String method, String ressource) {
-        return this.send(method, ressource, null);
-    }
-
-    /**
-     * Envoi requete sur le serveur
-     *
-     * @param method Methode d'envoi (POST ou GET)
-     * @param ressource Ressource demandée
-     * @param param Parametre JSON à envoyer au serveur
-     * @return Reussite
-     */
-    public boolean send(String method, String ressource, JSONObject param) {
-        //Verif que la methode existe
-        method = method.toUpperCase();
-        if (!method.equals("POST") && !method.equals("GET")) {
-            return false;
-        }
-        //Creation message pour envoi
-        String msg = method + " " + ressource;
-        if (param != null) {
-            msg += "\n" + param.toString();
-        }
-        //Envoi
-        this.socket.send(msg);
-        return true;
-    }
-
-    /**
-     * Attend une reponse du serveur
-     *
-     * @return La reponse analysée
-     */
-    public JSONObject receive() {
-        String msg = "";
-        /*do {
-            if(!msg.equals("")){
-                msg += "\n";
-            }
-            msg += this.socket.receive();
-        } while (msg.charAt(msg.length() - 1) != '}');*/
-        msg = this.socket.receive();
-        //System.out.println("Message : " + msg);
-        try {
-            return new JSONObject(msg);
-        } catch (JSONException ex) {
-            System.err.println("La reponse n'est pas en JSON : " + ex.getMessage());
-            return null;
-        }
-    }
-
-    /**
-     * Ferme la connexion
-     *
-     * @return Reussite
-     */
-    public boolean close() {
-        //Si connecté à un serveur
-        if (this.connect) {
-            this.connect = false;
-            //Avertit le serveur
-            this.send("POST", "client/end");
-            //Coupe le thread
-            this.request.interrupt();
-            //Verif que le thread est bien arréte
-            try {
-                Thread.sleep(3000);
-                if (this.request.isAlive()) {
-                    System.err.println("Imposible de tuer le thread de gestion des requetes");
-                }
-            } catch (InterruptedException ex) {
-
-            }
-            return this.socket.close();
-        }
-        return true;
-    }
-
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package rsx;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.HashMap;
+import org.json.JSONException;
+import org.json.JSONObject;
+import rsx.tcp.TcpClient;
+import rsx.udp.Broadcast;
+
+/**
+ * Connexion à un server BomberStudent
+ *
+ * @author Arthur Brandao
+ */
+public class BomberStudentClient {
+
+    /**
+     * Port pour le boradcast UDP
+     */
+    protected int portUdp;
+
+    /**
+     * Port pour la socket TCP
+     */
+    protected int portTcp;
+
+    /**
+     * Class pour broadcast
+     */
+    protected Broadcast finder;
+
+    /**
+     * Class pour le client TCP
+     */
+    protected TcpClient socket;
+
+    /**
+     * Si le client est conecter à un serveur en TCP
+     */
+    protected boolean connect;
+
+    /**
+     * Class de gestion des requetes serveurs
+     */
+    protected BomberStudentRequest request;
+
+    /**
+     * Liste des handlers pour gerer les requetes du serveur
+     */
+    protected HashMap<String, BomberStudentHandler> handlers = new HashMap<>();
+
+    /* --- Constructeurs --- */
+    /**
+     * Creation d'un client BomberStudent Le port 18624 est utilisé pour le
+     * broadcast udp Le port 18642 est utilisé pour la socket TCP
+     */
+    public BomberStudentClient() {
+        this.portUdp = 18624;
+        this.portTcp = 18642;
+        this.finder = new Broadcast(this.portUdp);
+    }
+
+    /**
+     * Creation d'un client BomberStudent
+     *
+     * @param portUdp Le port pour le broadcast UDP
+     * @param portTcp Le port pour la socket TCP
+     */
+    public BomberStudentClient(int portUdp, int portTcp) {
+        this.portUdp = portUdp;
+        this.portTcp = portTcp;
+        this.finder = new Broadcast(this.portUdp);
+    }
+
+    /* --- Methodes --- */
+    /**
+     * Ajoute un handler
+     *
+     * @param ressource Le nom de la ressource associè au handler
+     * @param handler Le handler
+     */
+    public void addHandler(String ressource, BomberStudentHandler handler) {
+        this.handlers.put(ressource, handler);
+    }
+
+    /**
+     * Cherche un serveur par broadcast
+     *
+     * @return Le nombre de serveur trouvé
+     */
+    public int findServer() {
+        this.finder.search("i'm a bomberstudent server");
+        return this.finder.getServers().size();
+    }
+
+    /**
+     * Selectionne un serveur pour s'y connecter
+     *
+     * @param index Le numero du serveur dans la liste
+     * @return Reussite
+     */
+    public boolean selectServer(int index) {
+        ArrayList<InetAddress> serv = this.finder.getServers();
+        if (!(index >= 0 && index < serv.size())) {
+            System.err.println("Index invalide");
+            return false;
+        }
+        //Lancement gestionnaire des requetes serveur
+        try {
+            this.request = new BomberStudentRequest(serv.get(index), this.portTcp + 1, handlers);
+            this.request.start();
+        } catch (IOException ex) {
+            return false;
+        }
+        //Creation socket d'envoi
+        this.socket = new TcpClient(serv.get(index), this.portTcp);
+        if (this.socket.connect()) {
+            this.connect = true;
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Envoi requete sur le serveur
+     *
+     * @param method Methode d'envoi (POST ou GET)
+     * @param ressource Ressource demandée
+     * @return Reussite
+     */
+    public boolean send(String method, String ressource) {
+        return this.send(method, ressource, null);
+    }
+
+    /**
+     * Envoi requete sur le serveur
+     *
+     * @param method Methode d'envoi (POST ou GET)
+     * @param ressource Ressource demandée
+     * @param param Parametre JSON à envoyer au serveur
+     * @return Reussite
+     */
+    public boolean send(String method, String ressource, JSONObject param) {
+        //Verif que la methode existe
+        method = method.toUpperCase();
+        if (!method.equals("POST") && !method.equals("GET")) {
+            return false;
+        }
+        //Creation message pour envoi
+        String msg = method + " " + ressource;
+        if (param != null) {
+            msg += "\n" + param.toString();
+        }
+        //Envoi
+        this.socket.send(msg);
+        return true;
+    }
+
+    /**
+     * Attend une reponse du serveur
+     *
+     * @return La reponse analysée
+     */
+    public JSONObject receive() {
+        String msg = "";
+        /*do {
+            if(!msg.equals("")){
+                msg += "\n";
+            }
+            msg += this.socket.receive();
+        } while (msg.charAt(msg.length() - 1) != '}');*/
+        msg = this.socket.receive();
+        //System.out.println("Message : " + msg);
+        try {
+            return new JSONObject(msg);
+        } catch (JSONException ex) {
+            System.err.println("La reponse n'est pas en JSON : " + ex.getMessage());
+            return null;
+        }
+    }
+
+    /**
+     * Ferme la connexion
+     *
+     * @return Reussite
+     */
+    public boolean close() {
+        //Si connecté à un serveur
+        if (this.connect) {
+            this.connect = false;
+            //Avertit le serveur
+            this.send("POST", "client/end");
+            //Coupe le thread
+            this.request.interrupt();
+            //Verif que le thread est bien arréte
+            try {
+                Thread.sleep(3000);
+                if (this.request.isAlive()) {
+                    System.err.println("Imposible de tuer le thread de gestion des requetes");
+                }
+            } catch (InterruptedException ex) {
+
+            }
+            return this.socket.close();
+        }
+        return true;
+    }
+
+}

+ 13 - 13
client/src/rsx/BomberStudentHandler.java

@@ -1,13 +1,13 @@
-package rsx;
-
-import org.json.JSONObject;
-
-/**
- * Interface des gestionnaires de requete du serveur
- * @author Arthur Brandao
- */
-public interface BomberStudentHandler {
-    
-    public boolean handle(JSONObject json);
-    
-}
+package rsx;
+
+import org.json.JSONObject;
+
+/**
+ * Interface des gestionnaires de requete du serveur
+ * @author Arthur Brandao
+ */
+public interface BomberStudentHandler {
+    
+    public boolean handle(JSONObject json);
+    
+}

+ 98 - 98
client/src/rsx/BomberStudentRequest.java

@@ -1,98 +1,98 @@
-package rsx;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.concurrent.atomic.AtomicBoolean;
-import org.json.JSONException;
-import org.json.JSONObject;
-import rsx.tcp.TcpClient;
-
-/**
- * Analyse les requetes emises par le serveur
- *
- * @author Arthur Brandao
- */
-public class BomberStudentRequest extends Thread {
-
-    /**
-     * Indique si on coupe la boucle
-     */
-    private final AtomicBoolean running = new AtomicBoolean(true);
-
-    /**
-     * Connexion au serveur
-     */
-    protected TcpClient socket;
-
-    /**
-     * Liste des handler à appeler
-     */
-    protected HashMap<String, BomberStudentHandler> handlers;
-
-    /* --- Constructeur --- */
-    public BomberStudentRequest(InetAddress adr, int port, HashMap<String, BomberStudentHandler> handlers) throws IOException {
-        this.handlers = handlers;
-        this.socket = new TcpClient(adr, port);
-        this.socket.timeout(2);
-        if (!this.socket.connect()) {
-            System.err.println("Impossible de créer la socket");
-            throw new IOException("Connexion impossible");
-        }
-    }
-
-    /* --- Surcharge --- */
-    @Override
-    public void interrupt() {
-        this.running.set(false);
-        super.interrupt();
-    }
-
-    @Override
-    public void run() {
-        //Tant qu'actif
-        while (this.running.get()) {
-            //Attente contact serveur
-            String entete = this.socket.receive();         
-            //Si rien on continue
-            if (entete == null) {
-                continue;
-            }
-            //On recup les parametres
-            String param = this.socket.receive();
-            //Si rien on continue
-            if (param == null) {
-                continue;
-            }
-            //Regarde la requete
-            String[] requete = entete.split(" ");
-            if (requete.length < 2) {
-                continue;
-            }
-            if (!requete[0].equals("POST")) {
-                continue;
-            }
-            //Regarde si il existe un handler
-            String ressource = requete[1];
-            if (!this.handlers.containsKey(ressource)) {
-                continue;
-            }
-            //Recup json
-            JSONObject json = null;
-            try {
-                json = new JSONObject(param);
-            } catch (JSONException ex) {
-                System.err.println("La requete n'est pas en JSON : " + ex.getMessage());
-                continue;
-            }
-            //Appel handler
-            BomberStudentHandler handler = this.handlers.get(ressource);
-            if(!handler.handle(json)){
-                System.err.println("Erreur pendant l'execution du handler " + ressource);
-            }
-        }
-        //Fermeture socket
-        this.socket.close();
-    }
-
-}
+package rsx;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.json.JSONException;
+import org.json.JSONObject;
+import rsx.tcp.TcpClient;
+
+/**
+ * Analyse les requetes emises par le serveur
+ *
+ * @author Arthur Brandao
+ */
+public class BomberStudentRequest extends Thread {
+
+    /**
+     * Indique si on coupe la boucle
+     */
+    private final AtomicBoolean running = new AtomicBoolean(true);
+
+    /**
+     * Connexion au serveur
+     */
+    protected TcpClient socket;
+
+    /**
+     * Liste des handler à appeler
+     */
+    protected HashMap<String, BomberStudentHandler> handlers;
+
+    /* --- Constructeur --- */
+    public BomberStudentRequest(InetAddress adr, int port, HashMap<String, BomberStudentHandler> handlers) throws IOException {
+        this.handlers = handlers;
+        this.socket = new TcpClient(adr, port);
+        this.socket.timeout(2);
+        if (!this.socket.connect()) {
+            System.err.println("Impossible de créer la socket");
+            throw new IOException("Connexion impossible");
+        }
+    }
+
+    /* --- Surcharge --- */
+    @Override
+    public void interrupt() {
+        this.running.set(false);
+        super.interrupt();
+    }
+
+    @Override
+    public void run() {
+        //Tant qu'actif
+        while (this.running.get()) {
+            //Attente contact serveur
+            String entete = this.socket.receive();         
+            //Si rien on continue
+            if (entete == null) {
+                continue;
+            }
+            //On recup les parametres
+            String param = this.socket.receive();
+            //Si rien on continue
+            if (param == null) {
+                continue;
+            }
+            //Regarde la requete
+            String[] requete = entete.split(" ");
+            if (requete.length < 2) {
+                continue;
+            }
+            if (!requete[0].equals("POST")) {
+                continue;
+            }
+            //Regarde si il existe un handler
+            String ressource = requete[1];
+            if (!this.handlers.containsKey(ressource)) {
+                continue;
+            }
+            //Recup json
+            JSONObject json = null;
+            try {
+                json = new JSONObject(param);
+            } catch (JSONException ex) {
+                System.err.println("La requete n'est pas en JSON : " + ex.getMessage());
+                continue;
+            }
+            //Appel handler
+            BomberStudentHandler handler = this.handlers.get(ressource);
+            if(!handler.handle(json)){
+                System.err.println("Erreur pendant l'execution du handler " + ressource);
+            }
+        }
+        //Fermeture socket
+        this.socket.close();
+    }
+
+}

+ 177 - 177
client/src/rsx/tcp/TcpClient.java

@@ -1,177 +1,177 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package rsx.tcp;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.net.UnknownHostException;
-
-/**
- *
- * @author loquicom
- */
-public class TcpClient {
-
-    /**
-     * Adresse du serveur
-     */
-    protected InetAddress adr;
-
-    /**
-     * Port du serveur
-     */
-    protected int port;
-
-    /**
-     * Socket TCP
-     */
-    protected Socket socket;
-
-    /**
-     * Timeout de la socket (en milisecondes)
-     */
-    protected int timeout = 0;
-
-    /**
-     * Flux d'entrée
-     */
-    protected BufferedReader input;
-
-    /**
-     * Flux de sorti
-     */
-    protected PrintWriter output;
-
-    /* --- Constructeurs --- */
-    /**
-     * Creation d'un client TCP
-     *
-     * @param ip L'ip du serveur
-     * @param port Le port du serveur
-     * @throws UnknownHostException
-     */
-    public TcpClient(String ip, int port) throws UnknownHostException {
-        this.adr = InetAddress.getByName(ip);
-        this.port = port;
-    }
-
-    /**
-     * Creation d'un client TCP
-     *
-     * @param adr L'adresse du serveur
-     * @param port Le port du serveur
-     */
-    public TcpClient(InetAddress adr, int port) {
-        this.adr = adr;
-        this.port = port;
-    }
-
-    /* --- Methodes --- */
-    /**
-     * Temps avant timeout du receive (qui retournera false)
-     * @param second Le temps en senconde
-     */
-    public void timeout(int second) {
-        this.timeout = second * 1000;
-    }
-
-    /**
-     * Retire un timeout
-     */
-    public void notimeout() {
-        this.timeout = 0;
-    }
-
-    /**
-     * Connexion au serveur
-     *
-     * @return Reussite
-     */
-    public boolean connect() {
-        try {
-            this.socket = new Socket(this.adr, this.port);
-            //Si un timeout
-            if (this.timeout > 0) {
-                this.socket.setSoTimeout(this.timeout);
-            }
-            //Ouverture flux
-            this.input = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
-            this.output = new PrintWriter(this.socket.getOutputStream());
-        } catch (IOException ex) {
-            System.err.println("Impossible de se connecter au serveur : " + ex.getMessage());
-            return false;
-        }
-        return true;
-    }
-
-    /**
-     * Envoi message au serveur
-     *
-     * @param msg Le message
-     * @return Reussite
-     */
-    public boolean send(String msg) {
-        output.print(msg);
-        output.flush();
-        return true;
-    }
-
-    /**
-     * Reception d'un message du serveur
-     *
-     * @return Le message ou null en cas d'erreur
-     */
-    public String receive() {
-        try {
-            return input.readLine();
-        } catch (IOException ex) {
-            //Si pas l'exception du timeout
-            if (!ex.getMessage().equals("Read timed out")) {
-                System.err.println("Impossible de lire : " + ex.getMessage() + " ");
-            }
-            return null;
-        }
-    }
-
-    /**
-     * Ferme la connexion au serveur
-     *
-     * @return Reussite
-     */
-    public boolean close() {
-        try {
-            input.close();
-            output.close();
-            socket.close();
-        } catch (IOException ex) {
-            System.err.println("Impossible de de fermer le client : " + ex.getMessage());
-            return false;
-        }
-        return true;
-    }
-
-    /* --- Getter/Setter --- */
-    public InetAddress getAdr() {
-        return adr;
-    }
-
-    public void setAdr(InetAddress adr) {
-        this.adr = adr;
-    }
-
-    public int getPort() {
-        return port;
-    }
-
-    public void setPort(int port) {
-        this.port = port;
-    }
-
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package rsx.tcp;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+
+/**
+ *
+ * @author loquicom
+ */
+public class TcpClient {
+
+    /**
+     * Adresse du serveur
+     */
+    protected InetAddress adr;
+
+    /**
+     * Port du serveur
+     */
+    protected int port;
+
+    /**
+     * Socket TCP
+     */
+    protected Socket socket;
+
+    /**
+     * Timeout de la socket (en milisecondes)
+     */
+    protected int timeout = 0;
+
+    /**
+     * Flux d'entrée
+     */
+    protected BufferedReader input;
+
+    /**
+     * Flux de sorti
+     */
+    protected PrintWriter output;
+
+    /* --- Constructeurs --- */
+    /**
+     * Creation d'un client TCP
+     *
+     * @param ip L'ip du serveur
+     * @param port Le port du serveur
+     * @throws UnknownHostException
+     */
+    public TcpClient(String ip, int port) throws UnknownHostException {
+        this.adr = InetAddress.getByName(ip);
+        this.port = port;
+    }
+
+    /**
+     * Creation d'un client TCP
+     *
+     * @param adr L'adresse du serveur
+     * @param port Le port du serveur
+     */
+    public TcpClient(InetAddress adr, int port) {
+        this.adr = adr;
+        this.port = port;
+    }
+
+    /* --- Methodes --- */
+    /**
+     * Temps avant timeout du receive (qui retournera false)
+     * @param second Le temps en senconde
+     */
+    public void timeout(int second) {
+        this.timeout = second * 1000;
+    }
+
+    /**
+     * Retire un timeout
+     */
+    public void notimeout() {
+        this.timeout = 0;
+    }
+
+    /**
+     * Connexion au serveur
+     *
+     * @return Reussite
+     */
+    public boolean connect() {
+        try {
+            this.socket = new Socket(this.adr, this.port);
+            //Si un timeout
+            if (this.timeout > 0) {
+                this.socket.setSoTimeout(this.timeout);
+            }
+            //Ouverture flux
+            this.input = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
+            this.output = new PrintWriter(this.socket.getOutputStream());
+        } catch (IOException ex) {
+            System.err.println("Impossible de se connecter au serveur : " + ex.getMessage());
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * Envoi message au serveur
+     *
+     * @param msg Le message
+     * @return Reussite
+     */
+    public boolean send(String msg) {
+        output.print(msg);
+        output.flush();
+        return true;
+    }
+
+    /**
+     * Reception d'un message du serveur
+     *
+     * @return Le message ou null en cas d'erreur
+     */
+    public String receive() {
+        try {
+            return input.readLine();
+        } catch (IOException ex) {
+            //Si pas l'exception du timeout
+            if (!ex.getMessage().equals("Read timed out")) {
+                System.err.println("Impossible de lire : " + ex.getMessage() + " ");
+            }
+            return null;
+        }
+    }
+
+    /**
+     * Ferme la connexion au serveur
+     *
+     * @return Reussite
+     */
+    public boolean close() {
+        try {
+            input.close();
+            output.close();
+            socket.close();
+        } catch (IOException ex) {
+            System.err.println("Impossible de de fermer le client : " + ex.getMessage());
+            return false;
+        }
+        return true;
+    }
+
+    /* --- Getter/Setter --- */
+    public InetAddress getAdr() {
+        return adr;
+    }
+
+    public void setAdr(InetAddress adr) {
+        this.adr = adr;
+    }
+
+    public int getPort() {
+        return port;
+    }
+
+    public void setPort(int port) {
+        this.port = port;
+    }
+
+}

+ 168 - 168
client/src/rsx/udp/Broadcast.java

@@ -1,168 +1,168 @@
-package rsx.udp;
-
-import java.io.IOException;
-import java.net.DatagramPacket;
-import java.net.DatagramSocket;
-import java.net.InetAddress;
-import java.net.SocketException;
-import java.net.SocketTimeoutException;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-
-/**
- * Broadcast pour trouver un serveur
- *
- * @author Arthur Brandao
- */
-public class Broadcast {
-
-    /**
-     * Port pour la socket UDP
-     */
-    protected int port;
-    
-    /**
-     * Le message à envoyer
-     */
-    protected String msg;
-    
-    /**
-     * TImeout
-     */
-    protected int timeout = 5000;
-    
-    /**
-     * Taille du buffer pour l'envoi
-     */
-    protected int bufferSize = 1024;
-    
-    /**
-     * Liste des serveurs ayant répondu
-     */
-    protected ArrayList<InetAddress> servers = new ArrayList<>();
-    
-    /* --- Constructeurs --- */
-
-    /**
-     * Creation d'un Broadcast
-     * @param port Le port à utiliser
-     */
-    public Broadcast(int port) {
-        this.port = port;
-        this.msg = "looking for bomberstudent servers";
-    }
-
-    /**
-     * Creation d'un Broadcast
-     * @param port Le port à utiliser
-     * @param msg Le message à envoyer
-     */
-    public Broadcast(int port, String msg) {
-        this.port = port;
-        this.msg = msg;
-    }
-    
-    /* --- Methodes --- */
-
-    /**
-     * Cherche les serveurs
-     * @param answer La reponse attendu du serveur
-     * @return Reussite
-     */
-    public boolean search(String answer) {
-        //Creation socket
-        DatagramSocket socket = null;
-        try {
-            socket = new DatagramSocket();
-            socket.setBroadcast(true);
-            socket.setSoTimeout(this.timeout);
-        } catch (SocketException ex) {
-            System.err.println("Erreur creation de la socket : " + ex.getMessage());
-            return false;
-        }
-
-        //Envoi message
-        byte[] buffer = this.msg.getBytes();
-        DatagramPacket packet;
-        try {
-            packet = new DatagramPacket(buffer, buffer.length, InetAddress.getByName("255.255.255.255"), this.port);
-            socket.send(packet);
-        } catch (UnknownHostException ex) {
-            System.err.println("Erreur hote inconnu : " + ex.getMessage());
-            return false;
-        } catch (IOException ex) {
-            System.err.println("Erreur IO : " + ex.getMessage());
-            return false;
-        }
-        
-        //Attente reponse
-        try {
-            while (true) {
-                //Recepetion reponse
-                byte[] tampon = new byte[this.bufferSize];
-                DatagramPacket dp = new DatagramPacket(tampon, tampon.length);
-                socket.receive(dp);
-                String reponse = new String(dp.getData(), 0, dp.getLength());
-                //Analyse reponse
-                if(reponse.equals(answer)){
-                    this.servers.add(dp.getAddress());
-                }
-            }
-        } catch (SocketTimeoutException ex) {
-            //Rien on fini la methode
-        } catch (IOException ex) {
-            System.err.println("Erreur IO : " + ex.getMessage());
-            return false;
-        }
-        
-        //Fin
-        socket.close();
-        return true;
-    }
-    
-    /**
-     * Vide la liste des serveurs
-     */
-    public void clean(){
-        this.servers = new ArrayList<>();
-    }
-    
-    /* --- Getter/Setter --- */
-
-    public int getPort() {
-        return port;
-    }
-
-    public void setPort(int port) {
-        this.port = port;
-    }
-
-    public String getMsg() {
-        return msg;
-    }
-
-    public void setMsg(String msg) {
-        this.msg = msg;
-    }
-
-    public int getTimeout() {
-        return timeout;
-    }
-
-    public void setTimeout(int timeout) {
-        this.timeout = timeout;
-    }
-
-    public int getBufferSize() {
-        return bufferSize;
-    }
-
-    public void setBufferSize(int bufferSize) {
-        this.bufferSize = bufferSize;
-    }
-    
-    public ArrayList<InetAddress> getServers(){
-        return new ArrayList<>(this.servers);
-    }
-
-}
+package rsx.udp;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.SocketException;
+import java.net.SocketTimeoutException;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+
+/**
+ * Broadcast pour trouver un serveur
+ *
+ * @author Arthur Brandao
+ */
+public class Broadcast {
+
+    /**
+     * Port pour la socket UDP
+     */
+    protected int port;
+    
+    /**
+     * Le message à envoyer
+     */
+    protected String msg;
+    
+    /**
+     * TImeout
+     */
+    protected int timeout = 5000;
+    
+    /**
+     * Taille du buffer pour l'envoi
+     */
+    protected int bufferSize = 1024;
+    
+    /**
+     * Liste des serveurs ayant répondu
+     */
+    protected ArrayList<InetAddress> servers = new ArrayList<>();
+    
+    /* --- Constructeurs --- */
+
+    /**
+     * Creation d'un Broadcast
+     * @param port Le port à utiliser
+     */
+    public Broadcast(int port) {
+        this.port = port;
+        this.msg = "looking for bomberstudent servers";
+    }
+
+    /**
+     * Creation d'un Broadcast
+     * @param port Le port à utiliser
+     * @param msg Le message à envoyer
+     */
+    public Broadcast(int port, String msg) {
+        this.port = port;
+        this.msg = msg;
+    }
+    
+    /* --- Methodes --- */
+
+    /**
+     * Cherche les serveurs
+     * @param answer La reponse attendu du serveur
+     * @return Reussite
+     */
+    public boolean search(String answer) {
+        //Creation socket
+        DatagramSocket socket = null;
+        try {
+            socket = new DatagramSocket();
+            socket.setBroadcast(true);
+            socket.setSoTimeout(this.timeout);
+        } catch (SocketException ex) {
+            System.err.println("Erreur creation de la socket : " + ex.getMessage());
+            return false;
+        }
+
+        //Envoi message
+        byte[] buffer = this.msg.getBytes();
+        DatagramPacket packet;
+        try {
+            packet = new DatagramPacket(buffer, buffer.length, InetAddress.getByName("255.255.255.255"), this.port);
+            socket.send(packet);
+        } catch (UnknownHostException ex) {
+            System.err.println("Erreur hote inconnu : " + ex.getMessage());
+            return false;
+        } catch (IOException ex) {
+            System.err.println("Erreur IO : " + ex.getMessage());
+            return false;
+        }
+        
+        //Attente reponse
+        try {
+            while (true) {
+                //Recepetion reponse
+                byte[] tampon = new byte[this.bufferSize];
+                DatagramPacket dp = new DatagramPacket(tampon, tampon.length);
+                socket.receive(dp);
+                String reponse = new String(dp.getData(), 0, dp.getLength());
+                //Analyse reponse
+                if(reponse.equals(answer)){
+                    this.servers.add(dp.getAddress());
+                }
+            }
+        } catch (SocketTimeoutException ex) {
+            //Rien on fini la methode
+        } catch (IOException ex) {
+            System.err.println("Erreur IO : " + ex.getMessage());
+            return false;
+        }
+        
+        //Fin
+        socket.close();
+        return true;
+    }
+    
+    /**
+     * Vide la liste des serveurs
+     */
+    public void clean(){
+        this.servers = new ArrayList<>();
+    }
+    
+    /* --- Getter/Setter --- */
+
+    public int getPort() {
+        return port;
+    }
+
+    public void setPort(int port) {
+        this.port = port;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    public int getTimeout() {
+        return timeout;
+    }
+
+    public void setTimeout(int timeout) {
+        this.timeout = timeout;
+    }
+
+    public int getBufferSize() {
+        return bufferSize;
+    }
+
+    public void setBufferSize(int bufferSize) {
+        this.bufferSize = bufferSize;
+    }
+    
+    public ArrayList<InetAddress> getServers(){
+        return new ArrayList<>(this.servers);
+    }
+
+}