VOOZH about

URL: https://www.geeksforgeeks.org/cpp/create-bingo-game-using-cpp/

⇱ Create Bingo Game Using C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Create Bingo Game Using C++

Last Updated : 22 Sep, 2023

Bingo, a timeless game of chance and anticipation, has been captivating players for generations. The thrill of marking numbers off your card and the excitement of shouting "Bingo!" are experiences that transcend time. In this article, we will guide you through the process of creating your very own Bingo game using the versatile and powerful C++ programming language.

Setting Up Development Environment

Before we dive into creating our Bingo game, make sure you have a functional C++ development environment in place. Popular choices include compilers like GCC (GNU Compiler Collection) or Visual C++. These tools will help you compile and execute your code seamlessly. With your environment ready, let's embark on the journey of building the Bingo game!

Designing the Bingo Game

Developing a Bingo game in C++ involves breaking down the implementation into several crucial components:

Bingo Card: We'll start by defining a structure that represents a Bingo card. This structure will hold the numbers that players aim to mark off.

Number Drawing: Next, we'll create a mechanism to draw random numbers and ensure that both players update their cards accordingly.

Game Logic: The game should run within a loop until a player achieves Bingo or a predefined condition is met.

Implementing the Bingo Game

Output:

Player 1 - Drawn Number: 14
Player 1's Card:
25 15 22 12 10
24 23 5 16 20
21 7 11 6 3
1 4 13 17 18
19 X 8 9 2
--------------------------
Player 2's Card:
22 10 16 24 8
1 13 15 20 12
5 X 25 4 19
17 9 18 7 23
11 21 3 6 2
--------------------------
Player 2 - Drawn Number: 11
Player 1's Card:
25 15 22 12 10
24 23 5 16 20
21 7 X 6 3
1 4 13 17 18
19 X 8 9 2
--------------------------
Player 2's Card:
22 10 16 24 8
1 13 15 20 12
5 X 25 4 19
17 9 18 7 23
X 21 3 6 2
--------------------------
Player 1 - Drawn Number: 15
Player 1's Card:
25 X 22 12 10
24 23 5 16 20
21 7 X 6 3
1 4 13 17 18
19 X 8 9 2
--------------------------
Player 2's Card:
22 10 16 24 8
1 13 X 20 12
5 X 25 4 19
17 9 18 7 23
X 21 3 6 2
--------------------------
Player 2 - Drawn Number: 21
Player 1's Card:
25 X 22 12 10
24 23 5 16 20
X 7 X 6 3
1 4 13 17 18
19 X 8 9 2
--------------------------
Player 2's Card:
22 10 16 24 8
1 13 X 20 12
5 X 25 4 19
17 9 18 7 23
X X 3 6 2
--------------------------
Player 1 - Drawn Number: 6
Player 1's Card:
25 X 22 12 10
24 23 5 16 20
X 7 X X 3
1 4 13 17 18
19 X 8 9 2
--------------------------
Player 2's Card:
22 10 16 24 8
1 13 X 20 12
5 X 25 4 19
17 9 18 7 23
X X 3 X 2
--------------------------
Player 2 - Drawn Number: 2
Player 1's Card:
25 X 22 12 10
24 23 5 16 20
X 7 X X 3
1 4 13 17 18
19 X 8 9 X
--------------------------
Player 2's Card:
22 10 16 24 8
1 13 X 20 12
5 X 25 4 19
17 9 18 7 23
X X 3 X X
--------------------------
Player 1 - Drawn Number: 5
Player 1's Card:
25 X 22 12 10
24 23 X 16 20
X 7 X X 3
1 4 13 17 18
19 X 8 9 X
--------------------------
Player 2's Card:
22 10 16 24 8
1 13 X 20 12
X X 25 4 19
17 9 18 7 23
X X 3 X X
--------------------------
Player 2 - Drawn Number: 21
Player 1's Card:
25 X 22 12 10
24 23 X 16 20
X 7 X X 3
1 4 13 17 18
19 X 8 9 X
--------------------------
Player 2's Card:
22 10 16 24 8
1 13 X 20 12
X X 25 4 19
17 9 18 7 23
X X 3 X X
--------------------------
Player 1 - Drawn Number: 6
Player 1's Card:
25 X 22 12 10
24 23 X 16 20
X 7 X X 3
1 4 13 17 18
19 X 8 9 X
--------------------------
Player 2's Card:
22 10 16 24 8
1 13 X 20 12
X X 25 4 19
17 9 18 7 23
X X 3 X X
--------------------------
Player 2 - Drawn Number: 22
Player 1's Card:
25 X X 12 10
24 23 X 16 20
X 7 X X 3
1 4 13 17 18
19 X 8 9 X
--------------------------
Player 2's Card:
X 10 16 24 8
1 13 X 20 12
X X 25 4 19
17 9 18 7 23
X X 3 X X
--------------------------
Player 1 - Drawn Number: 13
Player 1's Card:
25 X X 12 10
24 23 X 16 20
X 7 X X 3
1 4 X 17 18
19 X 8 9 X
--------------------------
Player 2's Card:
X 10 16 24 8
1 X X 20 12
X X 25 4 19
17 9 18 7 23
X X 3 X X
--------------------------
Player 2 - Drawn Number: 6
Player 1's Card:
25 X X 12 10
24 23 X 16 20
X 7 X X 3
1 4 X 17 18
19 X 8 9 X
--------------------------
Player 2's Card:
X 10 16 24 8
1 X X 20 12
X X 25 4 19
17 9 18 7 23
X X 3 X X
--------------------------
Player 1 - Drawn Number: 21
Player 1's Card:
25 X X 12 10
24 23 X 16 20
X 7 X X 3
1 4 X 17 18
19 X 8 9 X
--------------------------
Player 2's Card:
X 10 16 24 8
1 X X 20 12
X X 25 4 19
17 9 18 7 23
X X 3 X X
--------------------------
Player 2 - Drawn Number: 22
Player 1's Card:
25 X X 12 10
24 23 X 16 20
X 7 X X 3
1 4 X 17 18
19 X 8 9 X
--------------------------
Player 2's Card:
X 10 16 24 8
1 X X 20 12
X X 25 4 19
17 9 18 7 23
X X 3 X X
--------------------------
Player 1 - Drawn Number: 8
Player 1's Card:
25 X X 12 10
24 23 X 16 20
X 7 X X 3
1 4 X 17 18
19 X X 9 X
--------------------------
Player 2's Card:
X 10 16 24 X
1 X X 20 12
X X 25 4 19
17 9 18 7 23
X X 3 X X
--------------------------
Player 1 has achieved Bingo! Congratulations!

Playing the Bingo Game

Initiating the Game: Begin by compiling and executing the C++ program to initiate gameplay. The console will showcase the game's progression and updates as they unfold.

Unfolding Gameplay: As the game proceeds, participants will alternately draw numbers and adjust their individual Bingo cards accordingly.

Achieving Bingo: The game endures until a player successfully forms a Bingo pattern on their card. At this juncture, the program will announce the victor and bring the game to a close.

Comment
Article Tags: