Beispiel #1
0
/**
 * Initializes window with a grid of bricks.
 */
void initBricks(GWindow window)
{
  int xStart = 0;       // x coord  of brick
  int yStart = 0;       // y coord of brick
  int xSpacing = 2;     // spacing between bricks on horizontal
  int ySpacing = 2;     // spacing between bricks on vertical
  
  // Define dimensions of brick
  int brickWidth = WIDTH / (COLS) - xSpacing; 
  int brickHeight = 10;
  
  // Define different color for each row #rrggbb
  string color = "#" + itoa(rand()%1000000);
  
  // Build the matrix of bricks 
  for(int r = 0; r < ROWS; r++) {
    for(int c = 0; c < COLS; c++) {
      GRect brick = newGRect(xStart, yStart, brickWidth, brickHeight);
      setFilled(brick, true);
      setColor(brick, color);
      add(window, brick);
      xStart += (brickWidth + xSpacing);
    }
    yStart += (brickHeight + ySpacing);
    xStart = 0;
    color = "#" + itoa(rand()%1000000);
  }
}
Beispiel #2
0
/**
 * Initializes window with a grid of bricks.
 */
void initBricks(GWindow window)
{
    for(int i = 0; i < ROWS; i++)
    {
        for(int x = 0; x < COLS; x++)
        {
            GRect brick = newGRect(2 + (BL+6) * x, 50 + (BH+2) * i, BL, BH);
            if (i == 0)
            {
            setColor(brick, "RED");
            }
            else if (i == 1)
            {
            setColor(brick, "YELLOW");
            }
            else if (i == 2)
            {
            setColor(brick, "ORANGE");
            }
            else if (i == 3)
            {
            setColor(brick, "GREEN");
            }
            else if (i == 4)
            {
            setColor(brick, "BLUE");
            }
            setFilled(brick, true);
            add(window, brick);
        }
    }
}
/**
 * Initializes window with a grid of bricks.
 */
void initBricks(GWindow window)
{
    char *color[5] =   { "RED", "ORANGE", "YELLOW",  "GREEN", "CYAN"}; 
    
    double space = 4; // space in between bricks
    double x ; // vertical space before first brick
    double y = 50; //horizontal space before brick
    
    double brickWidth = 35;
    double brickHeight = 10;
    double w = getWidth(window);
    
    for (int r = 0 ; r < ROWS ; r++)
    {
        x = 2;
        for (int c = 0 ; c < COLS ; c++)
        {
            GRect brick = newGRect(x, y,brickWidth,brickHeight);
            setFilled(brick, true);
            setColor(brick,color[r]);
            add(window,brick);
            
            x = x + brickWidth + space;
        }
        
        y = y + brickHeight + space;
    }  
}
Beispiel #4
0
/**
 * Instantiate bricks and also return an array with Y coordinates for bricks.
 * This is probably not an elegant way to do it, but I wanted to avoid duplicate
 * code, running the same loop in a different function etc..
 */
int *initBricks(GWindow window)
{
    // array to store brick Y offsets
    int *bricks_offset = malloc(5 * sizeof(int));
    // drawing purpose array
    string color[5] = {"BLACK", "RED", "ORANGE", "GREEN", "CYAN"};
    // stay consistant with paddle bottom offset, paddle and bricks offsets are symmetrical
    int brick_top_offset = HEIGHT * 1/10. - BRICK_HEIGHT;
    
    for (int i = 0; i < 5; i++)
    {
        // update brick column offset on outer loop
        int y = brick_top_offset + (BRICK_SPACING * i) + (BRICK_HEIGHT * i);
        // store the offset
        bricks_offset[i] = y;
        for (int j = 0; j < 10; j++)
        {
            // update brick row
            int x = (BRICK_SPACING * j + 1) + (j * BRICK_WIDTH);
            // instantiate a new brick
            GRect brick = newGRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
            // set different brick colors for each row and add brick to canvas
            setFilled(brick, true);
            setColor(brick, color[i]);
            add(window, brick);
        }
    }
    
    return bricks_offset;
}
Beispiel #5
0
/**
 * Initializes window with a grid of bricks.
 */
void initBricks(GWindow window)
{
    string color[5] = {"BLACK", "RED", "ORANGE", "GREEN", "CYAN"};
    // stay consistant with paddle bottom offset, paddle and bricks offsets are symmetrical
    int brick_top_offset = HEIGHT * 1/10 - BRICK_HEIGHT;
    // set brick width to scale with window width
    int brick_width = WIDTH * 1/11;
    
    for (int i = 0; i < 5; i++)
    {
        // update brick column offset on outer loop
        int y = brick_top_offset + (BRICK_SPACING * i) + (BRICK_HEIGHT * i);
        for (int j = 0; j < 10; j++)
        {
            // update brick row
            int x = (BRICK_SPACING * j + 1) + (j * brick_width);
            // instantiate a new brick
            GRect brick = newGRect(x, y, brick_width, BRICK_HEIGHT);
            // set different brick colors for each row and add brick to canvas
            setFilled(brick, true);
            setColor(brick, color[i]);
            add(window, brick);
        }
    }
}
Beispiel #6
0
//Initializes window with a grid of bricks.
void initBricks(GWindow window)
{
    int xDistance = 2;
    int yDistance = 30;
    string rowColors[5];
    rowColors[0] = "RED";
    rowColors[1] = "MAGENTA";
    rowColors[2] = "ORANGE";
    rowColors[3] = "YELLOW";
    rowColors[4] = "GREEN";

    for(int row = 0; row < ROWS; row++)
    {
        for(int col = 0; col < COLS; col++, xDistance += 40)
        {
            GRect brick = newGRect(xDistance, yDistance, WIDTH/11, 10);
            setFilled(brick, true);
            setColor(brick, rowColors[row]);
            add(window, brick);
        }

        xDistance = 2;
        yDistance += 20;
    }
}
/**
 * Initializes window with a grid of bricks.
 */
void initBricks(GWindow window)
{
    // initiate bricks using five loops for each line of different colour.
    int i,j,posX=1,posY=50;
    for(i=0;i<ROWS;i++)    {
        for(j=0;j<COLS;j++)   {
        GRect brick = newGRect(posX+(j*40) ,posY+(i*15), BWIDTH, BHEIGHT);
       setFilled(brick, true);
        if(i==0){   //these if conditions choose colour for each line of bricks.
            setColor(brick, "RED");
        }
        if(i==1){
            setColor(brick, "BLUE");
        }
        if(i==2){
            setColor(brick, "CYAN");
        }
        if(i==3){
            setColor(brick, "YELLOW");
        }
        if(i==4){
            setColor(brick, "MAGENTA");
        }
        add(window, brick);
        }
    }
}
Beispiel #8
0
/**
 * Instantiates paddle in bottom-middle of window.
 */
GRect initPaddle(GWindow window)
{
    // TODO
    GRect paddle = newGRect((WIDTH / 2) - (PADDLEWIDTH / 2), HEIGHT - 10, PADDLEWIDTH, PADDLEHEIGHT);
    add(window, paddle);
    return paddle;
}
Beispiel #9
0
/**
 * Initializes window with a grid of bricks.
 */
void initBricks(GWindow window)
{
    int BricksWidth = (WIDTH / COLS) - 6;
    int BricksHeight = 10;
    for(int i = 0; i <= COLS - 1; i++)
    {
        for(int j = 0; j <= ROWS - 1 ; j++)
        {
            GRect bricks = newGRect(i * (WIDTH / COLS) + 2, j * (BricksHeight + 6) + 50 , BricksWidth, BricksHeight);
            if (j == 0)
            {
                setColor(bricks, "GREEN");
            }
            if (j == 1)
            {
                setColor(bricks, "BLUE");
            }
            if (j == 2)
            {
                setColor(bricks, "RED");
            }
            if (j == 3)
            {
                setColor(bricks, "YELLOW");
            }
            if (j == 4)
            {
                setColor(bricks, "CYAN");
            }
            setFilled(bricks, true);
            add(window, bricks);
        }
    }
}
/**
 * Initializes window with a grid of bricks.
 */
void initBricks(GWindow window)
{
    // TODO
	string color;
    for (int c = 0; c < COLS; c++) 
    {
        for (int r = 0; r < ROWS; r++)
        {
            GRect rect = newGRect( 40 * c + 3, 15 * r + 50, 34, 9);
            setFilled(rect, true);
			switch (r) {
            case 0:
                color = "RED";
                break;
            case 1:
                color = "ORANGE";
                break;
			case 2:
                color = "YELLOW";
                break;
			case 3:
                color = "CYAN";
                break;
            default:
                color = "GREEN";
            }
            setColor(rect, color);
            add(window, rect);
        }    
    }
    
}
Beispiel #11
0
/**
 * Initializes window with a grid of bricks.
 */
void initBricks(GWindow window)
{
    // create bricks
    
    //intialize column spacing
    double y = 10;
    
    //set colors
    string color[] = {"RED", "ORANGE", "YELLOW", "GREEN", "BLUE"};
    
    //create brick table
    for(int n = 0; n < ROWS; n ++)
      {
      double x = 2;
      for(int i = 0; i < COLS; i++)
        {
        GRect brick = newGRect(x, y, 35, 10);
        setFilled(brick, true);
        setColor(brick, color[n]);
        add(window, brick);
        x = x + 40;
        }
        y = y + 20;
      
      }
}
Beispiel #12
0
/**
 * Instantiates paddle in bottom-middle of window.
 */
GRect initPaddle(GWindow window)
{
    GRect rectangle = newGRect(WIDTH / 2 - PADDLEWIDTH / 2, HEIGHT - 30, PADDLEWIDTH, PADDLEHEIGHT);
    setColor(rectangle, "BLACK");
    setFilled(rectangle, true);
    return rectangle;
}
/**
 * Initializes window with a grid of bricks.
 */
void initBricks(GWindow window)
{
    // somewhere else ask user for number of blocks per row with slider perhaps? then calcualte even spaces
    for (int row = 0; row < ROWS; row++)
    {
        for(int column = 0; column < COLS; column++)
        {
            // location of individual bricks
            GRect(brick)= newGRect(SPACE / 2 + column * WIDTH / COLS, 
            (row + 2) * (HEIGHT / (ROWS + SPACE)) / ROWS,
            
            // size of bricks 
            WIDTH / COLS - SPACE, (HEIGHT / (ROWS + SPACE)) / ROWS - SPACE);
            
            // color bricks by row 
            switch (row % 3)
            {
                case 0:
                    setColor(brick, "GREEN");
                    setFilled(brick, true);
                    break;
                case 1:
                    setColor(brick, "GRAY");
                    setFilled(brick, true);
                    break;
                case 2:
                    setColor(brick, "YELLOW");
                    setFilled(brick, true);
                    break;
            }
            add(window, brick);
        }
    }
}
Beispiel #14
0
/**
 * Initializes window with a grid of bricks.
 */
void initBricks(GWindow window)
{
    
    double brickL =35 , brickH =10, space =4;
    double x = 2; // initial cordinate
    double y = SPACE; // final cordinate
    
    //char *color[5] ={"BLUE", "RED", "GREEN", "ORANGE", "YELLOW"};
    char *color[5] =   { "RED", "ORANGE", "YELLOW",  "GREEN", "CYAN"}; 
        
    for(int row = 0; row < ROWS; row++)
    {
        x = 2;      
        for(int col = 0 ; col < COLS; col++)
        {
            // start (x,y) end(x,y)
            GRect brick = newGRect( x , y, brickL, brickH);
            setFilled(brick, true);
            setColor(brick,color[row]);
            add(window,brick);
            x = x + brickL +space;
        }
        
        y = y + brickH + space;
    }
}
Beispiel #15
0
/**
 * Initializes window with a grid of bricks.
 */
void initBricks(GWindow window)
{
int x=0;
int y=40;

    for(int e = 0; e<ROWS; e++) {
    x=2;
        for(int i = 0; i<COLS;i++) {
         GRect bricks = newGRect(x,y,35,10);
        
            if(e==0) {
                setColor(bricks,"RED");
                setFilled(bricks,true);
            } if (e==1) {
                setColor(bricks,"FACC2E");
               setFilled(bricks,true);
            }  if (e==2) {
                setColor(bricks,"CE00F7");
              setFilled(bricks,true);
            }  if (e==3) {
                setColor(bricks,"BLUE");
                setFilled(bricks,true);
            } if (e==4) {
                setColor(bricks,"00DBF7");
                setFilled(bricks,true);
            }
          
              add(window,bricks);
              x = x+40;
   
        }
            y=y+13;
    }
}
Beispiel #16
0
/**
 * Instantiates paddle in bottom-middle of window.
 */
GRect initPaddle(GWindow window)
{
    GRect paddle = newGRect((WIDTH/2) - (BL/2) ,HEIGHT - (BH + 10), BL, BH);
    setColor(paddle, "BLACK");
    setFilled(paddle, true);
    add(window, paddle);
    return paddle;
}
Beispiel #17
0
/**
 * Instantiates paddle in bottom-middle of window.
 */
GRect initPaddle(GWindow window)
{
    GRect paddle = newGRect(190, 400, 50, 10);
    setFilled(paddle, true);
    setColor(paddle, "7FFFD4"); //Aquamarine
    add(window, paddle);
    return paddle;
}
Beispiel #18
0
/**
 * Instantiates paddle in bottom-middle of window.
 */
GRect initPaddle(GWindow window)
{
    GRect paddle=newGRect(200-35,500,70,10);
    setColor(paddle,"RED");
    setFilled(paddle, true);
    add(window,paddle);
    return paddle;
}
Beispiel #19
0
/**
 * Instantiates paddle in bottom-middle of window.
 */
GRect initPaddle(GWindow window)
{
    GRect paddle = newGRect(180, 550, PADWIDTH, PADHGHT);
    setColor (paddle, "MAGENTA");
    setFilled (paddle, true);
    add (window, paddle);
    return paddle;
}
Beispiel #20
0
/**
 * Instantiates paddle in bottom-middle of window.
 */
GRect initPaddle(GWindow window)
{
    GRect paddle = newGRect((WIDTH / 2) - (PADDLE_WIDTH / 2), HEIGHT - (HEIGHT / 7), PADDLE_WIDTH, PADDLE_HEIGHT);
    setColor(paddle, "BLACK");
    setFilled(paddle, true);
    add(window, paddle);
    return paddle;
}
Beispiel #21
0
/**
 * Instantiates paddle in bottom-middle of window.
 */
GRect initPaddle(GWindow window)
{
    GRect paddle = newGRect(200, 500, PHEIGHT, PWIDTH);
    setColor(paddle, "YELLOW");
    setFilled(paddle, true);
    add(window, paddle);
    return paddle;
}
Beispiel #22
0
/**
 * Instantiates paddle in bottom-middle of window.
 */
GRect initPaddle(GWindow window)
{
    GRect paddle = newGRect(185, 500, 50, 10);
    setFilled(paddle, true);
    setFillColor(paddle, "BLACK");
    add(window, paddle);
    return paddle;
}
Beispiel #23
0
/**
 * Instantiates paddle in bottom-middle of window.
 */
GRect initPaddle(GWindow window)
{
    GRect paddle = newGRect(160, 550, P_WIDTH, P_HEIGHT);
    setColor(paddle, "BLACK");
    setFilled(paddle, true);
    add(window, paddle);
    return paddle;
}
Beispiel #24
0
/**
 * Instantiates paddle in bottom-middle of window.
 */
GRect initPaddle(GWindow window)
{
    GRect paddle = newGRect(175, 500, 50, 10);
    setColor (paddle, "MAGENTA");
    setFilled (paddle, true);
    add (window, paddle);
    return paddle;
}
Beispiel #25
0
/**
 * Instantiates paddle in bottom-middle of window.
 */
GRect initPaddle(GWindow window)
{
    // newGRect utilizes paddle width(80) and paddle height(12)
    GRect paddle = newGRect((WIDTH / 2) - (80 / 2), 500, 80, 12);
    setColor(paddle, "BLACK");
    setFilled(paddle, true);
    add(window, paddle);
    return paddle;
}
Beispiel #26
0
/**
 * Instantiates paddle in bottom-middle of window.
 */
GRect initPaddle(GWindow window)
{
     // instantiate paddle
    GRect paddle = newGRect(200, 500, 70, 10);
    setColor(paddle, "ORANGE");
    setFilled(paddle, true);
    add(window, paddle);
    return paddle;
}
/**
 * Instantiates paddle in bottom-middle of window.
 */
GRect initPaddle(GWindow window)
{
    // create and return a paddle of type GRect
     GRect paddle = newGRect(PADDLEX ,PADDLEY , PADDLEW, PADDLEH);
        setFilled(paddle, true);
        setColor(paddle, "BLACK");
        add(window, paddle);
    return paddle;
}
Beispiel #28
0
/**
 * Instantiates paddle in bottom-middle of window.
 */
GRect initPaddle(GWindow window)
{
    GRect paddle = newGRect(0, 0, PWIDTH, PHEIGHT);
    setColor(paddle, "BLACK");
    setFilled(paddle, true);
    setLocation(paddle, ((WIDTH/2) - (PWIDTH/2)), 550);
    add(window, paddle);
    return paddle;
}
Beispiel #29
0
/**
 * Instantiates paddle in bottom-middle of window.
 */
GRect initPaddle(GWindow window)
{
    GRect paddle = newGRect(WIDTH/2 - PADDLE_WIDTH, HEIGHT - 50, PADDLE_WIDTH, PADDLE_HEIGHT);
    setColor(paddle, "DARK_GRAY");
    setFilled(paddle, true);
    add(window, paddle);
    
    return paddle;
}
Beispiel #30
0
/**
 * Instantiates paddle in bottom-middle of window.
 */
GRect initPaddle(GWindow window)
{
    //TODO (DONE)
    GRect paddle = newGRect(180, 560, 40, 10);
    setColor(paddle, "BLACK");
    setFilled(paddle, true);
    add(window, paddle);
    return paddle;
}