// -------------------------------------------------------------------------------------------------------------------------------------------------------
 // Decorations
 public void newDecos() {
   int prob = (int) (Math.random() * 100); // randomly spawnst he decoration
   if (prob == 1) {
     if (decoList.size() < 1) {
       int prob2 = (int) (Math.random() * 2);
       if (prob2 == 1) { // right side or left side
         decoList.add(new Decorations(-700, (int) (backy * 0.1) % 23080, false));
       } else {
         decoList.add(new Decorations(-700, (int) (backy * 0.1) % 23080, true));
       }
     }
   }
   Boolean check = true;
   for (Decorations i : decoList) {
     if (i.getYTop() >= 2000) {
       check = false;
       break;
     }
   }
   if (check == false
       && decoList.size()
           > 0) { // theres only on in the lsit but for consitency we kept it as a list
     decoList.remove(0);
   }
 }
Example #2
0
 public void update(double prob_slowdown, double prob_create) {
   int i = 0;
   while (i < LENGTH && speed[i] == -1) i++;
   while (i < LENGTH) {
     if (Math.random() <= prob_slowdown && speed[i] > 0) speed[i]--;
     else if (speed[i] < MAXSPEED) speed[i]++;
     int inext = i + 1;
     while (inext < LENGTH && speed[inext] == -1) inext++;
     if (inext < LENGTH) {
       if (speed[i] >= inext - i) speed[i] = inext - i - 1;
     }
     if (speed[i] > 0) {
       if (i + speed[i] < LENGTH) {
         int ni = i + speed[i];
         speed[ni] = speed[i];
         colors[ni] = colors[i];
       }
       speed[i] = -1;
     }
     i = inext;
   }
   if (Math.random() <= prob_create && speed[0] == -1) {
     speed[0] = (int) (5.99 * Math.random());
     colors[0] = ++count % 10 == 0 ? Color.red : Color.black;
   }
 }
Example #3
0
  private void DoAI(int pnum) {
    int[] dx = {0, 1, 0, -1};
    int[] dy = {-1, 0, 1, 0};
    int tdir;

    if (palive[pnum] != 1) return;
    if (map[(px[pnum] + dx[pdir[pnum]]) + (py[pnum] + dy[pdir[pnum]]) * SIZE_X] != 0) {
      if (Math.random() > 0.5) {
        tdir = (pdir[pnum] + 1) % 4;
        if (map[(px[pnum] + dx[tdir]) + (py[pnum] + dy[tdir]) * SIZE_X] == 0) pdir[pnum] = tdir;
        else pdir[pnum] = (pdir[pnum] + 3) % 4;
      } else {
        tdir = (pdir[pnum] + 3) % 4;
        if (map[(px[pnum] + dx[tdir]) + (py[pnum] + dy[tdir]) * SIZE_X] == 0) pdir[pnum] = tdir;
        else pdir[pnum] = (pdir[pnum] + 1) % 4;
      }
    } else if (Math.random() > 0.985) {
      if (Math.random() > 0.5) {
        tdir = (pdir[pnum] + 1) % 4;
        if (map[(px[pnum] + dx[tdir]) + (py[pnum] + dy[tdir]) * SIZE_X] == 0) pdir[pnum] = tdir;
      } else {
        tdir = (pdir[pnum] + 3) % 4;
        if (map[(px[pnum] + dx[tdir]) + (py[pnum] + dy[tdir]) * SIZE_X] == 0) pdir[pnum] = tdir;
      }
    }
  }
Example #4
0
  public void makeField() {
    int vector[] = new int[rows * cols];
    int temp = 0;
    int limit, m, n;
    field = new int[rows][cols];
    for (m = 0; m < rows; m++)
      for (n = 0; n < cols; n++)
        vector[(n * rows) + m] = field[m][n] = (int) (Math.random() * 10000);
    Sort(vector, 0, vector.length - 1);
    limit = vector[nummines - 1];
    for (m = 0; m < rows; m++)
      for (n = 0; n < cols; n++) {
        field[m][n] = (field[m][n] <= limit ? (-1) : (0));
        if (field[m][n] == -1) {
          minerowlist[temp] = m;
          minecollist[temp++] = n;
        }
      }

    for (m = 0; m < rows; m++)
      for (n = 0; n < cols; n++)
        if (field[m][n] == 0) {
          int v = countmines(m, n);
          field[m][n] = v;
        }
    // printField();
  }
 // -------------------------------------------------------------------------------------------------------------------------------------------------------
 // Patterns
 public void newPattern() {
   int prob = (int) (Math.random() * probs.get(level - 1) + 1);
   Pattern p = new Pattern(0, -300, prob, (int) (backy * 0.1));
   if (checkSpawn(new Rectangle(p.getX(), p.getY(), p.getWidth(), p.getHeight())) == true) {
     for (Coin i : p.getCoins()) {
       coinList.add(i);
     }
     for (Star i : p.getStars()) {
       starList.add(i);
     }
     for (Box i : p.getBoxes()) {
       boxList.add(i);
     }
     for (Jumper i : p.getJumpers()) {
       jumperList.add(i);
     }
     for (Enemy i : p.getEnemies()) {
       enemyList.add(i);
     }
     for (Spikes i : p.getSpikes()) {
       spikeList.add(i);
     }
     for (Powerup i : p.getPowerUps()) {
       pupList.add(i);
     }
     for (Rectangle i : p.getRects()) {
       rectList.add(i);
     }
   }
 }
 public void bulletCreator(
     int x, int y, double mouseX, double mouseY, ArrayList<ZBullet> bullets) {
   bullet = bullets;
   for (int i = 0; i < 150; i++) {
     double r = (Math.random());
     if (r < .33333) c = new Color(170, 64, 151);
     else if (r < .66666) c = new Color(186, 97, 191);
     else c = new Color(144, 86, 135);
     double bobX = x - mouseX;
     double bobY = y - mouseY;
     int sinX = (int) (Math.random() * 15 - 8);
     int sinY = (int) (Math.random() * 15 - 8);
     ZBullet bull = new ZBullet(sinX, sinY, (int) mouseX, (int) mouseY, 30, 10, c, this, 0, 0);
     bullet.add(bull);
   }
   ammo--;
 }
  /**
   * The user has clicked in the applet. Figure out where and see if a legal move is possible. If it
   * is a legal move, respond with a legal move (if possible).
   */
  public void mouseReleased(MouseEvent e) {
    int x = e.getX();
    int y = e.getY();

    switch (status()) {
      case WIN:
      case LOSE:
      case STALEMATE:
        play(getCodeBase(), "audio/return.au");
        white = black = 0;
        if (first) {
          white |= 1 << (int) (Math.random() * 9);
        }
        first = !first;
        repaint();
        return;
    }

    // Figure out the row/column
    Dimension d = getSize();
    int c = (x * 3) / d.width;
    int r = (y * 3) / d.height;
    if (yourMove(c + r * 3)) {
      repaint();

      switch (status()) {
        case WIN:
          play(getCodeBase(), "audio/yahoo1.au");
          break;
        case LOSE:
          play(getCodeBase(), "audio/yahoo2.au");
          break;
        case STALEMATE:
          break;
        default:
          if (myMove()) {
            repaint();
            switch (status()) {
              case WIN:
                play(getCodeBase(), "audio/yahoo1.au");
                break;
              case LOSE:
                play(getCodeBase(), "audio/yahoo2.au");
                break;
              case STALEMATE:
                break;
              default:
                play(getCodeBase(), "audio/ding.au");
            }
          } else {
            play(getCodeBase(), "audio/beep.au");
          }
      }
    } else {
      play(getCodeBase(), "audio/beep.au");
    }
  }
Example #8
0
 /*Generates a random exponential distribution random time difference vs. timeIn based on the frequency lambda */
 private double nextRandomTime(double lambda) {
   double timeLag = 0;
   /*System.out.println("I am computing nextRandomTime");
   System.out.println("When I am getting timeIn of " +timeIn+" and lambda of "+lambda);*/
   double random = Math.random();
   timeLag = -Math.log(random) / (lambda / (LENGTHOFADAY * 1000));
   /*System.out.println("I am returning a time difference of "+timeLag);*/
   return timeLag;
 }
  void sendContacts() {
    try {
      int n = (int) (7 * Math.random());
      if (n < 1) n = 2;

      String[] nicks = new String[n];
      String[] loginIds = new String[n];

      int i = 0;
      while (i < n) {
        nicks[i] = "random uin #" + i;
        loginIds[i] = "" + (22222 + (int) (10000000 * Math.random()));
        i++;
      }
      plugin.sendContacts(getMyLoginId(), contactListEntry.getText(), nicks, loginIds);
    } catch (Exception ex) {
      printException(ex);
    }
  }
Example #10
0
 /**
  * create a random surface
  *
  * @param obj
  * @param x1:surface x begin
  * @param x2:surface x end
  * @param y1:surface y begin
  * @param y2:surface y end
  * @return: the surface mObject
  */
 private mObject createRandomSurface(mObject obj, int x1, int x2, int y1, int y2) {
   int i = 0, j = 0;
   x1 /= 20;
   x2 /= 20;
   y1 /= 20;
   y2 /= 20;
   mPoint3[][] points = new mPoint3[x2 - x1 + 1][y2 - y1 + 1];
   for (i = y1; i <= y2; i++) {
     for (j = x1; j <= x2; j++) {
       points[j - x1][i - y1] =
           new mPoint3(j * 20, i * 20, (float) (Math.random() * 70 * Math.exp(0 - 0.3 * j)));
     }
   }
   return new mSurface(points, x2 - x1 + 1, y2 - y1 + 1);
 }
Example #11
0
 double my_rand(double min, double max) {
   double r = Math.random();
   // r=r%1000;
   return r * (max - min) + min;
 };