0% found this document useful (0 votes)
24 views15 pages

Final Documentation Egg Capture

Uploaded by

munirmansuri210
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)
24 views15 pages

Final Documentation Egg Capture

Uploaded by

munirmansuri210
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/ 15

SSRCOLLEGEOFARTS,COMMERCE&SCIENCE

(AffiliatedtoSavitribaiPhulePuneUniversity)

Submittedtothepartial fulfilment of

S.Y.B.B.A. (COMPUTER APPLICATION)

2023-2024

PROJECT WORK

PROJECT TITLE

Egg Capture

Guided by: Submitted by:

Mr. Vishal Langaliya 1.Mihir Vishwakarma

2.Munir Mansuri
SSR COLLEGE OF ARTS, COMMERCE & SCIENCE

(AffiliatedtoUniversityofPune)Saily,

Silvassa– 396230, D&N.H.

CERTIFICATE

Thisisto certify that Mr. /Ms.

Of S.Y.B.B.A. (COMPUTER APPLICATION) SeatNo has

successfully completed his/her project work on the topic

in theyear2023 – 2024.

In-charge H.O.D.

Internal Seal of the College External

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.

what is an egg catcher game?

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.

Steps involved in an egg catcher game?

firstly, we have to create new eggs.

Secondly, we have to check if the catcher has caught an egg.

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 import these modules.

from itertools import cycle

from random import randrange

See also Email Validation Using Python Regex module

from tkinter import Canvas, Tk, messagebox, font

from itertools import


cycle
1 from random import
2 randrange
3 from tkinter import
Canvas, Tk,
messagebox, font
we have to set the height and width for the rectangle shape we can create this
rectangle with the help of the canvas method in Tkinter.

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”)

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 = []
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.

1.create_egg(): we use this function t create eggs.

2.move_eggs(): we use this function to move the eggs.

3.egg_dropped(egg): This function is used to remove and delete the eggs.

4. lose_a_life(): This function tells us how many remaining lives are left to play the
game.

See also CARD GAME | PYTHON

5. check_catch(): This function is used to check the no. of catches.

6.increase_score(points): This function is used to tell us how much we scored.

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:

Here is the complete source code for the project.


1 from itertools import cycle
2 from random import randrange
3 from tkinter import Canvas, Tk, messagebox, font
4 canvas_width = 800
5 canvas_height = 400
6 root = Tk()
7 root.title("Egg Catcher")
8 c = Canvas(root, width=canvas_width,
9 height=canvas_height, background="deep sky
10 blue")
11 c.create_rectangle(-5, canvas_height-100,
12 canvas_width+5, canvas_height+5, fill="sea
13 green", width=0)
14 c.create_oval(-80, -80, 120, 120, fill='orange',
15 width=0)
16 c.pack()
17
18 color_cycle = cycle(["light blue", "light green",
19 "light pink", "light yellow", "light cyan"])
20 egg_width = 45
21 egg_height = 55
22 egg_score = 10
23 egg_speed = 500
24 egg_interval = 4000
25 difficulty = 0.95
26 catcher_color = "blue"
27 catcher_width = 100
28 catcher_height = 100
29 catcher_startx = canvas_width / 2 -
30 catcher_width / 2
31 catcher_starty = canvas_height - catcher_height -
32 20
33 catcher_startx2 = catcher_startx + catcher_width
34 catcher_starty2 = catcher_starty + catcher_height
35
36 catcher = c.create_arc(catcher_startx,
37 catcher_starty, catcher_startx2, catcher_starty2,
38 start=200, extent=140, style="arc",
39 outline=catcher_color, width=3)
40 game_font = font.nametofont("TkFixedFont")
41 game_font.config(size=18)
42
43
44 score = 0
45 score_text = c.create_text(10, 10, anchor="nw",
46 font=game_font, fill="darkblue", text="Score: "+
47 str(score))
48
49 lives_remaining = 3
50 lives_text = c.create_text(canvas_width-10, 10,
51 anchor="ne" font=game font fill="darkblue"
Output:

In this way, we can run the code.

See also Language Translator | Python


After running the above-given command you will get a new window opened and the
egg catcher game will be started in that window.

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.

Successfully we made an egg catcher game using python.

You might also like