VOOZH about

URL: https://www.geeksforgeeks.org/c/program-to-design-a-brick-game-using-computer-graphics/

⇱ Program to design a Brick Game using computer graphics - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to design a Brick Game using computer graphics

Last Updated : 23 Jul, 2025

In C graphics, the graphics.h functions are used to draw different shapes like a circle, rectangle, etc, display text(any message) in different formats (different fonts and colors). By using graphics.h programs, animations, and also games can be designed. These can be useful for beginners.


Functions Used:

  • rectangle(l, t, r, b): A function from graphics.h header file which draws a rectangle from left(l) to right(r) and from top(t) to bottom(b).
  • line(a1, b1, a2, b2):  A function from graphics.h header file which draws a line from (a1, b1) point to (a2, b2) point.
  • setfillstyle(pattern, color): A function from graphics.h header file by which one can give a pattern of drawing and also a specific color.
  • floodfill(a, b, c): A function from graphics.h header file by which one can color a specific bounded area with (a, b) as the center and c is the border color.
  • outtextxy(int x, int y, char *string): A function from graphics.h header file by which one can print any statements where, x, y are the coordinates of the point and, the third argument contains the address of the string to be displayed.
  • settextstyle(int font, int direction, int font_size): A function from graphics.h header file which can be used for the style of the printable text where the font argument specifies the font of the text. Direction can be HORIZ_DIR (Left to right) or VERT_DIR (Bottom to top).


Approach:

  • This is a brick game where bricks come from up are of random colors.
  • There are 3 columns in which the bricks can be placed.
  • If two bricks of the same color come adjacent to each other, they both disappear and the score will increase by 10 points.
  • If the bricks touch the top of the game area, then the game will be over. Below is a video to explain how the game works.

Below is the program to implement the same:

Output:

Comment