Beispiel #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();
 }
Beispiel #2
0
  public void run() {
    println("Enter values to compute Pythagorean theorem.");

    int a = readInt("a: ");
    int b = readInt("b: ");

    double c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
    println("c = " + c);
  }
Beispiel #3
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;
 }
Beispiel #4
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);
   }
 }
 public void run() {
   /* You fill this in */
   println("Enter values to compute the Pythagorean theorem.");
   double a = readDouble("a: ");
   double b = readDouble("b: ");
   double c = Math.sqrt(a * a + b * b);
   println("c = " + c);
 }
 public void run() {
   int a, b;
   double c;
   println("Enter values to compute Pythagorean theorem.");
   a = readInt("a: ");
   b = readInt("b: ");
   c = Math.sqrt(a * a + b * b);
   println("c = " + c);
 }
Beispiel #7
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;
 }