コード例 #1
0
ファイル: L_shape.java プロジェクト: ashley3/Tetris
 public void rotate() {
   if (rotation == 0) {
     if (super.blocks[0].canMove(1, -1)
         && super.blocks[2].canMove(-1, 1)
         && super.blocks[3].canMove(0, -2)) {
       super.blocks[0].move(1, -1);
       super.blocks[2].move(-1, 1);
       super.blocks[3].move(0, -2);
     }
     rotation++;
   } else if (rotation == 1) {
     if (super.blocks[0].canMove(1, 1)
         && super.blocks[2].canMove(-1, -1)
         && super.blocks[3].canMove(2, 0)) {
       super.blocks[0].move(1, 1);
       super.blocks[2].move(-1, -1);
       super.blocks[3].move(2, 0);
     }
     rotation++;
   } else if (rotation == 2) {
     if (super.blocks[0].canMove(-1, 1)
         && super.blocks[2].canMove(1, -1)
         && super.blocks[3].canMove(0, 2)) {
       super.blocks[0].move(-1, 1);
       super.blocks[2].move(1, -1);
       super.blocks[3].move(0, 2);
     }
     rotation++;
   } else if (rotation == 3) {
     if (super.blocks[0].canMove(-1, -1)
         && super.blocks[2].canMove(1, 1)
         && super.blocks[3].canMove(-2, 0)) {
       super.blocks[0].move(-1, -1);
       super.blocks[2].move(1, 1);
       super.blocks[3].move(-2, 0);
     }
     rotation = 0;
   }
 }
コード例 #2
0
ファイル: Shape.java プロジェクト: ezfe/Dartmouth-COSC10
 /**
  * Move the Shape to be a given center.
  *
  * @param newCenter the new center of the shape
  */
 public void setCenter(Point newCenter) {
   Point oldCenter = getCenter();
   move(newCenter.x - oldCenter.x, newCenter.y - oldCenter.y);
 }
 /**
  * Add one shape and move it by the vector (dx, dy)
  *
  * @param shape Shape to be added
  * @param dx Distance to move shape in x
  * @param dy Distance to move shape in y
  */
 public void addShape(Shape shape, double dx, double dy) {
   addShape(shape);
   shape.move(dx, dy);
 }