BomberStudent.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package bswfx;
  7. import bs.Create;
  8. import bswfx.handler.*;
  9. import bs.Game;
  10. import bs.Join;
  11. import bs.Menu;
  12. import org.json.JSONObject;
  13. import rsx.BomberStudentClient;
  14. import wfx.WebFx;
  15. /**
  16. *
  17. * @author Loquicom <contact@loquicom.fr>
  18. */
  19. public class BomberStudent {
  20. public static WebFx wfx = new WebFx();
  21. public static BomberStudentClient bsc = new BomberStudentClient();
  22. public static Game game;
  23. public static Menu menu;
  24. public static Create create;
  25. public static Join join;
  26. /**
  27. * @param args the command line arguments
  28. */
  29. public static void main(String[] args) {
  30. //Change passage de ligne du systeme
  31. System.setProperty("line.separator", "\n");
  32. //Variables
  33. JSONObject param;
  34. JSONObject res;
  35. //Lancement Thread affichage
  36. Thread twfx = new Thread(wfx);
  37. twfx.start();
  38. //Ajout handler
  39. bsc.addHandler("server/end", new HandlerServerEnd());
  40. bsc.addHandler("player/position/update", new HandlerPlayerMove());
  41. bsc.addHandler("game/newplayer", new HandlerPlayerJoin());
  42. bsc.addHandler("game/quit", new HandlerPlayerQuit());
  43. bsc.addHandler("attack/newbomb", new HandlerAttackBomb());
  44. bsc.addHandler("attack/explose", new HandlerAttackExplose());
  45. bsc.addHandler("attack/affect", new HandlerAttackAffect());
  46. bsc.addHandler("player/major/end", new HandlerMajorEnd());
  47. //Recherche serveur actif
  48. int nbRes = bsc.findServer();
  49. if (nbRes == 0) {
  50. wfx.alert("Erreur", "Aucun serveur trouvé");
  51. waitWfx();
  52. wfx.end();
  53. System.exit(0);
  54. }
  55. System.out.println("Nombre serveur : " + nbRes);
  56. //Connexion serveur et recup liste des games
  57. bsc.selectServer(0);
  58. //Verif affichage ok
  59. while(!WebFx.ini.get());
  60. //Affichage menu
  61. menu = new Menu();
  62. menu.show();
  63. }
  64. public static void updateWindow(){
  65. wfx.loadHtml(game.toHtml());
  66. }
  67. public static void end(){
  68. wfx.end();
  69. bsc.close();
  70. System.exit(0);
  71. }
  72. public static void waitWfx(){
  73. while(wfx.wait.get()){
  74. try{
  75. Thread.sleep(1000);
  76. } catch(Exception ex) {
  77. }
  78. }
  79. }
  80. }