コード例 #1
0
ファイル: ShopGame.java プロジェクト: Wissamkahi/Shop-Game
 /*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
ファイル: PythagoreanTheorem.java プロジェクト: ravero/CS106A
  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);
  }
コード例 #3
0
ファイル: ShopGame.java プロジェクト: Wissamkahi/Shop-Game
 /*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;
 }
コード例 #4
0
ファイル: DrawRectangle.java プロジェクト: RCoon/CS106A
 /** 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);
   }
 }
コード例 #5
0
 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);
 }
コード例 #6
0
 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);
 }
コード例 #7
0
ファイル: Breakout_Extension.java プロジェクト: czptv/CS106A
 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;
 }