예제 #1
1
파일: Game.java 프로젝트: cpetosky/o2d-lib
  // --------------------------------actionConnect------------------------------
  private void actionConnect() {
    if (oParty == null) {
      JOptionPane.showMessageDialog(frame, "Make a party before trying to connect.");
      return;
    }

    String[] oResults = (String[]) DialogManager.show(DialogManager.CONNECT, frame);

    if (oResults[DialogManager.RETURN_IP].equals("cancel")) return;

    lblStatus3.setText("Connecting...");
    try {
      oConn.connect(
          oResults[DialogManager.RETURN_IP], Integer.parseInt(oResults[DialogManager.RETURN_PORT]));
    } catch (UnknownHostException e) {
      JOptionPane.showMessageDialog(
          frame,
          "The IP of the host cannot be determined.",
          "Unknown Host Exception",
          JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          frame, e.getMessage(), "Input/Output Exception", JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    }
    echo("Connected to opponent!");

    tConn = new Thread(oConn, "conn");
    tConn.start();
    tMain = new Thread(this, "main");
    tMain.start();
  }
예제 #2
1
파일: Game.java 프로젝트: cpetosky/o2d-lib
  // --------------------------------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);
    }
  }
예제 #3
1
파일: Game.java 프로젝트: cpetosky/o2d-lib
  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();
      }
    }
  }
예제 #4
0
파일: Game.java 프로젝트: cpetosky/o2d-lib
 public void makeAvatarOrder() {
   int nRand = (int) Math.floor((Math.random() + 1) + 0.5);
   String sOrder = "A,0|B,0|A,1|B,1|A,2|B,2|A,3|B,3|A,4|B,4";
   String sOrder2 = "B,0|A,0|B,1|A,1|B,2|A,2|B,3|A,3|B,4|A,4";
   if (nRand == 1) {
     makeAvatarOrder(sOrder);
     oConn.send("avatar order", sOrder2);
   } else {
     makeAvatarOrder(sOrder2);
     oConn.send("avatar order", sOrder);
   }
 }
예제 #5
0
파일: Game.java 프로젝트: cpetosky/o2d-lib
  // -------------------------------actionMove-------------------------------
  private void actionMove() {
    System.out.println("actionMove");
    oConn.send("move", listChar[iChar].getTileX() + ";" + listChar[iChar].getTileY());

    // TEMP
    stateEndTurn();
  }
예제 #6
0
파일: Game.java 프로젝트: cpetosky/o2d-lib
  // --------------------------------actionDisconnect---------------------------
  private void actionDisconnect() {

    try {
      oConn.disconnect();
      tConn.join(2000);
      tMain.join(2000);
    } catch (Exception e) {
    }
  }
 private void onOK() {
   try {
     Map<String, String> data = new HashMap<String, String>();
     data.put("login", loginField.getText());
     data.put("password", passwordField.getText());
     String errorMsg = SocketManager.doAction(Constants.LOGIN_ACTION, data);
     if (errorMsg.equals("0")) {
       MainView mainView = new MainView();
       mainView.setVisible(true);
       dispose();
     } else {
       JOptionPane.showMessageDialog(this, errorMsg, "Error!", JOptionPane.ERROR_MESSAGE);
     }
   } catch (IOException e) {
     JOptionPane.showMessageDialog(this, e.getMessage(), "Error!", JOptionPane.ERROR_MESSAGE);
   }
 }
예제 #8
0
파일: Game.java 프로젝트: cpetosky/o2d-lib
 public void tradeParties() {
   oConn.sendObject(oParty);
   oOpponentParty = (Party) oConn.readObject();
   //		oOpponentParty.resetImages();
   oMap.addOpponentParty();
 }
예제 #9
0
파일: Game.java 프로젝트: cpetosky/o2d-lib
 // -------------------------------actionPrePlay----------------------------
 private void actionPrePlay() {
   oMap.prepareForPlay();
   lblStatus3.setText("Waiting for opponent to deploy...");
   bDeployed = true;
   oConn.send("deployed", "");
 }