Example #1
0
  public void serverPlay() {
    server = new Server();
    if ((server.getClient() == null) || (server.getServerSocket() == null)) {
      System.out.println("Error during establishing connection!");
      return;
    }
    server.writeToOutputStream(game.getFieldSize());
    int answer;
    do {
      boolean okCoords = false;
      do {
        answer = humanInput();
        if (answer == 1) {
          continue;
        } else if (answer == 2) {
          server.closeSocket();
          server = null;
          return;
        }
        okCoords = controller.figurePlaced(coordI, coordJ); // server place X
      } while (!okCoords);
      server.writeToOutputStream(coordI);
      server.writeToOutputStream(coordJ);
      if (game.getWinner() != ' ') {
        break;
      }

      System.out.println("O goes to...");
      coordI = server.getToInputStream();
      coordJ = server.getToInputStream();
      if ((coordI != -1) && (coordJ != -1)) {
        controller.figurePlaced(coordI, coordJ); // client place O
      } else {
        System.out.println("Network connection error!");
        server.closeSocket();
        server = null;
        return;
      }
    } while (game.getWinner() == ' ');
    server.closeSocket();
  }
Example #2
0
 public void printLine(int i) {
   for (int j = 0; j < game.getFieldSize(); j++) {
     System.out.print("[" + game.getField()[i][j] + "] ");
   }
   System.out.println("");
 }
Example #3
0
 public void printField() {
   for (int i = 0; i < game.getFieldSize(); i++) {
     printLine(i);
   }
 }
Example #4
0
 private void pvcCompGoes() {
   System.out.println("Computer goes to...");
   game.makeComputerStep(coordI, coordJ, game.getFieldSize(), game.getInstanceField());
   controller.figurePlaced(game.getComputer().getCoordI(), game.getComputer().getCoordJ());
 }