示例#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();
  }
 public void run() {
   for (int i = 0; i < NCIRCLES; i++) {
     double r = rgen.nextDouble(MIN_RADIUS, MAX_RADIUS);
     double x = rgen.nextDouble(0, getWidth() - 2 * r);
     double y = rgen.nextDouble(0, getHeight() - 2 * r);
     GOval circle = new GOval(x, y, 2 * r, 2 * r);
     circle.setFilled(true);
     circle.setColor(rgen.nextColor());
     add(circle);
   }
 }
示例#3
0
 /*Defines and places the Rent state as a circle */
 private void placeRent(int x, int y, int width, int height, Color rentColor) {
   GOval shape = new GOval(x, y, width, height);
   shape.setFilled(true);
   shape.setColor(rentColor);
   add(shape);
 }