Professional Documents
Culture Documents
Egg Hunt
Egg Hunt
INTRODUCTION
1.1. OBJECTIVE
Capacity : 120GB
OS : Windows 10
Server : Xampp
3.3.1. PHP
Additionally, PHP can be used for many programming tasks outside the web
context, such as standalone graphical applications and robotic drone control. PHP code can
also be directly executed from the command line.
The standard PHP interpreter, powered by the Zend Engine, is free software released
under the PHP License. PHP has been widely ported and can be deployed on most web
servers on a variety of operating systems and platforms.
3.3.2. MYSQL
One of MySQL's key strengths is its adherence to the SQL (Structured Query
Language) standard, making it easy for developers to interact with databases using a
familiar syntax. It supports various data types, including integers, strings, dates, and more,
allowing for the efficient storage and manipulation of diverse data.
MySQL operates on a client-server model where the database server handles data
storage, retrieval, and management tasks. It facilitates concurrent access to the database,
ensuring scalability and responsiveness for applications with numerous users.
MySQL has found widespread adoption across industries, from small-scale projects
to large enterprises. It has become an integral component of many content management
systems (CMS), e-commerce platforms, and custom-built web applications. With a vibrant
community of developers and a commitment to open-source principles, MySQL continues
to evolve, ensuring its relevance in the ever-changing landscape of data management.
3.3.3. WAMP SERVER
At the core of WampServer is the Apache HTTP Server, a robust and widely used
web server that handles the processing of HTTP requests. This, coupled with MySQL, a
powerful relational database management system, forms the backbone for storing and
retrieving data in web applications. Additionally, Wamp includes PHP, Python, or Perl,
scripting languages that enable the development of dynamic and interactive web pages.
PHP
Supports a wide range of operating systems, including Windows, Linux, Unix, and
macOS.
Wamp Server
A software stack for Windows operating system that includes Apache web server,
MySQL database management system, and PHP scripting language.
Enables developers to set up a local web server environment quickly without the
need for separate installations of Apache, MySQL, and PHP.
Ideal for beginners and experienced developers alike for local web development
and testing purposes.
2. SYSTEM DESIGN
This makes working with Anaconda accessible and easy. Just go to the
website and download the distribution. It provides a single download and an install
program/script that installs all the packages in one go. Alternatively, one can install
Python first and then individually install all the required packages using pip.
Additionally, it provides its own package manager (conda) and package repository.
But it allows installation of packages from PyPI using pip if the package is not in
Anaconda repositories. It is especially good if you are installing on Microsoft
Windows as it can easily install packages that would otherwise require you to install
C/C++ compilers and libraries if you were using pip. It is certainly an added
advantage that conda, in addition to being a package manager, is also a virtual
environment manager allowing you to install independent development environments
and switch from one to the other (similar to virtualenv). There is a minimal Anaconda
Python without all the packages, called Miniconda. After installing miniconda, you
can use conda and install only those scientific packages that you wish and avoid a
bloated installation.
16
3.3.3. ANACONDA NAVIGATOR
JupyterLab
Jupyter Notebook
QiConsole
Spyder
Glue
Orange
Rstudio
Visual Studio code
17
3.3.5. SPYDER
3.3.6. FEATURES
18
A Help pane able to retrieve and render rich text documentation on
functions, classes and methods automatically or on-demand.
A debugger linked to IPdb, for step-by-step execution
Static code analysis, powered by Pylint
A run-time Profiler, to benchmark code
Project support, allowing work on multiple development efforts
simultaneously
A built-in file explorer, for interacting with the filesystem and
managing projects
A "Find in Files" feature, allowing full regular expression search
over a specified scope An online help browser, allowing users to
search and view Python and package documentation inside the IDE
A history log, recording every user command entered in each
console An internal console, allowing for introspection and control
over Spyder's own operation.
19
3.4. PACKAGES
3.4.1. NumPy
NumPy is the primary tool for scientific computing in Python. It combines the
flexibility and simplicity of Python with the speed of languages like C and Fortran.
With NumPy, you are getting the computational power of compiled code, while using
accessible Python syntax. No wonder that there is a huge ecosystem of Python
packages and libraries drawing on the power of NumPy.
3.4.2. pandas
If you work with tabular, time series, or matrix data, pandas is your go-to
Python package. It is known as a fast, efficient, and easy-to-use tool for data analysis
and manipulation. It works with data frame objects; a data frame is a dedicated
structure for two-dimensional data. Data frames have rows and columns just like
database tables or Excel spreadsheets.
3.4.3. Matplotlib
Matplotlib is the most common data exploration and visualization library. You
can use it to create basic graphs like line plots, histograms, scatter plots, bar charts,
and pie charts. You can also create animated and interactive visualizations with this
library. Matplotlib is the foundation of every other visualization library.The library
offers a great deal of flexibility with regards to formatting and styling plots.
3.4.4. Seaborn
3.4.5. scikit-learn
20
3.4.6. Requests
This library is designed to make HTTP requests with Python more responsive
and user friendly. The intuitive JSON method offered by Requests helps you avoid
manually adding query strings to URLs.
3.4.7. urllib3
urllib3 is another user-friendly http client for Python. It is currently the most
downloaded pypi package, and it powers Requests and some other popular Python
packages. urllib3 provides many critical features missing from the standard libraries
are Thread safety,Connection pooling.
3.4.8. NLTK
Natural Language Toolkit (NLTK) is one of the leading Python platforms for
processing language data. It is a set of language processing libraries and programs that
provide a toolkit for Classification are Tokenization,Stemming,Tagging.
3.4.9. Pillow
If you work with image data, make sure to check out the Pillow package. It is
a fork of PIL (Python Image Library) that developed into an easy-to-use and efficient
tool for image manipulation in Python.
3.4.10. pytest
This package provides a variety of modules for testing new code, including
small unit tests and complex functional tests for applications and libraries.
21
3. SYSTEM DESIGN
def game_play():
minion_image = pygame.image.load(os.path.join(IMAGE_PATH,
'small_minion.jpg'))
basket_image = pygame.image.load(os.path.join(IMAGE_PATH,
'small_basket.jpg'))
egg_images_raw = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.gif', '8.jpg',
'9.jpg', 'bomb.png']
egg_images = [os.path.join(IMAGE_PATH, i) for i in egg_images_raw]
bomb_image = pygame.image.load(egg_images[9])
basket = pygame.image.load(os.path.join(IMAGE_PATH, 'small_basket.jpg'))
minion = pygame.image.load(egg_images[7])
explosion = pygame.image.load(os.path.join(IMAGE_PATH, 'explosion.gif'))
22
When instructions button was clicked, it displays the rules of the game. When best
score clicked, the highest score will be display.
# Initialising a boolean variable user_click to False to keep track of the user clicking
any button in the main menu
user_clicked = False
# Boolean variables to keep track which button the user taps on the main menu
# Whether it is the:
# 1. Play now button
play_clicked = False
# 2. Instructions button
instruction_clicked = False
# 3. Best Scores button
best_scores_clicked = False
# Intialising game over variable.
game_over = False
# Main Menu with 3 Buttons
# Setting white background to the game window
gameDisplay.fill((255, 255, 255))
# The Title moving up and positioning itself in the required co-ordinates.
for i in range(display_height + 100, 14, -10):
setText("Egg Hunt!", 140, (display_width / 2 - 350, i), (225, 10, 20), (255, 255,
255), "Algerian")
pygame.time.wait(5)
23
basket_y = display_height - 270
# For changing the X co-ordinate of the basket when appropriate keys are pressed.
x_change = 0
# Random positions for eggs
x = random.randint(0, display_width - 250)
y = -150
# Randomly loading Egg images
random_images = egg_images[random.randint(0, 9)]
random_eggs = pygame.image.load(random_images)
24
4.2. DIAGRAM
25
4.2.3. SEQUENCE DIAGRAM
26
4. TESTING
27
5.1. TEST CASES
28
Check in Landscape/Portrait mode.
Check scrolling.
Performance Check other objects too (ex -if its a car race- you
need to look at road, people, other objects like
buildings etc).
Check for localization Check the game when device memory is low.
At first we need to add login details while entering the game. After displaying
the name, the game will start. At least, 2 players played the game, displaying the score
with name and congratulating for their score.
Add levels to the game, like set a target for each level makes an interest to the
player to play the game. At each level, set a timer to catch eggs by the repective
target. For example, if the target for level 1 is 20, the player should catch the eggs
within 15 seconds. Insert sounds while playing game to make it more interest.
30
7. CONCLUSION
The project entitled as Egg Hunt game to make the player focus on the eggs
while catching using the basket. When the bomb or minion is caught, it will be an end
of an event, so here the egg will be removed and the game has to adjust the score by
increasing the score if the egg was caught in the basket. The end of an event occurs
when the egg is caught or dropped. As a result, the egg will be withdrawn, and the
game will adjust the score, either boosting it if the egg was caught in the basket or
decreasing it if the egg was dropped.
31
8. APPENDIX
8.1. CODING
game.py
# importing various modules required especially pygame.
import pygame
import sys
import time
import random
import os
# Initializing pygame.
pygame.init()
# Initializing the width and height of the window to be 680 and 1250 pixels
respectively.
display_height = 700
display_width = 1280
32
# Defining setText() function to display text to the screen which requires six
parameters to be supplied while calling it:
# 1. The text to be displayed.
# 2. The font size.
# 3. The position in terms of X and Y coordinates in pixles where the text is to be
displayed.
# 4. The background color which defaults to None if nothing are supplied.
# 6. The font type / font-family as string enclosed within double quotations which
defaults to Times New Roman.
def file_open_read():
f = open(os.path.join(RESOURCE_PATH, 'File', 'high_score.txt'), 'r')
best_score = f.read()
return f, best_score
def file_close(file):
file.close()
basket_image = pygame.image.load(os.path.join(IMAGE_PATH,
'small_basket.jpg'))
bomb_image = pygame.image.load(egg_images[9])
minion = pygame.image.load(egg_images[7])
# Initializing the speed variable which denotes the speed with which the images
move.
image_speed = 3
34
# Boolean variables to keep track which button the user taps on the main menu
# Whether it is the:
# 2. Instructions button
instruction_clicked = False
# Underlines
pygame.draw.line(gameDisplay, (125, 20, 220), (display_width / 2 - 340, 165),
(display_width / 2 + 330, 165))
pygame.draw.line(gameDisplay, (25, 120, 220), (display_width / 2 - 340, 168),
(display_width / 2 + 330, 168))
pygame.draw.line(gameDisplay, (220, 20, 125), (display_width / 2 - 340, 170),
(display_width / 2 + 330, 170))
35
pygame.time.wait(1000)
start = display_height + 40
end = 299
value = 0
time.sleep(1)
# Play Button
pygame.draw.rect(gameDisplay, (225, 10, 20), (display_width / 2 - 100, 260, 230,
100))
time.sleep(1)
# Instructions Button
pygame.draw.rect(gameDisplay, (30, 220, 20), (display_width / 2 - 200, 400, 440,
100))
time.sleep(1)
# Best Scores Button
36
pygame.draw.rect(gameDisplay, (30, 22, 240), (display_width / 2 - 200, 540, 440,
100))
pygame.display.update()
# (Event Loop) Keyboard and Mouse events (Checking whether the user had
clicked any button)
for event in pygame.event.get():
# Retrieving the mouse co-ordinates (Returns a list with 2 elements i,e X and
Y co-ordinates)
mouse_cord = pygame.mouse.get_pos()
# Checking whether the close button was tapped and if so terminate the
program!
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
else:
pygame.draw.rect(gameDisplay, (225, 10, 20), (display_width / 2 - 100,
260, 230, 100))
setText("Play !", 80, (530, 260), (255, 255, 255), None, "forte")
# Checking whether the user has clicked the Best scores button
if event.type == pygame.MOUSEBUTTONDOWN:
user_clicked = True
best_scores_clicked = True
38
else:
pygame.draw.rect(gameDisplay, (30, 22, 240), (display_width / 2 - 200,
540, 440, 100))
setText("Best Scores", 80, (450, 540), (255, 255, 255), None, "forte")
clock.tick(60)
# Instructions window
if instruction_clicked:
instruction_window = pygame.display.set_mode((display_width,
display_height))
pygame.display.set_caption('Instructions')
instruction_clock = pygame.time.Clock()
instruction_window.fill((69, 250, 245))
setText("1. Use left and right arrow keys to move the basket appropriately.", 45,
(40, 220), (255, 0, 0))
setText("2. Use down arrow key to stop the basket at that point.", 45, (40, 290),
(0, 185, 0))
setText("3. Collect as many eggs as you can with the basket.", 45, (40,360), (0,
0, 255))
39
setText("4. Avoid crashing with minions and bombs!", 45, (40, 430), (255, 0, 0))
while instruction_clicked:
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
instruction_clicked = False
game_play()
else:
40
pygame.draw.rect(instruction_window, (0, 128, 255), (display_width / 2 -
180, 560, 160, 80))
setText("High Score", 120, (display_width / 2 - 320, 50), (125, 20, 220), None,
"Elephant")
pygame.draw.line(score_window, (255, 0, 0), (display_width / 2 - 320, 180),
(display_width / 2 + 340, 180), 5)
pygame.draw.line(score_window, (0, 255, 0), (display_width / 2 - 320, 185),
(display_width / 2 + 340, 185), 5)
pygame.draw.line(score_window, (0, 0, 255), (display_width / 2 - 320, 190),
(display_width / 2 + 340, 190), 5)
while best_scores_clicked:
41
for event in pygame.event.get():
mouse_position = pygame.mouse.get_pos()
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
best_scores_clicked = False
game_play()
else:
pygame.draw.rect(score_window, (212, 108, 3), (display_width / 2 - 130,
display_height / 2 + 160, 300, 130))
pygame.display.update()
score_clock.tick(30)
# New game window is created on clicking the play button with the same
dimensions.
play_window = pygame.display.set_mode((1250, 680))
pygame.display.set_caption('Play')
play_window.fill((255, 255, 255))
play_clock = pygame.time.Clock()
# Event handling
43
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.key == pygame.K_RIGHT:
x_change = unit
basket_x += x_change
y += image_speed
44
# Checking whether the current score is greater than the best score.
file, current_best_score = file_open_read()
file_close(file)
time.sleep(3)
time.sleep(2)
game_over = True
play_clicked = False
# Increasing the speed in which the basket moves both the directions.
if unit != 15:
unit += 1
46
pygame.display.update()
play_clock.tick(60)
game_over_window = pygame.display.set_mode((display_width,
display_height))
pygame.display.set_caption("Game Over Buddy!")
game_over_clock = pygame.time.Clock()
game_over_window.fill((188, 7, 116))
while game_over:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
mouse = pygame.mouse.get_pos()
if display_width / 2 + 220 > mouse[0] > display_width / 2 - 200 and 510 >
mouse[1] > 420:
pygame.draw.rect(game_over_window, (128, 128, 255), (display_width /
2 - 200, 420, 420, 90))
setText("Back to Main Menu", 50, (display_width / 2 - 190, 430), (255,
0, 0))
if event.type == pygame.MOUSEBUTTONDOWN:
game_over = False
game_play()
else:
48
pygame.draw.rect(game_over_window, (244, 122, 11), (display_width / 2
- 200, 420, 420, 90))
setText("Back to Main Menu", 50, (display_width / 2 - 190, 430), (255,
255, 255))
if event.type == pygame.MOUSEBUTTONDOWN:
credit_clicked = True
game_over = False
else:
pygame.draw.rect(game_over_window, (255, 255, 128), (display_width /
2 - 110, 540, 180, 95))
setText("Credits", 60, (display_width / 2 - 110, 550), (0, 128, 127), None,
"Forte")
pygame.display.update()
game_over_clock.tick(60)
if credit_clicked:
credits_window = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption("CREDITS")
49
credits_clock = pygame.time.Clock()
pygame.time.wait(1000)
pygame.time.wait(1500)
pygame.time.wait(1500)
while credit_clicked:
50
if i >= 255:
i = 64
if j >=255:
j = 65
if k >=255:
k = 64
mouse_pos = pygame.mouse.get_pos()
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
credit_clicked = False
game_play()
else:
51
pygame.draw.rect(credits_window, (160, 0, 0), (display_width / 2 - 230,
display_height / 2 + 200, 470, 120))
setText("Play Again!", 80, (display_width / 2 - 205, display_height / 2 +
210), (0, 160, 0), None, "Forte")
i += random.randint(1, 10)
j += random.randint(1, 10)
k += random.randint(1, 10)
pygame.display.update()
credits_clock.tick(30)
if __name__ == '__main__':
game_play()
52
8.2. SCREENSHOTS
53
Fig 8.2.3. Bomb / Minion Crashed
54
Fig 8.2.5. Instuctions
55
Fig 8.2.7. Credits
56
9. REFERENCES
9.1. BOOKS
1. Learn Python the Hard Way: 3rd Edition
9.2. WEBSITES
1.
https://thecleverprogrammer.com
2.
https://www.sourcecodester.com
3.
https://inprogrammer.com
4.
https://coderspacket.com
5. https://www.geeksforgeeks.org
6.
https://www.codespeedy.com
57