Exemplo n.º 1
0
  public void LevelInit() {
    try {
      for (int i = 0; i < game.getNrofblocks() * game.getNrofblocks(); i++)
        game.setScreendata(leveldata[i], i);
      LevelContinue();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
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();
    }
  }