Report.01 (1) (AutoRecovered)
Report.01 (1) (AutoRecovered)
On
“PING PONG GAME IN C LANGUAGE”
In partial fulfillment of requirement for the degree of
Bachelor in Computer Application (B.C.A)
Course Code: CA 23.135
Course Title: C Programming Laboratory
Submitted By:
Esha Gupta (240210)
Rimpi (240215)
Teena Arora (240219)
November,2024
1
CERTIFICATE
It is certified that Esha Gupta, Rimpi, Teena Arora B.C.A.1st Semester student from Computer
Science and Engineering, Mody University, Lakshmangarh, has under gone project-based
learning (PBL) on “Ping Pong Game in C language” for the partial fulfillment towards the
degree of Bachelor of Computer Application (B.C.A.) in Computer Science and Engineering.
They have successfully completed the PBL work for the current semester under my/our
supervision.
Acknowledgement
2
We are deeply thankful to our guide, for his invaluable guidance, encouragement, and
constructive feedback throughout the project. His expertise and suggestions helped us overcome
challenges and improve the project's quality.
We also extend our gratitude to Mody University for providing the necessary resources and
infrastructure to complete this project.
Rimpi (240215)
ABSTRACT
3
The "Ping Pong Game" project developed in C language is an interactive and engaging console-
based application that allows users to have fun through a paddle and striking game .The primary
objective of the project is to create a simple yet effective game that challenges players' and help
them to entertain .
The game structure includes a racket where players select answers from a list of options. The
application tracks the number of shots the person has played . The player’s score is displayed at
the end of the game, and a congratulatory message is shown based on the final score.
Table of Contents
4
S. No. TOPICS Page No.
Certificate 2
Acknowledgement 3
Abstract 4
1. Introduction 7-9
2. Components Details
3. Steps Performed
Code 14
4. Result/Discussion/Output
5
Conclusion 25
Future Scope 26
References 27
Chapter 1: Introduction
6
1. INTRODUCTION
Ping pong, also known as table tennis, is a fast-paced and exciting sport that combines skill,
strategy, and quick reflexes. Played by two or four players, the game takes place on a rectangular
table divided by a net. Players use small, lightweight paddles to hit a lightweight plastic ball back
and forth, aiming to score points by outmanoeuvring their opponent.
Background:
The origins of ping pong, or table tennis, trace back to the late 19th century in
England, where it began as an indoor adaptation of lawn tennis. Initially, it was a
casual parlor game played by the upper class after dinner. Players used everyday
objects like books as paddles, corks or balls of string as balls, and a row of books
or a net as the divider.
The game quickly evolved, with more structured rules and specialized equipment
emerging. By the 1900s, manufacturers began producing celluloid balls and
paddles with rubber surfaces, which improved gameplay. The term "ping pong"
was trademarked by the Parker Brothers (now Hasbro) in the early 1900s, though
the sport officially adopted "table tennis" as its name in international competitions.
Objective:
The objective of the game is to score points by either forcing your opponent to
miss the ball or make an invalid return. Ping pong can be played recreationally or
competitively, with matches often being thrilling displays of agility, precision, and
tactical thinking.
7
Whether you're a beginner learning the basics or a seasoned pro, ping pong is a
game that can be enjoyed by people of all ages and skill levels. It’s not just about
competition—it’s also about having fun, staying active, and sharpening your hand-
eye coordination.
Significance:
- Enhanced creativity.
- Technological Advancement
8
Creativity: Games like Minecraft encourage creativity and resource management.
Technological Advancement:
Game development drives innovations in graphics, AI, virtual reality, and augmented reality.
These advancements often benefit other industries, including healthcare, education, and
architecture.
They serve as a platform for representation and diversity in character design and
storytelling.
Limitations
Technical Limitations
9
1. Limited User Interface (UI) Capabilities.
The present system of a quiz game typically refers to an existing implementation or version of a
quiz game that is already functional, though it may have certain limitations or opportunities for
improvement. A present system could vary greatly depending on how the game is structured,
what technologies are used, and its features. Below is an outline of the common features and
characteristics of a basic present system of a quiz game.
System Overview
The present system of a quiz game generally operates on a simple text-based interface. It allows
users to answer a series of questions and provides immediate feedback on their performance. The
system may or may not include additional features such as difficulty selection, time limits, or
score tracking.
The core features of a typical quiz game system include the following:
a. User Interface
b. Text-based Interface (Console): A simple interface where the user interacts by
typing in answers or selecting options via the keyboard.
10
c. Start Game: The user selects to start the ping pong game, which then presents questions
one by one.
Game Navigation: After ,the user typically presses "Enter" to move to the next round.
Some versions may allow the user to skip or jump between rounds.
Game End: At the end of the game, the system displays the user’s total score, how much
score was obtained at last, and sometimes a summary of their performance.
d. Score and Leaderboard
Final Score: Once the level is started, the system displays the user’s score, which is the
number of correct times they reciprocated the ball with racket out of the total balls
offered.
e. Retry and Exit
f. Replay Option: After the game ends, users are often prompted to try again or quit. They
can choose to restart the game with different settings or categories.
Exit Game: The game provides the option to exit after completing the quiz
The ping pong game system can be designed with multiple features, including different
categories, difficulty levels, a time limit for each level , a scoring system, and a
leaderboard. The idea is to make the engaging, competitive, and flexible.
Here’s a breakdown of a proposed design for a ping pong game in C:
1. Features:
Categories: The game can have different categories such as "attractice interface". The
concept is taken from table tennis game.
Difficulty Levels: There can be different levels of difficulty (e.g., Easy, Medium, Hard).
Timer: Each ball will have a time limit to answer.
Scoring System: The user earns points for each ball hitted.
11
Leaderboard: Track the highest scores for players.
2. Game Flow:
Start Screen: Greet the user and let them select the category and difficulty.
Game Round: The game will begin at 0:00 and the racket will appear and ball will be
thrown on the player to hit.
Timer: A countdown for hitting each ball (e.g., 10 seconds per ball).
Leaderboard: A file or array to track the top scores.
Player Data: Store the current player’s name and score for the session.
4. C Code Example:
Below is a simple implementation of the proposed system. It handles:
Categories and difficulty levels
Timer for each question
Scoring system
12
Compiler - Turbo C
Software System – Windows 11
UI Components:
Each component works together to create a smooth and interactive quiz game experience. The
structure can be easily extended with additional features like difficulty levels, multiple
categories, or a leaderboard system.
3.1 FLOWCHART
13
Figure 3.1
3.2 PROCESS
In a ping pong game implemented in C, the steps performed can be broken down into a series of
operations that guide the game flow from start to finish. These steps are logically arranged to
1. Initialization Phase
Action: The game starts by showing a welcome message to the player. This includes the
rules of the game, instructions, and any relevant details (e.g., how to input answers, time
limits).
14
Function: displayWelcomeMessage ()
Action: The player is prompted to enter their name. This is done to personalize the game
and make the experience more interactive.
Action: Once the game is completed , the game calculates the player’s final score (e.g.,
number of correct balls hit out of total balls) and displays it.
Action: After displaying the final score, the game asks the player if they would like to
play the ping pong game again.
Function: askReplay()
5. Ending Phase
15
Step 12: Exit or Replay
Action:
o If the player chooses to replay, the game restarts from the beginning (repeating
the initialization and game loop phases).
o If the player chooses not to replay, the game ends with a message of thankyou.
Function: If the player selects "No," the game exits with a final message.
Function: If the player selects "Yes," the game restarts, beginning with the welcome
message and the player’s name prompt.
3.3 CODE
#include <stdio.h>
#include <conio.h>
#include <dos.h>
// Game settings
#define WIDTH 40
16
#define HEIGHT 20
void draw() {
int i, j;
printf("\n");
if (j == 0 || j == WIDTH - 1) {
17
} else if (j == 2 && (i == leftPaddleY || i == leftPaddleY + 1 || i == leftPaddleY + 2)) {
printf("O"); // Ball
} else {
printf(" ");
printf("\n");
printf("\n");
// Display scores
void updateBall() {
ballX += ballDirX;
ballY += ballDirY;
18
// Bounce off paddles
if (ballX == 3 && ballY >= leftPaddleY && ballY <= leftPaddleY + 2) ballDirX = -ballDirX;
if (ballX == WIDTH - 4 && ballY >= rightPaddleY && ballY <= rightPaddleY + 2) ballDirX = -ballDirX;
// Scoring
if (ballX <= 0) {
computerScore++;
ballX = WIDTH / 2;
ballY = HEIGHT / 2;
userScore++;
ballX = WIDTH / 2;
ballY = HEIGHT / 2;
void updateUserPaddle() {
if (kbhit()) {
char ch = getch();
19
}
void updateComputerPaddle() {
// Main function
void main() {
int gameRunning = 1;
// Initialize positions
ballX = WIDTH / 2;
ballY = HEIGHT / 2;
leftPaddleY = HEIGHT / 2 - 1;
rightPaddleY = HEIGHT / 2 - 1;
// Game loop
while (gameRunning) {
draw();
updateBall();
updateUserPaddle();
updateComputerPaddle();
20
if (userScore == 5 || computerScore == 5) {
gameRunning = 0;
clrscr();
printf("Game Over!\n");
if (userScore == 5) {
printf("You Win!\n");
} else {
printf("Computer Wins!\n");
21
OUTPUT:
22
23
Chapter 4: Result/Discussion/Output
The result of a ping pong game typically includes the following elements:
1. Number of Correct Answers: This shows how many questions the player answered correctly.
3. Score Percentage: A percentage calculated by dividing the total balls by the total balls of and
then multiplying by 100
24
Conclusion:
In conclusion, the proposed **Ping Pong game in C** is a fun and entertainment way for users
to test and improve their entertainment quotient. The game is built using basic features of the C
programming language, like arrays, loops, and file handling, making it a great project for
learning programming. Users can get instant feedback on their answers, which helps them learn
and stay motivated. Although the game is text-based and doesn’t have fancy graphics, it is
simple, easy to use, and works well on most computers. The system can easily be expanded with
new features like multiplayer modes, leaderboards, or hints for questions. It also gives
programmers a chance to practice important skills like managing memory, checking user input,
and handling errors. While the game starts in a console window, it can be improved in the future
with a graphical interface or even be made available on the web or mobile devices. Overall, this
ping pong game is a good mix of learning, fun, and programming practice, with plenty of room
to grow and improve.
25
Future Scope:
To further enhance the system's functionality and effectiveness, potential future developments
include:
1. Mobile Application: Develop a mobile application for Android and iOS platforms to
increase accessibility.
2. Integration with social media: Integrate social media platforms for seamless login and
sharing.
3. Online Multiplayer: Introduce real-time multiplayer modes where users can compete
against each other, either in head-to-head battles or as part of a team.
4. Web-Based Game: Making it accessible from any browser without the need for
installation. This would allow the game to reach a much larger audience.
26
References:
GeeksforGeeks
Youtube
Let us C
Google
27