Final Documentation Egg Capture
Final Documentation Egg Capture
(AffiliatedtoSavitribaiPhulePuneUniversity)
Submittedtothepartial fulfilment of
2023-2024
PROJECT WORK
PROJECT TITLE
Egg Capture
2.Munir Mansuri
SSR COLLEGE OF ARTS, COMMERCE & SCIENCE
(AffiliatedtoUniversityofPune)Saily,
CERTIFICATE
in theyear2023 – 2024.
In-charge H.O.D.
Examiner Examiner
INDEX :
❖ Introduction
❖ Outline
❖ Project Prerequisites
❖ Code Implementation
❖ Source Code
❖ Bibliopraphy
❖ Output
Introduction:
To create an eggs catcher game using Python, our first step will be to design a ground,
basket, and eggs.
Eggs Catcher is a classic game where the goal is to catch as many eggs as possible.
whenever we catch an egg then our score increases and if we miss three eggs then we
will lose the game.
Thirdly, we have to move eggs and check if the eggs touched the ground
Outline:
To run this code we need to import three modules. we can simply create this game we
have to know a little bit about the usage of these modules in this code.
Project Prerequisites:
1. tkinter:
It is a module in Python, it is used and the most basic GUI framework is used in python
programming. tkinter provides a powerful object-oriented interface to the Tk GUI
toolkit.
2. Itertools:
It is a module in Python, it is used to iterate over data structures that can be stepped
over using a for-loop. Such data structures are also known as iterables. This module
works as a fast, memory-efficient tool that is used either by itself or in combination to
form iterator algebra.
3. random:
It is a module in Python,randint(), which Returns a random number between the given
range; choice(), which Returns a random element from the given sequence.
Code Implementation:
In this way, we have to set the height and weight of the egg.
canvas_width = 800
canvas_height = 400
root = Tk()
root.title(“Egg Catcher”)
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
game_font = font.nametofont(“TkFixedFont”)
game_font.config(size=18)
score = 0
eggs = []
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)
1 c.create_oval(-80, -80, 120, 120, fill='orange',
2 width=0)
3 c.pack()
4
5 color_cycle = cycle(["light blue", "light green",
6 "light pink", "light yellow", "light cyan"])
7 egg_width = 45
8 egg_height = 55
9 egg_score = 10
10 egg_speed = 500
11 egg_interval = 4000
12 difficulty = 0.95
13 catcher_color = "blue"
14 catcher_width = 100
15 catcher_height = 100
16 catcher_startx = canvas_width / 2 -
17 catcher_width / 2
18 catcher_starty = canvas_height - catcher_height -
19 20
20 catcher_startx2 = catcher_startx + catcher_width
21 catcher_starty2 = catcher_starty +
22 catcher_height
23
24 catcher = c.create_arc(catcher_startx,
25 catcher_starty, catcher_startx2, catcher_starty2,
26 start=200, extent=140, style="arc",
27 outline=catcher_color, width=3)
28 game_font = font.nametofont("TkFixedFont")
29 game_font.config(size=18)
30
31
32 score = 0
33 score_text = c.create_text(10, 10, anchor="nw",
34 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 = []
Here, we define eight different functions.
4. lose_a_life(): This function tells us how many remaining lives are left to play the
game.
7.move_left(event): This function is used to move the basket to the left side.
8.move_right(event): This function is used to move the basket to the left side.
1 def create_egg():
2 x = randrange(10, 740)
3 y = 40
4 new_egg = c.create_oval(x,
5 y, x+egg_width, y+egg_height,
6 fill=next(color_cycle),
7 width=0)
8 eggs.append(new_egg)
9 root.after(egg_interval,
10 create_egg)
11
12 def move_eggs():
13 for egg in eggs:
14 (eggx, eggy, eggx2,
15 eggy2) = c.coords(egg)
16 c.move(egg, 0, 10)
17 if eggy2 > canvas_height:
18 egg_dropped(egg)
19 root.after(egg_speed,
20 move_eggs)
21
22 def egg_dropped(egg):
23 eggs.remove(egg)
24 c.delete(egg)
25 lose_a_life()
26 if lives_remaining == 0:
27 messagebox.showinfo("
28 Game Over!", "Final Score: "+
29 str(score))
30 root.destroy()
31
32 def lose_a_life():
33 global lives_remaining
34 lives_remaining -= 1
35 c.itemconfigure(lives_text,
36 text="Lives: "+
37 str(lives_remaining))
38
39 def check_catch():
40 (catcherx, catchery,
41 catcherx2, catchery2) =
42 c.coords(catcher)
43 for egg in eggs:
44 (eggx, eggy, eggx2,
45 eggy2) = c.coords(egg)
46 if catcherx < eggx and
47 eggx2 < catcherx2 and
48 catchery2 - eggy2 < 40:
49 eggs.remove(egg)
50 c.delete(egg)
51 increase score(egg sc
Source Code:
This is the output of the code. we can see there is an egg coming toward the ground
and there is a blue u-shaped basket. now we have to catch the egg into the basket by
moving toward the left and right using the left arrow key and right arrow key.
this is the final score we get after using three lives. here is my final score.I scored 130.