Пример #1
0
 /*Creates the equipment in all states to initiate the game */
 private void fillStates(int sAvail, int sRent, int sShop) {
   int[] statesSizes = {sAvail, sRent, sShop};
   int s = 1;
   for (int stateSize : statesSizes) {
     for (int t = 1; t <= TYPES; t++) {
       for (int i = 1; i <= stateSize; i++) {
         Equipment e = new Equipment();
         e.state = s;
         e.type = t;
         int sMax =
             Math.max(
                 s - 2, 0); /*formula to make sure identifiers resume counting and stay unique */
         int sMin =
             Math.min(
                 s - 1, 1); /*formula to make sure identifiers resume counting and stay unique */
         e.ident = i + (sMin) * sAvail + (sMax) * sRent;
         e.c = equipColor(e.type);
         switch (s) {
           case 1:
             availEquipment.add(e);
             break;
           case 2:
             rentEquipment.add(e);
             break;
           case 3:
             shopEquipment.add(e);
             break;
         }
       }
     }
     s++;
   }
   computeInitialTimes();
   assignShapes();
 }
Пример #2
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;
 }
Пример #3
0
 /** Called on mouse drag to reshape the current rectangle */
 public void mouseDragged(MouseEvent e) {
   if (gobj != null) {
     gobj.move(e.getX() - lastX, e.getY() - lastY);
     lastX = e.getX();
     lastY = e.getY();
   } else {
     double x = Math.min(e.getX(), startX);
     double y = Math.min(e.getY(), startY);
     double width = Math.abs(e.getX() - startX);
     double height = Math.abs(e.getY() - startY);
     currentRect.setBounds(x, y, width, height);
   }
 }
Пример #4
0
  public void run() {

    double n; // anzahl der ecken
    double s; // zwischenergebnis
    double r = 100; // radius
    int x; // 1. X-Koordinate
    double xd; // 1. X-Koordinate in double
    int y; // 1. Y-Koordinate
    double yd; // 1. Y-Koordinate in double
    double i;
    double s1; // Zwischenergebnis
    int x1; // 2. X-Koordinate
    double x1d; // 2. X-Koordinate in double
    int y1; // 2. Y-Koordinate
    double y1d; // 2. Y-Koordinate in double
    IODialog dialog = new IODialog();
    // n = readDouble ("Anzahl der Ecken:");
    n = dialog.readDouble("Anzahl der Ecken: ");
    for (i = 0; i < n; i++) {
      s = i * (2 * Math.PI) / n; // Berechnung des Winkels
      xd = r * Math.cos(s); // Berechnung der X-Koordinate
      yd = r * Math.sin(s); // Berechnug der Y-Koordinate
      x = (int) xd;
      x = x + 120; // X-Koordinate verschieben damit sichbar
      y = (int) yd;
      y = y + 120; // Y-Koordinate verschieben ddamit sichbar

      s1 = (i + 1) * (2 * Math.PI) / n;
      x1d = r * Math.cos(s1);
      y1d = r * Math.sin(s1);
      x1 = (int) x1d;
      x1 = x1 + 120;
      y1 = (int) y1d;
      y1 = y1 + 120;
      add(new GLine(x, y, x1, y1));
    }
  }
Пример #5
0
 private GObject checkCorner(double x, double y) {
   GObject obj = getElementAt(x, y); // check the corner for GObject
   if (obj == paddle) {
     vy = -Math.abs(vy);
     PrecisionPaddle();
   } else if (obj != null && obj != lifeCount) { // check if the ball hits a brick
     remove(obj);
     vy = -1.05 * vy;
     vx = 1.05 * vx;
     brickCount--;
     AudioClip bounceClip = MediaTools.loadAudioClip("bounce.au");
     bounceClip.play();
   }
   return obj;
 }