Example #1
0
  @Override
  protected void buildGraphics() {

    GRect leftLeg = new GRect(35, 200, 35, 150);
    leftLeg.setColor(strokeColor);
    leftLeg.setFilled(true);
    leftLeg.setFillColor(strokeColor);
    addLeg(new Leg(leftLeg, 2));

    GRect rightLeg = new GRect(75, 200, 35, 150);
    rightLeg.setColor(strokeColor);
    rightLeg.setFilled(true);
    rightLeg.setFillColor(strokeColor);
    addLeg(new Leg(rightLeg, 2));

    GImage LlcoolJ = null;
    try {
      LlcoolJ = new GImage(ImageIO.read(getClass().getResource("/LLCOOLJ.png")));
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    getGraphics().add(LlcoolJ);

    addEye(Eye.createStandardEye(95, 20, 10, 0.26, 0.18, Color.RED));
    addEye(Eye.createStandardEye(110, 30, 10, 0.26, 0.18, Color.RED));
  }
Example #2
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() {
    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);
  }
 /*this method create and draws white rectangle */
 public void drawRect() {
   GRect rect = new GRect(RADIUS, RADIUS, getWidth() - RADIUS * 2, getHeight() - RADIUS * 2);
   rect.setFilled(true);
   rect.setFillColor(Color.WHITE);
   rect.setColor(Color.WHITE);
   add(rect);
 }
 /*### Creates Rect ###*/
 private GRect createRect(int xLeft, int yTop, int xWidth, int yHeight, Color col) {
   GRect rect = new GRect(xLeft, yTop, xWidth, yHeight);
   rect.setColor(col);
   rect.setFillColor(col);
   rect.setFilled(true);
   return rect;
 }
 private GRect getMeFilledrect(double x, double y, double w, double h, Color c) {
   GRect rect = new GRect(x, y, w, h);
   rect.setFilled(true);
   rect.setFillColor(c);
   rect.setColor(c);
   return rect;
 }
Example #7
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);
 }
 /** 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;
 }
Example #9
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();
 }
 // Draw central white rectangle
 private void drawCentralRectangle() {
   int x = (getWidth() - RECTANGLE_WIDTH) / 2;
   int y = (getHeight() - RECTANGLE_HEIGHT) / 2;
   GRect rect = new GRect(x, y, RECTANGLE_WIDTH, RECTANGLE_HEIGHT);
   rect.setColor(Color.white);
   rect.setFilled(true);
   add(rect);
 }
 /* Draw one of the stripes flag
  * Incoming parameters: coordinates of the upper
  * left corner (in x and y), the length and width of the strip, and its color
  */
 private void paintSegmentFlag(
     double x1, double y1, double rectWidth, double rectHeight, Color col) {
   GRect rect = new GRect(x1, y1, rectWidth, rectHeight);
   rect.setFilled(true);
   rect.setColor(col);
   rect.setFillColor(col);
   add(rect);
 }
Example #12
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);
 }
Example #13
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);
 }
 private void drawCell(
     int col, int row, double boxSize, double boxSpacing, double marginLeft, double marginTop) {
   GRect r =
       new GRect(
           (boxSize + boxSpacing) * col + marginLeft,
           (boxSize + boxSpacing) * row + marginTop,
           boxSize,
           boxSize);
   r.setFilled(true);
   r.setFillColor(Color.BLACK);
   add(r);
 }
 private void drawRect(int col, int row, double marginLeft, double marginTop) {
   GRect Rect =
       new GRect(
           col * (BOX_SIZE + BOX_SPACING + 1) + marginLeft,
           row * (BOX_SIZE + BOX_SPACING + 1) + marginTop,
           BOX_SIZE,
           BOX_SIZE); /* '+ 1' - don't really know why
                      BOX_SPACING start his work from count 2, not from 1 */
   Rect.setColor(Color.BLACK);
   Rect.setFilled(true);
   //        Rect.setColor(Color.CYAN);
   add(Rect);
 }
Example #16
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);
 }
Example #17
0
 public Star(Color color, int radius) {
   GRect rect = new GRect(radius * 2, radius * 2);
   rect.setFillColor(color);
   rect.setFilled(true);
   add(rect);
 }
Example #18
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);
 }
 /**
  * Draws horizontal streak of flag
  *
  * @param x The x coordinate of the upper-left corner of the streak
  * @param y The y coordinate of the upper-left corner of the streak
  * @param width The width of streak
  * @param height The height of streak
  * @param color the color of streak
  */
 private void drawStreak(double x, double y, double width, double height, Color color) {
   GRect r = new GRect(x, y, width, height);
   r.setColor(color);
   r.setFilled(true);
   add(r);
 }
 /**
  * Draws the contour of the flag, because the white color melts into background (in other words -
  * "do beautiful")
  *
  * @param x The x coordinate of the upper-left corner of the flag
  * @param y The y coordinate of the upper-left corner of the flag
  * @param flagWidth The width of flag
  * @param flagHeight the color of flag
  */
 private void drawFrame(double x, double y, double flagWidth, double flagHeight) {
   GRect r = new GRect(x, y, flagWidth, flagHeight);
   r.setColor(Color.lightGray);
   r.setFilled(false);
   add(r);
 }
Example #21
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);
  }