Beispiel #1
0
  @Override
  public synchronized void receiveData(
      String networkInput, String fromIp, String fromName, int port) {
    super.receiveData(networkInput, fromIp, fromName, port);

    if (networkInput.startsWith(GAME_UPDATE_TOKEN) && gameLoader != null) {

      GameState state = new GameState(networkInput.substring(2));

      for (Player player : playerList) {
        if (player.getName().equals(fromName)) {
          gameLoader.gameStateRecieved(state, player);
        }
      }

    } else if (networkInput.startsWith("LEFT: ")) {

      Iterator<Player> it = playerList.iterator();
      boolean found = false;

      while (it.hasNext() && !found) {
        Player player = it.next();
        if (player.getName().equals(fromName)) {
          found = true;

          gameLoader.playerLeft(player);
          it.remove();
        }
      }
    }
  }
Beispiel #2
0
  public GameHubModel(
      JFrame window,
      GatheringLoungeModel gatheringLoungeModel,
      User currentUser,
      String gameFileName,
      int gamePlayers,
      ArrayList<Player> playerList) {
    super(window, currentUser);

    ((LoungeWindowAdapter) window.getWindowListeners()[0]).setAbstractLoungeModel(this);

    this.window = window;
    this.gamePlayers = gamePlayers;

    gameLoader = null;

    this.gatheringLoungeModel = gatheringLoungeModel;

    this.playerList = playerList;
    playerList.add((Player) getCurrentUser());
    Collections.sort(playerList, new CompareByTeam());

    chatTabbedPanel = Chat.getSingleton();
    Chat.getSingleton().addChat(GameHubModel.GAMEHUB_NAME);
    Chat.getSingleton()
        .addChat(GameHubModel.GAMEHUB_NAME + ": Team " + getCurrentUser().getTeamId());

    for (Player player : playerList) {
      Chat.getSingleton().getChatTabbedModel().addChatter(GameHubModel.GAMEHUB_NAME, player);

      if (player.getTeamId() == getCurrentUser().getTeamId()) {
        Chat.getSingleton()
            .getChatTabbedModel()
            .addChatter(
                GameHubModel.GAMEHUB_NAME + ": Team " + getCurrentUser().getTeamId(), player);
      }
    }

    BoardGameReader boardGameReader = new BoardGameReader();
    File game = boardGameReader.getBoardGame(gameFileName);

    gameLoader = new GameLoader(this);
    gameLoader.loadBoardGame(game);
    try {
      gameLoader.startGame();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    gameGui = gameLoader.getGui();

    NetworkAdapter.getSingleton().setNetworkListener(this);
  }
Beispiel #3
0
 public void sendMessage(Object object, Player player) {
   NetworkAdapter.getSingleton()
       .sendSerializableObject(object, player.getIp().getHostAddress(), player.getName());
 }