Procházet zdrojové kódy

Ajout menu client + Sprite major

Arthur Brandao před 6 roky
rodič
revize
f891c91795
59 změnil soubory, kde provedl 941 přidání a 149 odebrání
  1. binární
      BSWFX/dist/BSWFX.jar
  2. 0 32
      BSWFX/dist/README.TXT
  3. 10 0
      BSWFX/dist/file/css/map.css
  4. 14 0
      BSWFX/dist/file/css/menu.css
  5. binární
      BSWFX/dist/file/img.png
  6. 0 0
      BSWFX/dist/file/index.html
  7. 15 0
      BSWFX/dist/file/menu.html
  8. binární
      BSWFX/dist/file/sprite - BS/player_md.png
  9. binární
      BSWFX/dist/file/sprite - BS/player_ml.png
  10. binární
      BSWFX/dist/file/sprite - BS/player_mr.png
  11. binární
      BSWFX/dist/file/sprite - BS/player_mu.png
  12. binární
      BSWFX/dist/file/sprite - Test/player_md.png
  13. binární
      BSWFX/dist/file/sprite - Test/player_ml.png
  14. binární
      BSWFX/dist/file/sprite - Test/player_mr.png
  15. binární
      BSWFX/dist/file/sprite - Test/player_mu.png
  16. binární
      BSWFX/dist/file/sprite/player_md.png
  17. binární
      BSWFX/dist/file/sprite/player_ml.png
  18. binární
      BSWFX/dist/file/sprite/player_mr.png
  19. binární
      BSWFX/dist/file/sprite/player_mu.png
  20. 2 1
      BSWFX/dist/file/webfx/config.json
  21. 10 0
      BSWFX/file/css/map.css
  22. 14 0
      BSWFX/file/css/menu.css
  23. binární
      BSWFX/file/img.png
  24. 0 0
      BSWFX/file/index.html
  25. 15 0
      BSWFX/file/menu.html
  26. binární
      BSWFX/file/sprite - BS/player_md.png
  27. binární
      BSWFX/file/sprite - BS/player_ml.png
  28. binární
      BSWFX/file/sprite - BS/player_mr.png
  29. binární
      BSWFX/file/sprite - BS/player_mu.png
  30. binární
      BSWFX/file/sprite - Test/player_md.png
  31. binární
      BSWFX/file/sprite - Test/player_ml.png
  32. binární
      BSWFX/file/sprite - Test/player_mr.png
  33. binární
      BSWFX/file/sprite - Test/player_mu.png
  34. binární
      BSWFX/file/sprite/player_md.png
  35. binární
      BSWFX/file/sprite/player_ml.png
  36. binární
      BSWFX/file/sprite/player_mr.png
  37. binární
      BSWFX/file/sprite/player_mu.png
  38. 2 1
      BSWFX/file/webfx/config.json
  39. 102 0
      BSWFX/src/bs/Create.java
  40. 24 5
      BSWFX/src/bs/Game.java
  41. 81 0
      BSWFX/src/bs/Join.java
  42. 59 0
      BSWFX/src/bs/Menu.java
  43. 25 60
      BSWFX/src/bswfx/BomberStudent.java
  44. 103 10
      BSWFX/src/bswfx/KeyHandler.java
  45. 5 3
      BSWFX/src/bswfx/ScreenManager.java
  46. 5 1
      BSWFX/src/bswfx/handler/HandlerMajorEnd.java
  47. 2 0
      BSWFX/src/bswfx/handler/HandlerServerEnd.java
  48. 23 0
      BSWFX/src/test/HandlerAttackAffect.java
  49. 23 0
      BSWFX/src/test/HandlerAttackBomb.java
  50. 23 0
      BSWFX/src/test/HandlerAttackExplode.java
  51. 23 0
      BSWFX/src/test/HandlerPlayerJoin.java
  52. 23 0
      BSWFX/src/test/HandlerPlayerMajorEnd.java
  53. 23 0
      BSWFX/src/test/HandlerPlayerMove.java
  54. 23 0
      BSWFX/src/test/HandlerPlayerQuit.java
  55. 21 0
      BSWFX/src/test/HandlerServerEnd.java
  56. 42 0
      BSWFX/src/test/ServerTest.java
  57. 168 0
      BSWFX/src/test/TestServer.java
  58. 57 36
      BSWFX/src/wfx/WebFx.java
  59. 4 0
      BSWFX/src/wfx/WebFxConfig.java

binární
BSWFX/dist/BSWFX.jar


+ 0 - 32
BSWFX/dist/README.TXT

@@ -1,32 +0,0 @@
-========================
-BUILD OUTPUT DESCRIPTION
-========================
-
-When you build an Java application project that has a main class, the IDE
-automatically copies all of the JAR
-files on the projects classpath to your projects dist/lib folder. The IDE
-also adds each of the JAR files to the Class-Path element in the application
-JAR files manifest file (MANIFEST.MF).
-
-To run the project from the command line, go to the dist folder and
-type the following:
-
-java -jar "BSWFX.jar" 
-
-To distribute this project, zip up the dist folder (including the lib folder)
-and distribute the ZIP file.
-
-Notes:
-
-* If two JAR files on the project classpath have the same name, only the first
-JAR file is copied to the lib folder.
-* Only JAR files are copied to the lib folder.
-If the classpath contains other types of files or folders, these files (folders)
-are not copied.
-* If a library on the projects classpath also has a Class-Path element
-specified in the manifest,the content of the Class-Path element has to be on
-the projects runtime path.
-* To set a main class in a standard Java project, right-click the project node
-in the Projects window and choose Properties. Then click Run and enter the
-class name in the Main Class field. Alternatively, you can manually type the
-class name in the manifest Main-Class element.

+ 10 - 0
BSWFX/dist/file/css/map.css

@@ -18,4 +18,14 @@ img{
   	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 - 0
BSWFX/dist/file/css/menu.css

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

binární
BSWFX/dist/file/img.png


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
BSWFX/dist/file/index.html


+ 15 - 0
BSWFX/dist/file/menu.html

@@ -0,0 +1,15 @@
+<style type="text/css">
+	button{
+		width: 100%;
+		height: 33%;
+		color: black;
+	}
+
+	#select{
+		border: 5px blue solid;
+	}
+</style> 
+
+<button disabled>A</button>
+<button id="select" disabled>B</button>
+<button disabled>C</button>

binární
BSWFX/dist/file/sprite - BS/player_md.png


binární
BSWFX/dist/file/sprite - BS/player_ml.png


binární
BSWFX/dist/file/sprite - BS/player_mr.png


binární
BSWFX/dist/file/sprite - BS/player_mu.png


binární
BSWFX/dist/file/sprite - Test/player_md.png


binární
BSWFX/dist/file/sprite - Test/player_ml.png


binární
BSWFX/dist/file/sprite - Test/player_mr.png


binární
BSWFX/dist/file/sprite - Test/player_mu.png


binární
BSWFX/dist/file/sprite/player_md.png


binární
BSWFX/dist/file/sprite/player_ml.png


binární
BSWFX/dist/file/sprite/player_mr.png


binární
BSWFX/dist/file/sprite/player_mu.png


+ 2 - 1
BSWFX/dist/file/webfx/config.json

@@ -6,5 +6,6 @@
 		"html" : "file/webfx/loader.html"
 	},
 	"width" : 1000,
-	"height": 1000
+	"height": 1000,
+	"zoom": 1.0
 }

+ 10 - 0
BSWFX/file/css/map.css

@@ -18,4 +18,14 @@ img{
   	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 - 0
BSWFX/file/css/menu.css

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

binární
BSWFX/file/img.png


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
BSWFX/file/index.html


+ 15 - 0
BSWFX/file/menu.html

@@ -0,0 +1,15 @@
+<style type="text/css">
+	button{
+		width: 100%;
+		height: 33%;
+		color: black;
+	}
+
+	#select{
+		border: 5px blue solid;
+	}
+</style> 
+
+<button disabled>A</button>
+<button id="select" disabled>B</button>
+<button disabled>C</button>

binární
BSWFX/file/sprite - BS/player_md.png


binární
BSWFX/file/sprite - BS/player_ml.png


binární
BSWFX/file/sprite - BS/player_mr.png


binární
BSWFX/file/sprite - BS/player_mu.png


binární
BSWFX/file/sprite - Test/player_md.png


binární
BSWFX/file/sprite - Test/player_ml.png


binární
BSWFX/file/sprite - Test/player_mr.png


binární
BSWFX/file/sprite - Test/player_mu.png


binární
BSWFX/file/sprite/player_md.png


binární
BSWFX/file/sprite/player_ml.png


binární
BSWFX/file/sprite/player_mr.png


binární
BSWFX/file/sprite/player_mu.png


+ 2 - 1
BSWFX/file/webfx/config.json

@@ -6,5 +6,6 @@
 		"html" : "file/webfx/loader.html"
 	},
 	"width" : 1000,
-	"height": 1000
+	"height": 1000,
+	"zoom": 1.0
 }

+ 102 - 0
BSWFX/src/bs/Create.java

@@ -0,0 +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());
+    }
+
+}

+ 24 - 5
BSWFX/src/bs/Game.java

@@ -6,9 +6,11 @@
 package bs;
 
 import bswfx.BomberStudent;
+import bswfx.ScreenManager;
 import java.util.HashMap;
 import org.json.JSONArray;
 import org.json.JSONObject;
+import wfx.WebFx;
 
 /**
  *
@@ -279,8 +281,7 @@ public class Game {
         if (type == Player.FIREPOWER) {
             p.setFirepower(p.getFirepower() + 1);
         } else if (type == Player.MAJOR) {
-            System.out.println("Get major");
-            //p.setMajor(true); Inutile le serveur n'envoi pas les infos de degats pendant la durée du Major
+            p.setMajor(true);
         }
         return true;
     }
@@ -304,7 +305,7 @@ public class Game {
             if (newLife > 0) {
                 p.setLife(newLife);
             } else {
-                BomberStudent.end();
+                this.gameOver();
             }
         }
     }
@@ -320,10 +321,25 @@ public class Game {
         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();
+    }
 
     /* --- Méthodes affichage --- */
     public String toHtml() {
-        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\"><table><tbody>";
+        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++) {
@@ -407,8 +423,11 @@ public class Game {
                     case '8':
                     case '9':
                         Player p = this.player.get(Integer.parseInt(this.map[j][i]));
-                        if (p.main) {
+                        if (p.isMain()) {
                             html += "file/sprite/player_";
+                            if(p.isMajor()){
+                                html += "m";
+                            }
                             switch(p.dir){
                                 case Player.UP:
                                     html += "u.png";

+ 81 - 0
BSWFX/src/bs/Join.java

@@ -0,0 +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());
+    }
+
+}

+ 59 - 0
BSWFX/src/bs/Menu.java

@@ -0,0 +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());
+    }
+    
+}

+ 25 - 60
BSWFX/src/bswfx/BomberStudent.java

@@ -5,9 +5,11 @@
  */
 package bswfx;
 
+import bs.Create;
 import bswfx.handler.*;
 import bs.Game;
-import org.json.JSONArray;
+import bs.Join;
+import bs.Menu;
 import org.json.JSONObject;
 import rsx.BomberStudentClient;
 import wfx.WebFx;
@@ -19,10 +21,11 @@ import wfx.WebFx;
 public class BomberStudent {
     
     public static WebFx wfx = new WebFx();
-    
     public static BomberStudentClient bsc = new BomberStudentClient();
-    
-    public static Game game;
+    public static Game game;  
+    public static Menu menu;
+    public static Create create;
+    public static Join join;
 
     /**
      * @param args the command line arguments
@@ -52,7 +55,8 @@ public class BomberStudent {
         //Recherche serveur actif
         int nbRes = bsc.findServer();
         if (nbRes == 0) {
-            System.err.println("Aucun serveur");
+            wfx.alert("Erreur", "Aucun serveur trouvé");
+            waitWfx();
             wfx.end();
             System.exit(0);
         }
@@ -60,62 +64,13 @@ public class BomberStudent {
         
         //Connexion serveur et recup liste des games
         bsc.selectServer(0);
-        bsc.send("GET", "game/list");
-        res = bsc.receive();
         
-        //Verif si une game de test existe
-        boolean gameTest = false;
-        if(res.getInt("numberGameList") != 0){
-            JSONArray ja = res.getJSONArray("games");
-            for(int i = 0; i < ja.length(); i++){
-                JSONObject jo = ja.getJSONObject(i);
-                if(jo.getString("name").equals("gameTest")){
-                    gameTest = true;
-                    break;
-                }
-            }
-        }
-        //Si pas de game creation
-        if(!gameTest){
-            //Verif que la mapTest est présente
-            JSONArray ja = res.getJSONArray("maps");
-            boolean present = false;
-            for(int i = 0; i < ja.length(); i++){
-                if(ja.getString(i).equals("mapTest")){
-                    present = true;
-                    break;
-                }
-            }
-            if(!present){
-                System.err.println("La map de test n'est pas présente sur le serveur");
-                end();
-            }
-            //Creation game
-            param = new JSONObject();
-            param.put("name", "gameTest");
-            param.put("map", "mapTest");
-            bsc.send("POST", "game/create", param);
-            res = bsc.receive();
-            if(res.getInt("status") != 201){
-                System.err.println("Impossible de créer la game");
-                end();
-            }
-        } 
-        //Sinon on rejoint
-        else {
-            param = new JSONObject();
-            param.put("name", "gameTest");
-            bsc.send("POST", "game/join", param);
-            res = bsc.receive();
-            if(res.getInt("status") != 201){
-                System.err.println("Impossible de rejoindre la game");
-                end();
-            }
-        }
-        //Creation game
-        game = new Game(res);
-        updateWindow();
-        ScreenManager.setScreen(ScreenManager.GAME_SCREEN);
+        //Verif affichage ok
+        while(!WebFx.ini.get());
+        
+        //Affichage menu
+        menu = new Menu();
+        menu.show();
     }
     
     public static void updateWindow(){
@@ -127,5 +82,15 @@ public class BomberStudent {
         bsc.close();
         System.exit(0);
     }
+    
+    public static void waitWfx(){
+        while(wfx.wait.get()){
+            try{
+                Thread.sleep(1000);
+            } catch(Exception ex) {
+                
+            }
+        }
+    }
 
 }

+ 103 - 10
BSWFX/src/bswfx/KeyHandler.java

@@ -5,8 +5,12 @@
  */
 package bswfx;
 
+import bs.Create;
+import bs.Join;
+import bs.Menu;
 import bs.Player;
 import javafx.scene.input.KeyEvent;
+import wfx.WebFx;
 
 /**
  *
@@ -17,40 +21,129 @@ public class KeyHandler {
     public static void manage(KeyEvent ke) {
         switch (ScreenManager.getScreen()) {
             case ScreenManager.GAME_SCREEN:
-                //System.out.println("Key : " + ke.getText());
                 gameEvent(ke);
                 break;
+            case ScreenManager.END_SCREEN:
+                WebFx.wait.set(false);
+                break;
+            case ScreenManager.MENU_SCREEN:
+                menuEvent(ke);
+                break;
+            case ScreenManager.CREATE_SCREEN:
+                createEvent(ke);
+                break;
+            case ScreenManager.JOIN_SCREEN:
+                joinEvent(ke);
         }
     }
 
     protected static void gameEvent(KeyEvent ke) {
         //Recup le joueur principale
         Player p = BomberStudent.game.getPlayer(BomberStudent.game.getMainPlayerId());
-        switch (ke.getText()) {
-            case "z":
+        switch (ke.getCode()) {
+            case Z:
                 p.move(Player.UP);
                 break;
-            case "q":
+            case Q:
                 p.move(Player.LEFT);
                 break;
-            case "s":
+            case S:
                 p.move(Player.DOWN);
                 break;
-            case "d":
+            case D:
                 p.move(Player.RIGHT);
                 break;
-            case "a":
+            case A:
                 p.attack(Player.CLASSIC);
                 break;
-            case "e":
+            case E:
                 p.attack(Player.MINE);
                 break;
-            case "r":
+            case R:
                 p.attack(Player.REMOTE);
                 break;
-            case "f":
+            case F:
                 BomberStudent.bsc.send("POST", "attack/remote/go");
                 break;
+            case ESCAPE:
+                BomberStudent.bsc.send("POST", "game/quit");
+                BomberStudent.menu = new Menu();
+                BomberStudent.menu.show();
+                break;
+        }
+    }
+
+    protected static void menuEvent(KeyEvent ke) {
+        switch (ke.getCode()) {
+            case Z:
+                BomberStudent.menu.up();
+                BomberStudent.menu.show();
+                break;
+            case S:
+                BomberStudent.menu.down();
+                BomberStudent.menu.show();
+                break;
+            case ENTER:
+                switch (BomberStudent.menu.getAction()) {
+                    case Menu.QUIT:
+                        BomberStudent.end();
+                        break;
+                    case Menu.CREATE:
+                        BomberStudent.create = new Create();
+                        BomberStudent.create.show();
+                        break;
+                    case Menu.JOIN:
+                        BomberStudent.join = new Join();
+                        BomberStudent.join.show();
+                        break;
+                }
+                break;
+        }
+    }
+
+    public static void createEvent(KeyEvent ke) {
+        if (BomberStudent.create.getMode() == Create.NAME_MODE) {
+            switch (ke.getCode()) {
+                case ENTER:
+                    BomberStudent.create.changeMode(Create.CHOOSE_MODE);
+                    break;
+                default:
+                    BomberStudent.create.generateName(ke);
+                    break;
+            }
+            BomberStudent.create.show();
+        } else {
+            switch (ke.getCode()) {
+                case Z:
+                    BomberStudent.create.up();
+                    BomberStudent.create.show();
+                    break;
+                case S:
+                    BomberStudent.create.down();
+                    BomberStudent.create.show();
+                    break;
+                case ENTER:
+                    BomberStudent.create.createGame();
+                    BomberStudent.updateWindow();
+                    break;
+            }
+        }
+    }
+
+    public static void joinEvent(KeyEvent ke) {
+        switch (ke.getCode()) {
+            case Z:
+                BomberStudent.join.up();
+                BomberStudent.join.show();
+                break;
+            case S:
+                BomberStudent.join.down();
+                BomberStudent.join.show();
+                break;
+            case ENTER:
+                BomberStudent.join.connect();
+                BomberStudent.updateWindow();
+                break;
         }
     }
 

+ 5 - 3
BSWFX/src/bswfx/ScreenManager.java

@@ -13,6 +13,10 @@ 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;
     
@@ -21,9 +25,7 @@ public class ScreenManager {
     }
     
     public static void setScreen(int screen){
-        if(!( screen != LOADING_SCREEN && screen != GAME_SCREEN )){
-            ScreenManager.screen = screen;
-        }
+        ScreenManager.screen = screen;
     }
     
 }

+ 5 - 1
BSWFX/src/bswfx/handler/HandlerMajorEnd.java

@@ -5,8 +5,10 @@
  */
 package bswfx.handler;
 
+import bs.Player;
 import org.json.JSONObject;
 import rsx.BomberStudentHandler;
+import bswfx.BomberStudent;
 
 /**
  *
@@ -16,7 +18,9 @@ public class HandlerMajorEnd implements BomberStudentHandler{
 
     @Override
     public boolean handle(JSONObject json) {
-        System.out.println("Fin major");
+        Player p = BomberStudent.game.getPlayer(BomberStudent.game.getMainPlayerId());
+        p.setMajor(false);
+        BomberStudent.updateWindow();
         return true;
     }
     

+ 2 - 0
BSWFX/src/bswfx/handler/HandlerServerEnd.java

@@ -17,6 +17,8 @@ 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;
     }

+ 23 - 0
BSWFX/src/test/HandlerAttackAffect.java

@@ -0,0 +1,23 @@
+/*
+ * 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 test;
+
+import org.json.JSONObject;
+import rsx.BomberStudentHandler;
+
+/**
+ *
+ * @author loquicom
+ */
+public class HandlerAttackAffect implements BomberStudentHandler {
+
+    @Override
+    public boolean handle(JSONObject json) {
+        System.out.println("Handler Attack Affect : " + json.toString(1));
+        return true;
+    }
+    
+}

+ 23 - 0
BSWFX/src/test/HandlerAttackBomb.java

@@ -0,0 +1,23 @@
+/*
+ * 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 test;
+
+import org.json.JSONObject;
+import rsx.BomberStudentHandler;
+
+/**
+ *
+ * @author loquicom
+ */
+public class HandlerAttackBomb implements BomberStudentHandler{
+
+    @Override
+    public boolean handle(JSONObject json) {
+        System.out.println("Handler Attack Bomb : " + json.toString(1));
+        return true;
+    }
+    
+}

+ 23 - 0
BSWFX/src/test/HandlerAttackExplode.java

@@ -0,0 +1,23 @@
+/*
+ * 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 test;
+
+import org.json.JSONObject;
+import rsx.BomberStudentHandler;
+
+/**
+ *
+ * @author loquicom
+ */
+public class HandlerAttackExplode implements BomberStudentHandler {
+
+    @Override
+    public boolean handle(JSONObject json) {
+        System.out.println("Handler Attack Explode : " + json.toString(1));
+        return true;
+    }
+    
+}

+ 23 - 0
BSWFX/src/test/HandlerPlayerJoin.java

@@ -0,0 +1,23 @@
+/*
+ * 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 test;
+
+import org.json.JSONObject;
+import rsx.BomberStudentHandler;
+
+/**
+ *
+ * @author loquicom
+ */
+public class HandlerPlayerJoin implements BomberStudentHandler{
+
+    @Override
+    public boolean handle(JSONObject json) {
+        System.out.println("Join Handler : " + json.toString(1));
+        return true;
+    }
+    
+}

+ 23 - 0
BSWFX/src/test/HandlerPlayerMajorEnd.java

@@ -0,0 +1,23 @@
+/*
+ * 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 test;
+
+import org.json.JSONObject;
+import rsx.BomberStudentHandler;
+
+/**
+ *
+ * @author loquicom
+ */
+public class HandlerPlayerMajorEnd implements BomberStudentHandler{
+
+    @Override
+    public boolean handle(JSONObject json) {
+        System.out.println("Player Major End Handler : " + json.toString(1));
+        return true;
+    }
+    
+}

+ 23 - 0
BSWFX/src/test/HandlerPlayerMove.java

@@ -0,0 +1,23 @@
+/*
+ * 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 test;
+
+import org.json.JSONObject;
+import rsx.BomberStudentHandler;
+
+/**
+ *
+ * @author loquicom
+ */
+public class HandlerPlayerMove implements BomberStudentHandler{
+
+    @Override
+    public boolean handle(JSONObject json) {
+        System.out.println("Player Move Handler : " + json.toString(1));
+        return true;
+    }
+    
+}

+ 23 - 0
BSWFX/src/test/HandlerPlayerQuit.java

@@ -0,0 +1,23 @@
+/*
+ * 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 test;
+
+import org.json.JSONObject;
+import rsx.BomberStudentHandler;
+
+/**
+ *
+ * @author loquicom
+ */
+public class HandlerPlayerQuit implements BomberStudentHandler{
+
+    @Override
+    public boolean handle(JSONObject json) {
+        System.out.println("Player quit : " + json.toString(1));
+        return true;
+    }
+    
+}

+ 21 - 0
BSWFX/src/test/HandlerServerEnd.java

@@ -0,0 +1,21 @@
+package test;
+
+import org.json.JSONObject;
+import rsx.BomberStudentClient;
+import rsx.BomberStudentHandler;
+
+/**
+ *
+ * @author Arthur Brandao
+ */
+public class HandlerServerEnd implements BomberStudentHandler{
+
+    @Override
+    public boolean handle(JSONObject json) {
+        System.out.println("Handler server/end");
+        ServerTest.code = Integer.parseInt(json.getString("statut"));
+        ServerTest.stop.set(true);
+        return true;
+    }
+    
+}

+ 42 - 0
BSWFX/src/test/ServerTest.java

@@ -0,0 +1,42 @@
+package test;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.json.JSONObject;
+import rsx.BomberStudentClient;
+
+/**
+ * Exemple appel vers le serveur
+ * @author Arthur Brandao
+ */
+public class ServerTest {
+    
+    public static AtomicBoolean stop = new AtomicBoolean(false);
+    public static int code = -1;
+
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String[] args) {
+        //Creation client BomberStudent
+        BomberStudentClient bsc = new BomberStudentClient();
+        //Ajout handler
+        bsc.addHandler("server/end", new HandlerServerEnd());
+        //Recherche serveur actif
+        int nbRes = bsc.findServer();
+        if(nbRes == 0){
+            System.err.println("Aucun serveur");
+            return;
+        }
+        //Selectionne le 1er serveur qui à repondu
+        bsc.selectServer(0);
+        //Attend fin serveur
+        System.out.println("Attente");
+        while(!stop.get()){
+            
+        }
+        System.out.println("Code : " + code);
+        bsc.close();
+        //*/
+    }
+    
+}

+ 168 - 0
BSWFX/src/test/TestServer.java

@@ -0,0 +1,168 @@
+/*
+ * 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 test;
+
+import org.json.JSONObject;
+import rsx.BomberStudentClient;
+
+/**
+ *
+ * @author loquicom
+ */
+public class TestServer {
+
+    public static void main(String[] args) throws InterruptedException {
+        //Creation client BomberStudent
+        BomberStudentClient bsc = new BomberStudentClient();
+        //Ajout handler
+        bsc.addHandler("server/end", new HandlerServerEnd());
+        bsc.addHandler("game/newplayer", new HandlerPlayerJoin());
+        bsc.addHandler("game/quit", new HandlerPlayerQuit());
+        bsc.addHandler("player/position/update", new HandlerPlayerMove());
+        bsc.addHandler("player/major/end", new HandlerPlayerMajorEnd());
+        bsc.addHandler("attack/newbomb", new HandlerAttackBomb());
+        bsc.addHandler("attack/affect", new HandlerAttackAffect());
+        bsc.addHandler("attack/explose", new HandlerAttackExplode());
+        //Recherche serveur actif
+        int nbRes = bsc.findServer();
+        if (nbRes == 0) {
+            System.err.println("Aucun serveur");
+            return;
+        }
+        //Selectionne le 1er serveur qui à repondu
+        System.out.println("Connexion");
+        bsc.selectServer(0);
+        
+        //Execute une/des requetes(s)
+        /*
+        System.out.println("Envoi");
+        if(!bsc.send("GET", "nop")){
+            System.err.println("Impossible envoyer la requete");
+            return;
+        }
+        System.out.println("Reception");
+        print(bsc.receive());
+        //*/
+        /*
+        Thread.sleep(10000);
+        //*/
+        /*
+        bsc.send("GET", "game/list");
+        JSONObject json = bsc.receive();
+        System.out.println(json.toString(1));
+        //*/
+        /*
+        JSONObject param = new JSONObject();
+        param.put("name", "gameTest");
+        param.put("map", "map1");
+        bsc.send("POST", "game/create", param);
+        JSONObject json = bsc.receive();
+        System.out.println(json.toString(1));
+        Thread.sleep(30000);
+        bsc.send("GET", "game/list");
+        json = bsc.receive();
+        System.out.println(json.toString(1));
+        param = new JSONObject();
+        param.put("move", "right");
+        bsc.send("POST", "player/move", param);
+        //bsc.send("POST", "game/quit");
+        //*/
+        /*
+        JSONObject param = new JSONObject();
+        param.put("name", "gameTest");
+        bsc.send("POST", "game/join", param);
+        JSONObject json = bsc.receive();
+        System.out.println(json.toString(1));
+        bsc.send("GET", "game/list");
+        json = bsc.receive();
+        System.out.println(json.toString(1));
+        param = new JSONObject();
+        param.put("move", "right");
+        bsc.send("POST", "player/move", param);
+        param = new JSONObject();
+        param.put("move", "left");
+        bsc.send("POST", "player/move", param);
+        param = new JSONObject();
+        param.put("move", "up");
+        bsc.send("POST", "player/move", param);
+        //*/
+        /*
+        JSONObject param = new JSONObject();
+        param.put("name", "gameTest");
+        param.put("map", "map1");
+        bsc.send("POST", "game/create", param);
+        JSONObject json = bsc.receive();
+        System.out.println(json.toString(1));
+        Thread.sleep(2000);
+        param = new JSONObject();
+        param.put("class", "major");
+        bsc.send("POST", "object/new", param);
+        json = bsc.receive();
+        System.out.println(json.toString(1));
+        Thread.sleep(10000);
+        //*/
+        
+        /*
+        JSONObject param = new JSONObject();
+        param.put("name", "gameTest");
+        param.put("map", "map1");
+        bsc.send("POST", "game/create", param);
+        JSONObject json = bsc.receive();
+        System.out.println(json.toString(1));
+        Thread.sleep(20000);
+        //*/
+        /*
+        JSONObject param = new JSONObject();
+        param.put("name", "gameTest");
+        bsc.send("POST", "game/join", param);
+        JSONObject json = bsc.receive();
+        System.out.println(json.toString(1));
+        param = new JSONObject();
+        param.put("class", "mine");
+        param.put("pos", "2,1");
+        bsc.send("POST", "attack/bomb", param);
+        json = bsc.receive();
+        System.out.println(json.toString(1));
+        //*/
+        
+        JSONObject param = new JSONObject();
+        param.put("name", "gameTest");
+        param.put("map", "map1");
+        bsc.send("POST", "game/create", param);
+        JSONObject json = bsc.receive();
+        System.out.println(json.toString(1));
+        param = new JSONObject();
+        param.put("class", "remote");
+        param.put("pos", "2,1");
+        bsc.send("POST", "attack/bomb", param);
+        json = bsc.receive();
+        System.out.println(json.toString(1));
+        param.put("class", "classic");
+        param.put("pos", "3,1");
+        bsc.send("POST", "attack/bomb", param);
+        json = bsc.receive();
+        System.out.println(json.toString(1));
+        bsc.send("POST", "attack/remote/go");
+        Thread.sleep(5000);
+        param = new JSONObject();
+        param.put("class", "remote");
+        param.put("pos", "3,5");
+        bsc.send("POST", "attack/bomb", param);
+        json = bsc.receive();
+        System.out.println(json.toString(1));
+        bsc.send("POST", "attack/remote/go");
+        
+        bsc.close();
+    }
+
+    public static void print(JSONObject json) {
+        if (json != null) {
+            System.out.println("Code : " + json.getString("statut"));
+            System.out.println("Message : " + json.getString("message"));
+        }
+    }
+
+}

+ 57 - 36
BSWFX/src/wfx/WebFx.java

@@ -12,9 +12,12 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
+import java.util.concurrent.atomic.AtomicBoolean;
 import javafx.application.Application;
 import javafx.application.Platform;
 import javafx.scene.Scene;
+import javafx.scene.control.Alert;
+import javafx.scene.control.Alert.AlertType;
 import javafx.scene.image.Image;
 import javafx.scene.layout.VBox;
 import javafx.scene.web.WebView;
@@ -25,61 +28,66 @@ import javafx.stage.Stage;
  * @author Loquicom <contact@loquicom.fr>
  */
 public class WebFx extends Application implements Runnable {
-    
+
     public static Stage stage;
-    
+    public static AtomicBoolean ini = new AtomicBoolean(false);
+    public static AtomicBoolean wait = new AtomicBoolean(false);
+
+    protected double zoom = 1;
     protected int width = 800;
     protected int height = 800;
     protected String title = "WFX";
     protected String html = "<div style=\"margin-top: 48vh\"><h1 style=\"font-family: Arial\"><div style=\"text-align: center\">Loading...</div></h1></div>";
     protected String icon = null;
-    
+
     public WebFx() {
         WebFxConfig config = WebFxConfig.getInstance();
         config.setUpWebFx(this);
     }
-    
+
     public WebFx(String configPath) {
         WebFxConfig config = WebFxConfig.getInstance(configPath);
         config.setUpWebFx(this);
     }
-    
+
     /* --- Getter/Setter --- */
-    
+    public void setZoom(double zoom) {
+        this.zoom = zoom;
+    }
+
     public void setSize(int width, int height) {
         this.width = width;
         this.height = height;
     }
-    
-    public void setTitle(String title){
+
+    public void setTitle(String title) {
         this.title = title;
     }
-    
-    public void setHtml(String html){
+
+    public void setHtml(String html) {
         this.html = html;
     }
-    
-    public void setHtmlFile(String htmlFile){
+
+    public void setHtmlFile(String htmlFile) {
         String content = this.fileGetContent(htmlFile);
-        if(content != null){
+        if (content != null) {
             this.html = content;
         }
     }
-    
-    public void setIcon(String path){
+
+    public void setIcon(String path) {
         this.icon = "file:" + path;
     }
-    
+
     /* --- Méthodes JavaFx --- */
-    
     public void launch() {
         Application.launch();
     }
-    
+
     public void end() {
         Platform.exit();
     }
-    
+
     @Override
     public void start(final Stage stage) {
         //Creation element graphiques
@@ -87,6 +95,7 @@ public class WebFx extends Application implements Runnable {
         VBox root = new VBox();
 
         //Modification taille
+        wv.setZoom(this.zoom);
         wv.setMinWidth(this.width);
         wv.setMinHeight(this.height);
         root.setMinWidth(this.width);
@@ -108,17 +117,16 @@ public class WebFx extends Application implements Runnable {
                 + "-fx-border-insets: 5;"
                 + "-fx-border-radius: 5;"
                 + "-fx-border-color: blue;");*/
-
         //Creation et ajout de la scene
         Scene scene = new Scene(root);
         WebFx.stage.setScene(scene);
-        
+
         //Parametrage stage
         WebFx.stage.setTitle(title);
-        if(this.icon != null){
+        if (this.icon != null) {
             WebFx.stage.getIcons().add(new Image(this.icon));
         }
-        
+
         //Handler
         WebFx.stage.setOnCloseRequest(event -> {
             BomberStudent.end();
@@ -129,10 +137,10 @@ public class WebFx extends Application implements Runnable {
 
         //Affiche la fenetre
         WebFx.stage.show();
+        ini.set(true);
     }
-    
+
     /* --- Méthodes modification fenetre --- */
-    
     public void loadHtml(String html) {
         Platform.runLater(new Runnable() {
             @Override
@@ -143,31 +151,44 @@ public class WebFx extends Application implements Runnable {
             }
         });
     }
-    
-    public boolean loadFile(String path){
+
+    public boolean loadFile(String path) {
         //Recup le contenu du fichier
         String fileContent = this.fileGetContent(path);
-        if(fileContent == null){
+        if (fileContent == null) {
             return false;
         }
         //Chargement de l'html
         this.loadHtml(fileContent);
         return true;
     }
+
+    public void alert(String title, String text) {
+        wait.set(true);
+        Platform.runLater(new Runnable() {
+            @Override
+            public void run() {
+                Alert alert = new Alert(AlertType.INFORMATION);
+                alert.setTitle(title);
+                alert.setHeaderText(null);
+                alert.setContentText(text);
+                alert.showAndWait();
+                WebFx.wait.set(false);
+            }
+        });
+    }
     
     /* --- Methode Runneable --- */
-    
     @Override
     public void run() {
         this.launch();
     }
-    
+
     /* --- Methodes privées --- */
-    
-    private String fileGetContent(String path){
+    private String fileGetContent(String path) {
         //Ouverture fichier
         File f = new File(path);
-        if(!( f.exists() && f.canRead() )){
+        if (!(f.exists() && f.canRead())) {
             return null;
         }
         //Lecture fichier
@@ -175,8 +196,8 @@ public class WebFx extends Application implements Runnable {
         try {
             String buf;
             BufferedReader br = new BufferedReader(new FileReader(f));
-            while((buf = br.readLine()) != null){
-               fileContent += buf;
+            while ((buf = br.readLine()) != null) {
+                fileContent += buf;
             }
             br.close();
         } catch (FileNotFoundException ex) {
@@ -188,5 +209,5 @@ public class WebFx extends Application implements Runnable {
         }
         return fileContent;
     }
-    
+
 }

+ 4 - 0
BSWFX/src/wfx/WebFxConfig.java

@@ -106,6 +106,10 @@ public class WebFxConfig {
         if (this.json.has("width") && this.json.has("height")) {
             wfx.setSize(this.json.getInt("width"), this.json.getInt("height"));
         }
+        //Zoom
+        if(this.json.has("zoom")){
+            wfx.setZoom(this.json.getDouble("zoom"));
+        }
     }
 
     /* --- Methodes privées --- */

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů