예제 #1
0
  /** getReady: Initialize the game */
  private void getReady() {

    // Make up the bricks
    double brickPerWidth =
        (getWidth() - DIST_BRICK_WALL * 2 - DIST_BRICK_BRICK * (NUM_BRICK_ROW - 1)) / NUM_BRICK_ROW;
    double brickPerHeight = BRICK_HEIGHT;
    double x_start = DIST_BRICK_WALL;
    double y_start;
    for (int i = 1; i <= NUM_BRICK_ROW; i++) {
      for (int j = 1; j <= NUM_BRICK_COL; j++) {
        y_start = 50 + (j - 1) * (DIST_BRICK_BRICK + brickPerHeight);
        GRect tmpbrick = new GRect(brickPerWidth, brickPerHeight);
        tmpbrick.setFilled(true);
        add(tmpbrick, x_start, y_start);
      }
      x_start += DIST_BRICK_BRICK + brickPerWidth;
    }

    // Make up the board
    board = new GRect(BOARD_WIDTH, BOARD_HEIGHT);
    board.setFilled(true);
    add(board, (getWidth() - BOARD_WIDTH) / 2, (getHeight() - 30));

    // Place the ball
    ball = new GOval(BALL_RADIUS * 2, BALL_RADIUS * 2);
    ball.setFilled(true);
    ball.setColor(Color.RED);
    add(ball, (getWidth() - BALL_RADIUS * 2) / 2, (getHeight() - 30 - BALL_RADIUS * 2));

    // Set up random generator
    rgen = RandomGenerator.getInstance();

    // Add Listeners
    addMouseListeners();
  }
예제 #2
0
 private void buildHead() {
   double startingWidth = ((getWidth() / 2) - (head_width / 2));
   double startingHeight = ((getHeight() / 2) - (head_height / 2));
   GRect face = new GRect(startingWidth, startingHeight, head_width, head_height);
   add(face);
   face.setFilled(true);
   face.setFillColor(Color.GRAY);
 }
예제 #3
0
 private void drawPaddle() {
   double x = (WIDTH - PADDLE_WIDTH) / 2;
   double y = HEIGHT - BRICK_Y_OFFSET - PADDLE_HEIGHT;
   paddle = new GRect(x, y, PADDLE_WIDTH, PADDLE_HEIGHT);
   paddle.setFilled(true);
   add(paddle);
   addMouseListeners();
 }
예제 #4
0
 private void buildMouth() {
   double startingWidth = getWidth() / 2 - mouth_width / 2;
   double startingHeight = getHeight() / 2 + head_height / 4 - mouth_height / 2;
   GRect mouth = new GRect(startingWidth, startingHeight, mouth_width, mouth_height);
   add(mouth);
   mouth.setColor(Color.WHITE);
   mouth.setFilled(true);
   mouth.setFillColor(Color.WHITE);
 }
예제 #5
0
 private void drawOneBrick(int row, int col) {
   double x0 =
       (WIDTH - NBRICKS_PER_ROW * BRICK_WIDTH - (NBRICKS_PER_ROW - 1) * BRICK_SEP)
           / 2; // the distance of leftmost brick to left border of the world
   double x = x0 + (BRICK_WIDTH + BRICK_SEP) * col;
   double y = BRICK_Y_OFFSET + (BRICK_SEP + BRICK_HEIGHT) * row;
   GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
   brick.setFilled(true);
   colorBrick(row, brick);
   add(brick);
 }
예제 #6
0
 /** Places a rectangle at x,y with width, height and specified color */
 public void place(int x, int y, int width, int height, Color shapeColor) {
   GRect shape = new GRect(x, y, width, height);
   shape.setFilled(true);
   shape.setColor(shapeColor);
   add(shape);
 }