Beispiel #1
1
  // -------------------------------actionOpenMap----------------------------
  private void actionOpenMap() {
    JFileChooser oFC = new JFileChooser(DEFAULT_MAP_DIRECTORY);
    int nReturn = oFC.showOpenDialog(frame);

    if (nReturn == JFileChooser.APPROVE_OPTION) {
      try {
        oMap.loadMap(oFC.getSelectedFile());
      } catch (Exception e) {
      }
    }
  }
Beispiel #2
1
  // --------------------------------actionHost---------------------------------
  private void actionHost() {
    if (oParty == null) {
      JOptionPane.showMessageDialog(frame, "Make a party before trying to connect.");
      return;
    }

    JFileChooser oFC = new JFileChooser(DEFAULT_MAP_DIRECTORY);
    int nReturn = oFC.showOpenDialog(frame);

    if (nReturn == JFileChooser.CANCEL_OPTION) {
      return;
    }

    int nPort = Integer.parseInt((String) (DialogManager.show(DialogManager.HOST, frame)));

    JDialog dlgBox = (JDialog) (DialogManager.show(DialogManager.WAITING_FOR_CONN, frame));
    dlgBox.pack();
    try {
      oConn.host(nPort);
    } catch (IOException e) {
      JOptionPane.showMessageDialog(frame, e.getMessage(), "Error!", JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    }
    dlgBox.setVisible(false);
    echo("Connected to opponent!");

    tConn = new Thread(oConn, "conn");
    tConn.start();
    tMain = new Thread(this, "main");
    tMain.start();

    try {
      oMap.loadMap(oFC.getSelectedFile());
      oConn.send("loadmap", oFC.getName(oFC.getSelectedFile()));
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(-1);
    }
  }
Beispiel #3
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();
      }
    }
  }