Example #1
1
  public void run() {
    String[] sData;
    while (oConn.isConnected()) {
      sData = oConn.getData();
      System.out.println("Received \"" + sData[0] + "\" command.");

      if (sData[0].equals("chat")) panChat.addChat(sData[1]);
      else if (sData[0].equals("loadmap")) {
        try {
          oMap.loadMap(new File(DEFAULT_MAP_DIRECTORY + sData[1]));
          int nRand = (int) Math.floor((Math.random() + 1) + 0.5);
          stateDeploy(nRand);
          if (nRand == 1) nRand = 2;
          else nRand = 1;
          oConn.send("deploy", "" + nRand);
        } catch (FileNotFoundException e) {
          oConn.send("error", "Opponent does not have map.");
          actionDisconnect();
        }
      } else if (sData[0].equals("deploy")) {
        stateDeploy(Integer.parseInt(sData[1]));
      } else if (sData[0].equals("error")) {
        JOptionPane.showMessageDialog(frame, sData[1]);
        actionDisconnect();
      } else if (sData[0].equals("deployed")) {
        bOpponentDeployed = true;
        if (bDeployed) {
          oConn.send("trade parties", "");
          tradeParties();
          makeAvatarOrder();
          long nRandSeed = Math.round((Math.random() * Long.MAX_VALUE));
          oRandom = new Random(nRandSeed);
          oConn.send("random seed", "" + nRandSeed);
          oConn.send("phase", "1");
          phase1();
        }
      } else if (sData[0].equals("trade parties")) {
        tradeParties();
      } else if (sData[0].equals("avatar order")) {
        makeAvatarOrder(sData[1]);
      } else if (sData[0].equals("random seed")) {
        oRandom = new Random(Long.parseLong(sData[1]));
      } else if (sData[0].equals("phase")) {
        switch (Integer.parseInt(sData[1])) {
          case 1:
            phase1();
            break;
          case 2:
            phase2();
            break;
          case 3:
            phase3();
            break;
          case 4:
            iChar = 0;
            bMyAT = false;
            phase4();
            break;
        }
      } else if (sData[0].equals("move")) {
        oMap.moveATAvatar(Integer.parseInt(sData[1]), Integer.parseInt(sData[2]));
        // TEMP
        stateEndTurn();
      }
    }
  }