0% found this document useful (0 votes)
79 views11 pages

Bubble Shooter

Uploaded by

kasithangamcse92
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views11 pages

Bubble Shooter

Uploaded by

kasithangamcse92
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Building a Bubble Shooter

Game with Recursion in C


Join us for a captivating journey into the world of bubble
shooters, where we'll explore the elegant power of recursion
to create a dynamic and engaging game using the C
programming language.
Introduction to Bubble Shooter Games

A popular arcade game Players strategically aim These games often feature
where the goal is to and shoot bubbles to create levels with increasing
eliminate bubbles by clusters of three or more of difficulty, challenging
shooting colored bubbles the same color, causing players with new patterns
from a cannon. them to burst. and bubble types.
Conceptualizing the Game Mechan

Bubble Creation Bubble Launching

Generate bubbles of Allow the player to aim


different colors and and shoot bubbles from
sizes. a cannon.
Bubble Collisions Bubble Elimination

Detect collisions Implement a recursive


between bubbles and function to eliminate
the game board. groups of three or more
bubbles of the same
color.
Implementing a Recursive Function

Base Case

1 Check if a group of bubbles is less than three in size.

Recursive Step

2 Recursively call the function to eliminate neighboring


bubbles of the same color.

Bubble Elimination
3
Remove the bubbles from the game board.
Defining the Game Board and Bubbles

Game Board Bubbles

A grid structure, typically Circular objects with


circular, to hold the unique colors and
bubbles. positions on the board.

Data Structures

Utilize arrays or linked lists to represent the game board and bubbles.
Handling User Input and Bubble La
Mouse/Keyboard Input

Capture player input to control the cannon.

Aiming

Update the cannon's direction based on player input.

Launching

Release a bubble from the cannon in the targeted direct


Detecting Bubble Collisions and Removal

Collision Detection Bubble Removal

Check if the launched bubble Remove the collided bubble


collides with any existing and any other bubbles that
bubbles. are part of a group of three
or more of the same color.
Applying Recursive Logic for Bubble Elimination

Base Case
1
If no more adjacent bubbles of the same color exist, stop the recursion.

Recursive Step
2
Recursively check for adjacent bubbles of the same color and eliminate them

Bubble Removal
3
Remove the eliminated bubbles from the game board.
Scoring, Levels, and Game Progression

100 3
Score Levels

Award points for each group Introduce new challenges as


of bubbles eliminated. the player progresses.
#include <stdio.h> void clearBubbles(char board[ROWS] void shootBubble(char // Fill some bubbles in the board to
#include <stdlib.h> [COLS], int row, int col, char board[ROWS][COLS], int row, int col, simulate initial conditions
#define ROWS 10 targetColor) { char bubbleColor) { board[4][4] = 'R'; // Red bubble at
#define COLS 10 // Base cases if (board[row][col] == ' ') { position (4, 4)
if (row < 0 || row >= ROWS || col < board[row][col] = board[4][5] = 'R'; // Red bubble at
// Directions for adjacent bubbles 0 || col >= COLS) { bubbleColor; // Place the bubble in position (4, 5)
(left, right, up, down) return; // Out of bounds the empty spot board[5][4] = 'R'; // Red bubble at
int directions[4][2] = { } printf("Bubble shot at position position (5, 4)
{-1, 0}, // Up if (board[row][col] != targetColor) { (%d, %d)\n", row, col); board[6][4] = 'B'; // Blue bubble
{1, 0}, // Down return; // Not the target color at position (6, 4)
{0, -1}, // Left } // After shooting, we check for board[6][5] = 'B'; // Blue bubble
{0, 1} // Right any connected bubbles of the same at position (6, 5)
}; // Clear the current bubble color
board[row][col] = ' '; // clearBubbles(board, row, col, // Print initial board state
// Function to print the game grid Representing an empty spot bubbleColor); // Clear bubbles of printf("Initial Board:\n");
void printBoard(char board[ROWS] the same color printBoard(board);
[COLS]) { // Recursively call for all 4 adjacent } else {
for (int i = 0; i < ROWS; i++) { cells printf("Cannot shoot here, // Simulate shooting a Red bubble
for (int j = 0; j < COLS; j++) { for (int i = 0; i < 4; i++) { position already filled!\n"); at position (5, 5)
printf("%c ", board[i][j]); int newRow = row + directions[i] } shootBubble(board, 5, 5, 'R'); //
} [0]; } Shoot red bubble at (5,5)
printf("\n"); int newCol = col + directions[i][1];
} clearBubbles(board, newRow, int main() { // Print the updated board state
} newCol, targetColor); // Recursive call // Initialize the board with empty printf("\nUpdated Board After
} spaces Shot:\n");
//Recursive function to clear } char board[ROWS][COLS]; printBoard(board);
connected bubbles of the same for (int i = 0; i < ROWS; i++) {
color // Function to shoot a bubble (insert for (int j = 0; j < COLS; j++) { return 0;
into the grid) and clear connected board[i][j] = ' '; // ' ' }
bubbles represents an empty spot
}
}
OUTPUT
Initial Board:

RRR
RRR
BB

Bubble shot at position (5, 5)

Updated Board After Shot:

RRR
RRR
RR

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy