Exemple #1
0
  private static void recuperacionFallas() {
    File file = new File(serverName + ".swp");
    if (file.exists()) {
      try {
        System.out.println("Un fichero de salvaguarda es presente:");
        System.out.println("Quiere recuperar el antiguo juego(y/n)?");
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
          String s = in.readLine();
          if (s.equals("y")) {
            recuperationServer();
            InputStream ips = new FileInputStream(serverName + ".swp");
            InputStreamReader ipsr = new InputStreamReader(ips);
            BufferedReader br = new BufferedReader(ipsr);
            String info = br.readLine();
            reconstruction(info);
            game.setRecoveringServer(false);
            break;
          } else if (s.equals("n")) {
            serverInit();
            break;
          }
        }

      } catch (FileNotFoundException e) {
        System.out.println("Failed to wait");
      } catch (IOException e) {
        System.out.println("Failed to wait");
      }

    } else serverInit();
    saveStateServer();
  }
Exemple #2
0
  public static void main(String[] args) {
    // Establecimiento del game en el rmiserver
    if (args.length == 0) {
      System.out.println("Wrong number of argument");
      System.exit(1);
    }

    listAddr = new ListAddr();
    serverInfo = listAddr.getServer(args[args.length - 1]);
    serverName = args[args.length - 1];

    if (args.length == 2 && args[0].equals("wait")) {
      try {
        serverWaiting();
      } catch (Exception e) {
        System.out.println("Failed to wait");
      }
    } else {
      if (args.length == 2) numPlayer = Integer.parseInt(args[0]);
      serverInit();

      File file = new File(serverName + ".swp");
      if (file.exists()) {
        try {
          InputStream ips = new FileInputStream(serverName + ".swp");
          InputStreamReader ipsr = new InputStreamReader(ips);
          BufferedReader br = new BufferedReader(ipsr);
          String info = br.readLine();
          reconstruction(info);
        } catch (FileNotFoundException e) {
          System.out.println("Failed to wait");
        } catch (IOException e) {
          System.out.println("Failed to wait");
        }
      }
      saveStateServer();
      serverRunning();
    }
  }
Exemple #3
0
  public void moveGhosts() {
    saveStateServer(); // We save the configuration of the game
    try {
      int nbrPlayerInGame = game.getNbrPlayerInGame();
      int[] ghosty = game.getGhosty();
      int[] ghostx = game.getGhostx();
      if (ghostMove == 0) {
        short i;
        int pos;
        int count;
        int blocksize = game.getBlocksize();
        int nrofblocks = game.getNrofblocks();
        int nrofghosts = game.getNrofghosts();
        short[] screendata = game.getScreendata();

        for (i = 0; i < nrofghosts; i++) {
          if (ghostx[i] % blocksize == 0 && ghosty[i] % blocksize == 0) {
            pos = ghostx[i] / blocksize + nrofblocks * (int) (ghosty[i] / blocksize);

            count = 0;
            if ((screendata[pos] & 1) == 0 && ghostdx[i] != 1) {
              dx[count] = -1;
              dy[count] = 0;
              count++;
            }
            if ((screendata[pos] & 2) == 0 && ghostdy[i] != 1) {
              dx[count] = 0;
              dy[count] = -1;
              count++;
            }
            if ((screendata[pos] & 4) == 0 && ghostdx[i] != -1) {
              dx[count] = 1;
              dy[count] = 0;
              count++;
            }
            if ((screendata[pos] & 8) == 0 && ghostdy[i] != -1) {
              dx[count] = 0;
              dy[count] = 1;
              count++;
            }

            if (count == 0) {
              if ((screendata[pos] & 15) == 15) {
                ghostdx[i] = 0;
                ghostdy[i] = 0;
              } else {
                ghostdx[i] = -ghostdx[i];
                ghostdy[i] = -ghostdy[i];
              }
            } else {
              count = (int) (Math.random() * count);
              if (count > 3) count = 3;
              ghostdx[i] = dx[count];
              ghostdy[i] = dy[count];
            }
          }
          ghostx[i] = ghostx[i] + (ghostdx[i] * ghostspeed[i]);
          ghosty[i] = ghosty[i] + (ghostdy[i] * ghostspeed[i]);
        }
      }
      ghostMove = (ghostMove + 1) % nbrPlayerInGame;
      game.setGhostx(ghostx);
      game.setGhosty(ghosty);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }