コード例 #1
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);
   }
 }
コード例 #2
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();
 }