0% found this document useful (0 votes)
22 views18 pages

Reportformat UPDATED

Uploaded by

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

Reportformat UPDATED

Uploaded by

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

KARNATAK LAW SOCIETY’S

GOGTE INSTITUTE OF TECHNOLOGY


UDYAMBAG, BELAGAVI – 590008
(An Autonomous Institution under Visvesvaraya Technological University, Belagavi)
(APPROVED BY AICTE, NEW DELHI)

PYTHON COURSE ACTIVITY Report


submitted in the partial fulfillment for the academic requirement of
3rd Semester BE in Information Science and Engineering

TOPIC: BALL CATCHER GAME


Subject Code: 22IS354
Submitted by:

NAME USN

ADITYA.VERNEKAR 2GI23IS004
CHAITAN.TALAWAR 2GI23IS026
APPASAB.WADDAR 2GI23IS014

under the guidance of,


Dr. SUDHINDRA.DESPHANDE
Associate Professor, ISE dept, KLS GIT
Course Activity Report and PPT Content
Marks allocation:
Sl.No Batch No:
1. Seminar Title: Marks USN
Range
2. Abstract (PO2) 0-2
3. Application of the topic to the
0-2
course(PO2)
4. Literature survey and its
0-2
findings(PO2)
5. Methodologies, Result and
0-2
Conclusion (PO1,PO3,PO4)
6. Report and oral representation
0-2
skill(PO9,PO10)
Total 10
* 10 marks is for CGPA calculation

1.Engineering Knowledge: Apply the knowledge of mathematics, science, engineering fundamentals and an
engineering specialization to the solution of complex engineering problems.
2.Problem Analysis: Identify, formulate, review research literature, and analyze complex engineering problems
reaching substantiated conclusions using first principles of mathematics, natural sciences and Engineering sciences.
3.Design/Development of solutions: Design solutions for complex engineering problems and design system
components or processes that meet the specified needs with appropriate consideration for the public health and
safety, and the cultural, societal, and environmental considerations.
4.Conduct investigations of complex problems: Use research-based knowledge and research methods including
design of experiments, analysis and interpretation of data, and synthesis of the information to provide valid
conclusions.
5.Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering and IT
tools including prediction and modeling to complex engineering activities with an understanding of the limitations.
6.The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal, health, safety,
legal and cultural issues and the consequent responsibilities relevant to the professional engineering practice.
7.Environment and sustainability: Understand the impact of the professional engineering solutions in societal and
environmental contexts, and demonstrate the knowledge of, and need
for sustainable development.
8.Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the engineering
practice.
9.Individual and team work: Function effectively as an individual and as a member or leader in diverse teams, and
in multidisciplinary settings.
10.Communication: Communicate effectively on complex engineering activities with the engineering community
and with society at large, such as, being able to comprehend and write effective reports and design documentation,
make effective presentations, and give and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the engineering management
principles and apply these to one’s own work, as a member and leader in a team, to manage projects and in
multidisciplinary environments.
12. Life-long learning: Recognize the need for and have the preparation and ability to engage in independent and
lifelong learning in the broadest context of technological change.
INDEX

1) PROBLEM STATEMENT 1

2) OBJECTIVES 1

3) TOOLS USED 2

4) INTRODUCTION 3

5) METHODOLOGY 4

6) CODE IMPLEMENTATION 5

7) OUTPUT 11

8) CONCLUSION 15

9) REFERENCES 15
BALL CATCHER GAME

1) PROBLEM STATEMENT:

This project aims to create a simple and interactive ball-catching


game where users can log in or register, play through multiple difficulty
levels, and track their scores. The game challenges players to catch
falling balls with a paddle, increasing in difficulty as they progress.
Player details like username, score, and progress are stored securely in a
database, and a log file keeps track of gameplay activities, such as login
times and restart actions.

2) OBJECTIVES:

i. User Registration and Login System:


• Provide a secure mechanism for users to register and log in.
• Store user credentials in a database to ensure data persistence.
ii. Engaging Gameplay:
• Design a fun game where users catch falling balls using a paddle.
• Include multiple levels (Easy, Medium, Hard) with increasing
difficulty to keep players engaged.
iii. Progress Tracking and Scoring:
• Record and display the player's progress (score and level) during the
game.
• Store this data in a database for future reference.
iv. Logging Mechanism:
• Maintain a log file to track user activities, such as login, progress
during the game, and restarts.
• Include timestamps to provide detailed session records.
v. Game Restart Feature:
• Allow users to restart the game from the beginning after game over.
• Ensure the new session is also recorded in the log file.

1
3) TOOLS USED :

i. Programming Language - Python:


• Python 3.11 is used as the primary programming language because of
its simplicity and powerful libraries for game development and data
handling.

ii. GUI Library - Tkinter:


• Tkinter is utilized to design the graphical interface, including the
game window, paddle, balls, and score display. It helps make the
game interactive and visually appealing.

iii. Database - SQLite:


• SQLite is used to store player details like username, password, scores,
and progress. It is lightweight, easy to use, and ensures that data is
saved even after the game ends.

iv. Logging with File I/O:


• Python's built-in file handling is used to create a log file that tracks
player activity. This includes login time, game progress, score, and
restart events for each session.

v. Libraries Used:
• Random: For generating random positions for falling balls, making
the game unpredictable and exciting.
• Time: For recording timestamps in the log file, providing a detailed
history of gameplay sessions.

These tools work together to create an engaging, data-driven game with


user-friendly features and a seamless experience.

2
4) INTRODUCTION:

The Ball Catching Game is an engaging and interactive game


designed to test and improve players' reflexes and concentration. The
game involves controlling a paddle to catch falling balls, with the
difficulty increasing as players progress through three levels: Easy,
Medium, and Hard. Each level brings faster ball speeds, making the
game more challenging and fun.
Players start by registering or logging in, ensuring their scores and
progress are saved securely. The game keeps track of their achievements,
such as current scores and levels, and displays them in real-time. If a ball is
missed, the game ends, but players can restart and try again while their
activities, including restarts and progress, are logged for tracking purposes.

➢ SIGNIFICANCE:
1. Entertainment and Skill Development:
The game offers a combination of fun and skill enhancement. It sharpens
players’ reflexes, hand-eye coordination, and decision-making abilities.
2. Learning Opportunity for Developers:
For developers, this project provides hands-on experience in combining
game development with user authentication, database management, and
real-time data handling.
3. Practical Use of Programming Concepts:
The game incorporates essential programming concepts like GUI design,
collision detection, database interaction, and file handling, making it a
great project for learning and applying coding skills.
4. Customizable and Expandable:
The design allows for future enhancements, such as adding new levels,
power-ups, or additional gameplay mechanics, ensuring long-term
engagement and adaptability.

The Ball Catching Game is more than just entertainment—it’s a learning


tool for programmers and a fun challenge for players of all ages.

3
5) METHODOLOGY:

➢ Logic Used (Mathematical Approach):


• Coordinate Geometry: The game uses the coordinates of the ball and
paddle to detect collisions. A catch is registered when the ball's coordinates
overlap with the paddle's bounding box.
• Dynamic Speed Adjustment: The speed of falling balls increases as
players progress through levels, controlled by a mathematical increment
based on level progression.

➢ Steps/Process Followed:

1. User Authentication System:


• Implemented registration and login features to ensure each player has a unique
profile.
• Credentials are securely stored in an SQLite database.
2. Gameplay Mechanics:
• The game starts at the "Easy" level with slower ball speeds.
• Balls fall from random positions at the top of the screen. Players move the paddle
using arrow keys to catch them.
3. Collision Detection:
• A "catch" is detected when the ball overlaps with the paddle’s position. The score
is updated accordingly.
4. Level Progression:
• After every 5 successful catches, the game progresses to a higher level (Medium,
then Hard), with balls falling faster.
• The current level and score are displayed at the center of the game screen for
clarity.
5. Game Over Logic:
• The game ends if a ball reaches the bottom of the screen without being caught.
• The player’s score and level are saved to the database, and a log entry is created
with the session details.
6. Restart Feature:
• After game over, players can restart the game. The new session details, including
the restart action, are logged for tracking purposes.

This methodology ensures the game is intuitive, scalable, and enjoyable, while also
teaching key programming concepts through its implementation.

4
6) CODE IMPLEMENTATION:

import tkinter as tk
from tkinter import messagebox
import sqlite3
import random
import time

# Define database and log file names


DB_NAME = 'details.db'
LOG_FILE = 'game_log.txt'

# Initialize database and tables


def setup_database():
conn = sqlite3.connect(DB_NAME)
cursor = conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS users (username TEXT
PRIMARY KEY, password TEXT)")
cursor.execute("CREATE TABLE IF NOT EXISTS scores (username TEXT,
score INTEGER)")
conn.commit()
conn.close()

# Log session information


def log_session(username, action, level, score):
with open(LOG_FILE, 'a') as log:
log_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
log.write(f"Username: {username}, Action: {action}, Level: {level},
Score: {score}, Time: {log_time}\n")

# Register a new user


def register():
username = entry_username.get()
password = entry_password.get()

5
if username and password:
conn = sqlite3.connect(DB_NAME)
cursor = conn.cursor()
cursor.execute("SELECT * FROM users WHERE username = ?",
(username,))
if cursor.fetchone():
messagebox.showerror("Error", "Username already exists!")
else:
cursor.execute("INSERT INTO users (username, password) VALUES
(?, ?)", (username, password))
conn.commit()
messagebox.showinfo("Registration", "Registration successful!")
conn.close()
else:
messagebox.showwarning("Input Error", "Please enter both username
and password")

# Login existing user


def login():
username = entry_username.get()
password = entry_password.get()

conn = sqlite3.connect(DB_NAME)
cursor = conn.cursor()
cursor.execute("SELECT * FROM users WHERE username = ? AND
password = ?", (username, password))
user = cursor.fetchone()
conn.close()

if user:
messagebox.showinfo("Login", "Login successful!")
log_session(username, "Login", "-", 0)
open_game_window(username)
else:
messagebox.showerror("Error", "Invalid username or password")

6
# Ball-catching game
def open_game_window(username):
game_window = tk.Toplevel(root)
game_window.title("Ball Catching Game")

# Game variables
levels = {1: {"speed": 5, "level_name": "Easy"},
2: {"speed": 8, "level_name": "Medium"},
3: {"speed": 12, "level_name": "Hard"}}
level = 1
speed = levels[level]["speed"]
ball_count = 0
score = 0

# Set up the canvas


canvas = tk.Canvas(game_window, width=400, height=400,
bg="lightblue")
canvas.pack()

# Create catcher (basket), score, and level display


catcher = canvas.create_rectangle(170, 370, 230, 390,
fill="darkorange")
level_text = canvas.create_text(200, 20, text="Level: Easy", font=("Arial",
16, "bold"), fill="black")
score_text = canvas.create_text(200, 50, text="Score: 0", font=("Arial",
14), fill="black")
current_ball = None

# Move catcher
def move_left(event):
if canvas.coords(catcher)[0] > 0: # Prevent moving out of bounds
canvas.move(catcher, -20, 0)

def move_right(event):
if canvas.coords(catcher)[2] < 400: # Prevent moving out of bounds
canvas.move(catcher, 20, 0)
7
game_window.bind("<Left>", move_left)
game_window.bind("<Right>", move_right)

# Drop balls
def drop_ball():
nonlocal current_ball
if current_ball is None: # Only create a new ball if none exists
x = random.randint(20, 380)
ball_color = random.choice(["#FF6347", "#FFD700", "#00FA9A",
"#1E90FF", "#FF69B4"])
current_ball = canvas.create_oval(x, 10, x + 20, 30, fill=ball_color)
game_window.after(1500, drop_ball)

# Update game mechanics


def update_game():
nonlocal score, ball_count, level, speed, current_ball
if current_ball:
canvas.move(current_ball, 0, speed)
ball_pos = canvas.coords(current_ball)
catcher_pos = canvas.coords(catcher)

# Check for collision with catcher


if (catcher_pos[0] < ball_pos[0] < catcher_pos[2] and
catcher_pos[1] < ball_pos[1] < catcher_pos[3]):
canvas.delete(current_ball)
current_ball = None
score += 1
ball_count += 1
canvas.itemconfig(score_text, text=f"Score: {score}")

# Increase level after every 5 balls


if ball_count % 5 == 0:
level = min(level + 1, 3) # Cap level at 3
speed = levels[level]["speed"]

8
canvas.itemconfig(level_text, text=f"Level:
{levels[level]['level_name']}")

# Remove ball if it hits the bottom


elif ball_pos[3] >= 400:
canvas.delete(current_ball)
current_ball = None
game_over(username, level, score) # End game if a ball reaches
the bottom
return # Stop the game loop on game over

game_window.after(50, update_game)

drop_ball()
update_game()

# Game over and saving score


def game_over(username, level, score):
conn = sqlite3.connect(DB_NAME)
cursor = conn.cursor()
cursor.execute("INSERT INTO scores (username, score) VALUES (?, ?)",
(username, score))
conn.commit()
conn.close()

log_session(username, "Game Over", level, score)

game_over_popup(username, level, score)

# Display Game Over popup with Restart option


def game_over_popup(username, level, score):
popup = tk.Toplevel(root)
popup.title("Game Over")
popup.geometry("300x150")

9
tk.Label(popup, text=f"Game Over!\nLevel: {level}\nScore: {score}",
font=("Arial", 14)).pack(pady=10)

def restart_game():
popup.destroy()
log_session(username, "Restart", level, score)
open_game_window(username)

tk.Button(popup, text="Restart",
command=restart_game).pack(pady=5)
tk.Button(popup, text="Exit", command=popup.destroy).pack()

# Main login/register interface


root = tk.Tk()
root.title("Ball Catching Game Login")
root.geometry("300x200")

tk.Label(root, text="Username").pack()
entry_username = tk.Entry(root)
entry_username.pack()

tk.Label(root, text="Password").pack()
entry_password = tk.Entry(root, show="*")
entry_password.pack()

tk.Button(root, text="Login", command=login).pack()


tk.Button(root, text="Register", command=register).pack()

# Initialize the database (if not already created)


setup_database()

# Start the main loop


root.mainloop()

10
7) OUTPUT:

I. REGISTER/LOGIN DASHBOARD:

II. REGISTRATION AND LOGIN CONFIRMATION:

11
III. GAME DASHBOARD:

a. LEVEL 1: EASY

b. WHEN BALL TOUCHES THE CATCHER, SCORE GETS UPDATED:

12
c. LEVEL 2: MEDIUM

d. LEVEL 3: HARD

13
IV. GAME OVER DASHBOARD:

V. ALL USER DETAILS,RESULTS AND THEIR LOGIN TIMINGS ARE


STORED IN LOG FILE.

14
8) CONCLUSION:

The Ball Catching Game is a perfect blend of fun and learning. It provides an
engaging and interactive experience for players while also showcasing key programming
concepts. Built using Python, a graphical user interface, and database integration, the
game offers a reliable and entertaining platform for users and developers alike.

For players, the game is an exciting challenge that sharpens reflexes and decision-
making skills as they progress through increasingly difficult levels. Features like score
tracking, real-time progress display, and a restart option make the game more engaging
and easier to access.For developers, this project demonstrates how to combine essential
programming skills such as user authentication, database management, file handling, and
GUI design. It emphasizes the importance of writing clean, scalable code and focusing on
user-friendly design.

What makes this game stand out is its versatility—it’s not just about
entertainment but also practical application. With room for future enhancements, such as
power-ups, multiplayer options, or improved graphics, the game can easily evolve into
something even more exciting. In essence, the Ball Catching Game is a fantastic example
of how programming can be both educational and enjoyable.

9) REFERENCES:

i. SQLite Documentation
https://www.sqlite.org/docs.html
ii. Tkinter Documentation
https://docs.python.org/3/library/tkinter.html
iii. Random Module Documentation
https://docs.python.org/3/library/random.html
iv. Time Module Documentation
https://docs.python.org/3/library/time.html
v. Game Design Tutorials
https://www.geeksforgeeks.org/python-tkinter/

15

You might also like