/**
   * Draws a pawprint. The parameters should specify the upper-left corner of the bounding box
   * containing that pawprint.
   *
   * @param x The x coordinate of the upper-left corner of the bounding box for the pawprint.
   * @param y The y coordinate of the upper-left corner of the bounding box for the pawprint.
   */
  private void drawPawprint(double x, double y) {
    // draw first toe
    double firstToeX = x + FIRST_TOE_OFFSET_X;
    double firstToeY = y + FIRST_TOE_OFFSET_Y;
    GOval firstToe = new GOval(firstToeX, firstToeY, TOE_WIDTH, TOE_HEIGHT);
    firstToe.setFilled(true);
    firstToe.setColor(Color.BLACK);
    add(firstToe);

    // draw second toe
    double secondToeX = x + SECOND_TOE_OFFSET_X;
    double secondToeY = y + SECOND_TOE_OFFSET_Y;
    GOval secondToe = new GOval(secondToeX, secondToeY, TOE_WIDTH, TOE_HEIGHT);
    secondToe.setFilled(true);
    secondToe.setColor(Color.BLACK);
    add(secondToe);

    // draw third toe
    double thirdToeX = x + THIRD_TOE_OFFSET_X;
    double thirdToeY = y + THIRD_TOE_OFFSET_Y;
    GOval thirdToe = new GOval(thirdToeX, thirdToeY, TOE_WIDTH, TOE_HEIGHT);
    thirdToe.setFilled(true);
    thirdToe.setColor(Color.BLACK);
    add(thirdToe);

    // draw heel
    double heelX = x + HEEL_OFFSET_X;
    double heelY = y + HEEL_OFFSET_Y;
    GOval heel = new GOval(heelX, heelY, HEEL_WIDTH, HEEL_HEIGHT);
    heel.setFilled(true);
    heel.setColor(Color.BLACK);
    add(heel);
  }
 public void run() {
   double outerCircleDiameter = 2 * OUTER_CIRCLE_RADIUS;
   double middleCircleDiameter = 2 * MIDDLE_CIRCLE_RADIUS;
   double innerCircleDiameter = 2 * INNER_CIRCLE_RADIUS;
   double xOuterCircle = (getWidth() - outerCircleDiameter) / 2;
   double xMiddleCircle = (getWidth() - middleCircleDiameter) / 2;
   double xInnerCircle = (getWidth() - innerCircleDiameter) / 2;
   double yOuterCircle = (getHeight() - outerCircleDiameter) / 2;
   double yMiddleCircle = (getHeight() - middleCircleDiameter) / 2;
   double yInnerCircle = (getHeight() - innerCircleDiameter) / 2;
   GOval outCircle =
       new GOval(xOuterCircle, yOuterCircle, outerCircleDiameter, outerCircleDiameter);
   GOval middleCircle =
       new GOval(xMiddleCircle, yMiddleCircle, middleCircleDiameter, middleCircleDiameter);
   GOval centreCircle =
       new GOval(xInnerCircle, yInnerCircle, innerCircleDiameter, innerCircleDiameter);
   outCircle.setColor(Color.RED);
   middleCircle.setColor(Color.WHITE);
   centreCircle.setColor(Color.RED);
   outCircle.setFilled(true);
   middleCircle.setFilled(true);
   centreCircle.setFilled(true);
   outCircle.setFillColor(Color.RED);
   middleCircle.setFillColor(Color.WHITE);
   centreCircle.setFillColor(Color.RED);
   add(outCircle);
   add(middleCircle);
   add(centreCircle);
 }
Ejemplo n.º 3
0
 private void PaintOval(
     int x, int y, int Width, int Height) { // Paint four round in corners? black color
   GOval OvalPaint = new GOval(x, y, Width, Height);
   OvalPaint.setFilled(true);
   OvalPaint.setColor(Color.BLACK);
   add(OvalPaint);
 }
 /*### Creates Oval ###*/
 private GOval createOval(int gWidth, int gHeight, int x, int y, int locX, int locY, Color col) {
   GOval Oval = new GOval(gWidth, gHeight, x, y);
   Oval.setLocation(locX, locY);
   Oval.setColor(col);
   Oval.setFilled(true);
   return Oval;
 }
Ejemplo n.º 5
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();
  }
Ejemplo n.º 6
0
 private void buildEye(double x, double y) {
   GOval Eye = new GOval(x, y, eye_radius * 2, eye_radius * 2);
   Eye.setColor(Color.YELLOW);
   Eye.setFilled(true);
   Eye.setFillColor(Color.YELLOW);
   add(Eye);
 }
 /** The method takes parameters and returns, oval shape figure */
 private GOval oval(int x, int y, int width, int height, Color colorSetFill, Color colorSet) {
   GOval oval = new GOval(x, y, width, height);
   oval.setFilled(true);
   oval.setFillColor(colorSetFill);
   oval.setColor(colorSet);
   add(oval);
   return oval;
 }
Ejemplo n.º 8
0
 private void drawBall() {
   double x = WIDTH / 2 - BALL_RADIUS;
   double y = HEIGHT / 2 - BALL_RADIUS;
   double d = 2 * BALL_RADIUS;
   ball = new GOval(x, y, d, d);
   ball.setFilled(true);
   add(ball);
 }
Ejemplo n.º 9
0
 public void drawInnerOval() {
   double x = getWidth() / 2.0 - INNER_CIRCLE_WIDTH / 2.0;
   double y = getHeight() / 2.0 - INNER_CIRCLE_WIDTH / 2.0;
   GOval oval = new GOval(x, y, INNER_CIRCLE_WIDTH, INNER_CIRCLE_WIDTH);
   add(oval);
   oval.setFilled(true);
   oval.setFillColor(Color.RED);
   oval.setColor(Color.WHITE);
 }
Ejemplo n.º 10
0
  public void drawWhiteOval() {

    double x = getWidth() / 2.0 - WHITE_CIRCLE_WIDTH / 2.0;
    double y = getHeight() / 2.0 - WHITE_CIRCLE_WIDTH / 2.0;
    GOval oval = new GOval(x, y, WHITE_CIRCLE_WIDTH, WHITE_CIRCLE_WIDTH);
    add(oval);
    oval.setFilled(true);
    oval.setFillColor(Color.WHITE);
    oval.setColor(Color.WHITE);
  }
Ejemplo n.º 11
0
 private GOval createFilledCircle(double x, double y, double r, int i) {
   GOval circle = new GOval(x - r, y - r, 2 * r, 2 * r);
   if (i % 2 != 0) {
     circle.setColor(Color.RED);
   } else {
     circle.setColor(Color.WHITE);
   }
   circle.setFilled(true);
   return circle;
 }
 public void run() {
   GOval o = new GOval(40, 40);
   o.setColor(Color.RED);
   o.setFilled(true);
   add(o, 100, 100);
   while (true) {
     pause(WAIT);
     o.move(xMove, yMove);
   }
 }
 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);
   }
 }
 private void drawOval(int x, int y, int size) {
   // create circle and set whether it will be red or white
   GOval circle = new GOval(x, y, size, size);
   if ((size % 2) == 0) { // if the size of the circle divides evenly (remainder of zero)
     // color the circle RED
     circle.setFillColor(Color.RED);
   } else {
     // color the circle white
     circle.setFillColor(Color.WHITE);
   }
   circle.setFilled(true); // add color
   add(circle); // create circle
 }
 /*this method draws four circles*/
 public void drawCircles() {
   // row
   for (int k = 0; k <= 1; k++) {
     // column
     for (int i = 0; i <= 1; i++) {
       GOval oval =
           new GOval(
               i * (getWidth() - RADIUS * 2),
               k * (getHeight() - RADIUS * 2),
               RADIUS * 2,
               RADIUS * 2);
       oval.setFilled(true);
       oval.setFillColor(Color.black);
       add(oval);
     }
   }
 }
 // Draw oval
 private void drawOval(int x, int y) {
   GOval oval = new GOval(x, y, DIAMETER, DIAMETER);
   oval.setColor(Color.black);
   oval.setFilled(true);
   add(oval);
 }
Ejemplo n.º 17
0
 // Create and place ball
 private void setup() {
   ball = new GOval(X_START, Y_START, DIAM_BALL, DIAM_BALL);
   ball.setFilled(true);
   add(ball);
 }
 /* Draw graph line with the name and rating */
 private void drawEntry(NameSurferEntry entry, int entryNumber) {
   /* Draws graph line */
   for (int i = 0; i < NDECADES - 1; i++) {
     int position1 = entry.getRank(i);
     int position2 = entry.getRank(i + 1);
     double x1 = i * (getWidth() / NDECADES);
     double x2 = (i + 1) * (getWidth() / NDECADES);
     double y1 = 0;
     double y2 = 0;
     if (position1 != 0 && position2 != 0) {
       y1 = GRAPH_MARGIN_SIZE + (getHeight() - GRAPH_MARGIN_SIZE * 2) * position1 / MAX_RANK;
       y2 = GRAPH_MARGIN_SIZE + (getHeight() - GRAPH_MARGIN_SIZE * 2) * position2 / MAX_RANK;
     } else if (position1 == 0 && position2 == 0) {
       y1 = getHeight() - GRAPH_MARGIN_SIZE;
       y2 = y1;
     } else if (position1 == 0) {
       y1 = getHeight() - GRAPH_MARGIN_SIZE;
       y2 = GRAPH_MARGIN_SIZE + (getHeight() - GRAPH_MARGIN_SIZE * 2) * position2 / MAX_RANK;
     } else {
       y1 = GRAPH_MARGIN_SIZE + (getHeight() - GRAPH_MARGIN_SIZE * 2) * position1 / MAX_RANK;
       y2 = getHeight() - GRAPH_MARGIN_SIZE;
     }
     GLine line = new GLine(x1, y1, x2, y2);
     /* Set line color */
     if (entryNumber % 4 == 0) {
       line.setColor(Color.BLUE);
     } else if (entryNumber % 4 == 1) {
       line.setColor(Color.RED);
     } else if (entryNumber % 4 == 2) {
       line.setColor(Color.MAGENTA);
     } else if (entryNumber % 4 == 3) {
       line.setColor(Color.BLACK);
     }
     add(line);
   }
   /* Add label with the name and ranking */
   for (int i = 0; i < NDECADES; i++) {
     String name = entry.getName();
     int position = entry.getRank(i);
     String positionString = Integer.toString(position);
     String label = name + " " + positionString;
     double x = i * (getWidth() / NDECADES) + 10;
     double x1 = x - NDECADES;
     double y;
     int R = 5;
     if (position != 0) {
       y = GRAPH_MARGIN_SIZE + (getHeight() - GRAPH_MARGIN_SIZE * 2) * position / MAX_RANK;
     } else {
       /* Add "*" if name was not used and remove marker point */
       label = name + " *";
       y = getHeight() - GRAPH_MARGIN_SIZE - 10;
       R = 0;
     }
     /* Add marker point */
     GOval marker = new GOval(x1, y - 2, R, R); /* Got "y-2" by scientific research =) */
     marker.setFilled(true);
     GLabel nameLabel = new GLabel(label, x, y);
     nameLabel.setFont(new Font("Times Roman", Font.BOLD, 12));
     /* Set label color */
     if (entryNumber % 4 == 0) {
       nameLabel.setColor(Color.BLUE);
       marker.setColor(Color.BLUE);
     } else if (entryNumber % 4 == 1) {
       nameLabel.setColor(Color.RED);
       marker.setColor(Color.RED);
     } else if (entryNumber % 4 == 2) {
       nameLabel.setColor(Color.MAGENTA);
       marker.setColor(Color.MAGENTA);
     } else if (entryNumber % 4 == 3) {
       nameLabel.setColor(Color.BLACK);
       marker.setColor(Color.BLACK);
     }
     add(nameLabel);
     add(marker);
   }
 }
Ejemplo n.º 19
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);
 }
Ejemplo n.º 20
0
  public void run() {
    addKeyListeners();

    File boardFile = new File("largerboard.txt");
    try {
      Scanner sc = new Scanner(boardFile);
      int rowNum = 0;
      while (sc.hasNextLine()) {
        String s = sc.nextLine();
        char[] nums = s.toCharArray();
        for (int i = 0; i < nums.length; i++) {
          char2D[i][rowNum] = nums[i];
          System.out.print(char2D[i][rowNum] + " ");
        }
        System.out.println();
        rowNum++;
      }
    } catch (IOException e) {
      System.out.println("File not found.");
    }

    GRect box;
    GOval o;
    for (int i = 0; i < height; i++) {
      for (int j = 0; j < width; j++) {
        // int rand = (int) (3*Math.random());
        // twoD[j][i] = rand;
        // System.out.print(twoD[j][i] + " ");

        box = new GRect(boxSize * j, boxSize * i, boxSize, boxSize);
        add(box);

        if (char2D[j][i] == '0') {
          box.setFilled(true);
          box.setColor(Color.BLACK);
          o = new GOval(boxSize * j + 10, boxSize * i + 10, 5, 5);
          o.setFilled(true);
          o.setColor(Color.YELLOW);
          add(o);
          food.add(o);
        } else if (char2D[j][i] == '1') {
          box.setFilled(true);
          box.setColor(Color.BLUE);
        }
      }
      // System.out.println();
    }
    // end of nested for loops
    player = new GOval(playerX + 5, playerY + 5, 15, 15);
    player.setFilled(true);
    player.setColor(Color.RED);
    add(player);

    addGhosts();

    while (true) {

      // ghost movement
      // 0: up, 1: down, 2: right, 3: left
      for (int i = 0; i < ghostList.size(); i++) {
        ghost = (Ghost) ghostList.get(i);
        if (timer % 500 == 0) {
          if (playerX < ghost.getGhostX()) {
            ghost.move(3);
          } else if (playerY > ghost.getGhostY()) {
            ghost.move(1);
          } else if (playerX > ghost.getGhostX()) {
            ghost.move(2);
          } else if (playerY < ghost.getGhostY()) {
            ghost.move(0);
          }
          //				int rand =(int) (4*Math.random()); // between 0-3
          //				if(rand == 2 && isCollidable(ghost.getGhostX()+1, ghost.getGhostY())){
          //					ghost.move(rand);
          //				}
          //				else if(rand == 3 && isCollidable(ghost.getGhostX()-1, ghost.getGhostY())){
          //					ghost.move(rand);
          //				}
          //				else if(rand == 1 && isCollidable(ghost.getGhostX(), ghost.getGhostY()+1)){
          //					ghost.move(rand);
          //				}
          //				else if(rand == 0 && isCollidable(ghost.getGhostX(), ghost.getGhostY()-1)){
          //					ghost.move(rand);
          //				}
          // System.out.println(ghost.getGhostX() +" , "+ ghost.getGhostY() );
        }
      }

      if (collision(ghost, player)) {
        remove(player);
        hasLost = true;
        break;
      }

      if (food.size() == 0) {
        break;
      }

      for (int i = 0; i < food.size(); i++) {
        GOval foodPiece = (GOval) food.get(i);
        if (collision(player, foodPiece)) {
          remove(foodPiece);
          food.remove(i);
        }
      }

      pause(10);
      timer = timer + 10;
    }

    GLabel wonLost;

    if (hasLost) {
      wonLost = new GLabel("YOU LOSE", 220, 250);
    } else {
      wonLost = new GLabel("YOU WON AND ARE AWESOME", 220, 250);
    }

    wonLost.setColor(Color.WHITE);
    add(wonLost);
  }