예제 #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
  public void run() {
    getWidth();
    getHeight();

    double x = getWidth() / 2;
    double y = getHeight() / 2;

    GRect a = new GRect(x - 1.5 * SIZE, y - 1.5 * SIZE, SIZE, 3 * SIZE);
    a.setColor(Color.RED);
    a.setFilled(true);
    add(a);

    GRect b = new GRect(x - SIZE / 2, y - 1.5 * SIZE, SIZE, 3 * SIZE);
    b.setColor(Color.YELLOW);
    b.setFilled(true);
    add(b);

    GRect c = new GRect(x + SIZE / 2, y - 1.5 * SIZE, SIZE, 3 * SIZE);
    c.setColor(TURQUOISE);
    c.setFilled(true);
    add(c);

    GLabel d = new GLabel("Flag of Peru", x + SIZE, y + 1.9 * SIZE);
    d.setColor(Color.BLACK);
    d.setFont("Broadway-12");
    add(d);
  }
 /** The method takes parameters and returns, square shape figure */
 private GRect rectangle(int x, int y, int width, int height, Color colorSetFill, Color colorSet) {
   GRect rectangle = new GRect(x, y, width, height);
   rectangle.setFilled(true);
   rectangle.setFillColor(colorSetFill);
   rectangle.setColor(colorSet);
   add(rectangle);
   return rectangle;
 }
예제 #4
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);
 }
예제 #5
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();
 }
예제 #6
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);
 }
예제 #7
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);
 }
예제 #8
0
 private void PaintRect(int xPosition, int yPosition) { // Paint square, white color
   GRect rect = new GRect((xPosition / 2), (yPosition / 2), 2 * xPosition, 2 * yPosition);
   rect.setFilled(true);
   rect.setColor(Color.WHITE);
   add(rect);
 }
예제 #9
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);
 }