0% found this document useful (0 votes)
2 views

CS Project?

The document certifies that Harshvardhan Dange completed a Python project for the Egg Catcher game as part of the Computer Science curriculum at PM SHRI KENDRIYA VIDYALAYA. The game involves catching falling eggs, with increasing difficulty as the player progresses, and utilizes Python libraries such as Tkinter for graphics. The document includes acknowledgments, system specifications, modules used, functions, and the complete source code for the project.

Uploaded by

harshvardhan3139
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

CS Project?

The document certifies that Harshvardhan Dange completed a Python project for the Egg Catcher game as part of the Computer Science curriculum at PM SHRI KENDRIYA VIDYALAYA. The game involves catching falling eggs, with increasing difficulty as the player progresses, and utilizes Python libraries such as Tkinter for graphics. The document includes acknowledgments, system specifications, modules used, functions, and the complete source code for the project.

Uploaded by

harshvardhan3139
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

PM SHRI KENDRIYA

VIDYALAYA INS HAMLA


------------------------------
TOPIC:- TO DEVELOP A GAME IN
PYTHON
---------------------------------------
NAME:-
ROLL NO.:-
CLASS:-
Certificate of completion
This is to certify that Harshvardhan Dange, a student of PM SHRI KENDRIYA VIDYALAYA, has
successfully completed this project as part of the Computer Science curriculum for the academic year
2024-25.

This project has been completed under the guidance of SAVITA MAM, and it adheres to the prescribed
requirements of the subject.

Signature of Guide SIGNATURE OF STUDENT SIGNATURE OF PRINCIPAL

SAVITA SHARMA
Date:
ACKNOWLEDGEMENT
I would like to express my sincere gratitude to SAVITA MAM, my Computer Science teacher,
for their invaluable guidance, encouragement, and support throughout the completion of this
project.

I am also thankful to my school, PM SHRI KENDRIYA VIDYALAYA INS HAMLA, for providing
the necessary resources and a conducive environment for learning and developing this
project. Additionally, I extend my gratitude to my classmates, family, and friends for their
support and motivation.

This project would not have been possible without the collective assistance of everyone
mentioned above. Thank you all!

Name: HARSHVARDHAN DANGE


Class:11-A
Date: 14/02/2025
INDEX
● INTRODUCTION
● PROJECT DESCRIPTION
● SYSTEM REQUIREMENTS
● MODULES USED IN THE PROJECT
● FUNCTIONS USED IN THE PROJECT
● PROJECT CODE
● OUTPUT
Quick Introduction to Python
Python is a high-level, interpreted programming language known for its
simplicity and readability. It is widely used in web development, data
science, AI, automation, and more.
Why Python?
✅ Easy to learn and use
✅ Large community and support
✅ Cross-platform compatibility
✅ Extensive libraries and frameworks
🎮 Egg Catcher Game 🥚
🔹 Description: A fun arcade game where the player catches falling eggs using a basket.
Avoid dropping eggs to keep the game going!

🔹 How to Play:
✔ Move left (←) and right (→) to catch eggs.
✔ Each caught egg = +10 points.
✔ Dropping an egg loses a life (3 lives total).
✔ Game gets harder as speed increases.

🔹 Tech Used:
✅ Python (Game Logic)
✅ Tkinter (Graphics & UI)
✅ Random & Itertools (Egg behavior)

🚀 Survive, score high, and have fun!


System specifications
Device name: Avita-Laptop1

Processor: AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx 2.10
GHz

Installed RAM: 8.00 GB (6.95 GB usable)

Device ID: 8F95FD11-740A-44C8-A167-EDB1700D0451

Product ID: 00356-22017-00250-AAOEM

System type: 64-bit operating system, x64-based processor


Modules used in the code
1. itertools – Specifically, cycle is used to cycle through different colors for
the falling eggs.
2. random – The randrange function is used to randomly position eggs when
they are created.
3. tkinter –
● Tk for creating the game window.
● Canvas for drawing the game elements like the catcher and eggs.
● messagebox for displaying the "Game Over" message.
● font for customizing the text (score and lives display).
Functions used in the program
1. create_egg()

● Creates a new egg at a random position.


● Appends the egg to the eggs list.
● Calls itself recursively after egg_interval milliseconds.

2. move_eggs()

● Moves all eggs downward by 10 pixels.


● Checks if any egg has fallen off the screen (eggy2 > canvas_height).
● If an egg falls, it calls egg_dropped().
● Runs recursively every egg_speed milliseconds.

3. egg_dropped(egg)

● Removes the fallen egg from the list and deletes it from the canvas.
● Calls lose_a_life().
● If lives_remaining == 0, it shows a Game Over message and closes the game.
4. lose_a_life() 7. move_left(event)

● Decreases the lives_remaining counter. ● Moves the catcher left by 20 pixels.


● Updates the "Lives" text on the screen. ● Ensures the catcher does not go out
of bounds.

5. check_catch()
8. move_right(event)
● Checks if an egg is caught by the catcher.
● If the egg is within the catcher's range, it: ● Moves the catcher right by 20 pixels.
○ Removes the egg. ● Ensures the catcher does not go out
○ Calls increase_score(). of bounds.
● Runs every 100 milliseconds.

6. increase_score(points)

● Increases the score by the given points.


● Updates the speed of the falling eggs (egg_speed) and
spawn rate (egg_interval) to make the game harder
Programs required for that code
1. Python (Mandatory)

● You must have Python 3.x installed.


● You can download it from: https://www.python.org/downloads/

2. Tkinter (Built-in in Python)

● tkinter is included with Python's standard library, so you don't need to install it separately.

To check if tkinter is installed, run:


sh
CopyEdit
python -m tkinter

● If a window opens, it means tkinter is installed.


3. Code Editor (Optional)

● You can write and run the program in:


○ IDLE (Comes with Python)
○ VS Code (Recommended)
○ PyCharm
○ Any other Python IDE
Source code
from itertools import cycle
from random import randrange
from tkinter import Canvas, Tk, messagebox, font

canvas_width = 800
canvas_height = 400

root = Tk()
root.title("Egg Catcher")
c = Canvas(root, width=canvas_width, height=canvas_height, background="deep sky
blue")
c.create_rectangle(-5, canvas_height-100, canvas_width+5, canvas_height+5, fill="sea
green", width=0)
c.create_oval(-80, -80, 120, 120, fill='orange', width=0)
c.pack()
color_cycle = cycle(["light blue", "light green", "light pink", "light yellow", "light cyan"])
egg_width = 45
egg_height = 55
egg_score = 10
egg_speed = 500
egg_interval = 4000
difficulty = 0.95
catcher_color = "blue"
catcher_width = 100
catcher_height = 100
catcher_startx = canvas_width / 2 - catcher_width / 2
catcher_starty = canvas_height - catcher_height - 20
catcher_startx2 = catcher_startx + catcher_width
catcher_starty2 = catcher_starty + catcher_height

catcher = c.create_arc(catcher_startx, catcher_starty, catcher_startx2, catcher_starty2,


start=200, extent=140, style="arc", outline=catcher_color, width=3)
game_font = font.nametofont("TkFixedFont")
game_font.config(size=18)
score = 0
score_text = c.create_text(10, 10, anchor="nw", font=game_font, fill="darkblue",
text="Score: "+ str(score))

lives_remaining = 3
lives_text = c.create_text(canvas_width-10, 10, anchor="ne", font=game_font,
fill="darkblue", text="Lives: "+ str(lives_remaining))

eggs = []

def create_egg():
x = randrange(10, 740)
y = 40
new_egg = c.create_oval(x, y, x+egg_width, y+egg_height, fill=next(color_cycle),
width=0)
eggs.append(new_egg)
root.after(egg_interval, create_egg)
def move_eggs():
for egg in eggs:
(eggx, eggy, eggx2, eggy2) = c.coords(egg)
c.move(egg, 0, 10)
if eggy2 > canvas_height:
egg_dropped(egg)
root.after(egg_speed, move_eggs)

def egg_dropped(egg):
eggs.remove(egg)
c.delete(egg)
lose_a_life()
if lives_remaining == 0:
messagebox.showinfo("Game Over!", "Final Score: "+ str(score))
root.destroy()
def lose_a_life():
global lives_remaining
lives_remaining -= 1
c.itemconfigure(lives_text, text="Lives: "+ str(lives_remaining))

def check_catch():
(catcherx, catchery, catcherx2, catchery2) = c.coords(catcher)
for egg in eggs:
(eggx, eggy, eggx2, eggy2) = c.coords(egg)
if catcherx < eggx and eggx2 < catcherx2 and catchery2 - eggy2 < 40:
eggs.remove(egg)
c.delete(egg)
increase_score(egg_score)
root.after(100, check_catch)
def increase_score(points):
global score, egg_speed, egg_interval
score += points
egg_speed = int(egg_speed * difficulty)
egg_interval = int(egg_interval * difficulty)
c.itemconfigure(score_text, text="Score: "+ str(score))

def move_left(event):
(x1, y1, x2, y2) = c.coords(catcher)
if x1 > 0:
c.move(catcher, -20, 0)

def move_right(event):
(x1, y1, x2, y2) = c.coords(catcher)
if x2 < canvas_width:
c.move(catcher, 20, 0)
c.bind("<Left>", move_left)
c.bind("<Right>", move_right)
c.focus_set()
root.after(1000, create_egg)
root.after(1000, move_eggs)
root.after(1000, check_catch)
root.mainloop()
Final Output
If we miss three
eggs then game
overs and we have
to re-run it

You might also like