Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 57

1.

INTRODUCTION

1.1. OBJECTIVE

The management of old age homes is a multifaceted endeavor, encompassing


the coordination of resident care, staff scheduling, facility maintenance, financial oversight,
and communication with families. An Old Age Home Management System (OAHMS)
serves as the backbone of these operations, providing administrators with a centralized
platform to streamline administrative tasks and optimize the quality of care provided to
elderly residents. By leveraging technology to automate processes, track vital information,
and facilitate communication, OAHMS enhances efficiency, improves resident satisfaction,
and ensures a safe and supportive environment for seniors in their later years.

The objective of developing an Old Age Home Management System (OAHMS) is


to create a comprehensive and efficient platform that addresses the unique needs and
challenges of managing elderly care facilities. The system aims to streamline administrative
processes, optimize resource allocation, enhance communication between residents, staff,
and families, and ultimately improve the quality of care provided to elderly residents. By
centralizing data management, automating routine tasks, and providing valuable insights
through analytics, OAHMS seeks to empower administrators and caregivers to deliver
personalized and compassionate care while promoting the safety, well-being, and dignity of
elderly residents.
2. SYSTEM ANALYSIS

2.1. EXISTING SYSTEM

Existing old age home management systems encompass a range of functionalities to


efficiently manage the facility's operations. They typically integrate resident management,
staff scheduling, and medical record-keeping. These systems help maintain comprehensive
resident profiles, including medical histories and dietary preferences. Staff management
features enable the scheduling of shifts, tracking of training records, and performance
evaluations. Medical records management ensures secure storage of sensitive information
and compliance with healthcare regulations. Additionally, these systems facilitate facility
maintenance by managing repair requests and inventory. Billing and invoicing
functionalities streamline financial transactions, while communication tools enhance
interaction among residents, staff, and families. Reporting functionalities provide insights
into occupancy rates, staff productivity, and resident satisfaction, contributing to the overall
quality of care provided.

2.2. PROPOSED SYSTEM


A proposed old age home management system would integrate advanced features
to streamline operations and enhance resident care. It would include comprehensive resident
management capabilities, allowing for the tracking of demographics, medical histories, care
plans, and preferences. The system would feature intelligent scheduling algorithms for
efficient staff management, ensuring optimal coverage while considering staff skills and
availability.

 Inventory management: Monitoring and ordering supplies such as medication,


food, and hygiene products.
 Reporting: Generating reports on various aspects of the facility's operations,
such as occupancy rates, financial performance, and resident satisfaction
surveys.
 Billing and invoicing: Generating bills for residents' accommodation, meals,
and additional services.
 Integration with healthcare providers: Streamlining communication and
information sharing with external healthcare providers for residents' medical
needs.
3. TECHNICAL SPECIFICATION

3.1. HARDWARE REQUIREMENTS

Processor : AMD PRO A4-4350B R4

Processor Speed : 2.5GHz

RAM : 4.00 GB (3.84 GB usable)

RAM Capacity : 4.00 GB Hard disk

Capacity : 120GB

3.2. SOFTWARE REQUIREMENTS

OS : Windows 10

Front End : PHP

Back End : My SQL

Server : Xampp

3.3. SOFTWARE SPECIFICATION

3.3.1. PHP

PHP is a widely-used open source general-purpose scripting language that is


especially suited for web development and can be embedded into HTML. It was originally
created by Danish-Canadian Programmer Rasmus Lerdorf in 1993 and released in 1995.
PHP was originally an abbreviation of Personal Home Page but it now stands for
the recursive initialisim PHP: Hypertext Preprocessor. It is a server-side scripting
language. It is open-source which means it is free to download and use. It is very simple to
learn and use. The files have the extension “.php”.

PHP code is usually processed on a web server by a PHP interpreter implemented as


a module, a daemon or a Common Gateway Interface (CGI) executable. On a web server,
the result of the interpreted and executed PHP code which may be any type of data, such as
generated HTML or binary image data would form the whole or part of an HTTP response.
Various web template systems, web content management systems, and web
frameworks exist that can be employed to orchestrate or facilitate the generation of that
response.

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.

Fig 3.3.1 PHP

3.3.2. MYSQL

MySQL is a popular open-source relational database management system (RDBMS)


that plays a pivotal role in the storage and retrieval of structured data. Originally developed
by MySQL AB, it is now owned by Oracle Corporation. As one of the most widely used
databases, MySQL is integral to the development of dynamic and data-driven web
applications.

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.

Security is a paramount concern in database management, and MySQL addresses


this through robust authentication mechanisms, user privileges, and encryption options. It
supports both traditional username-password authentication and more advanced methods
like SSL/TLS for encrypted connections.

Fig 3.3.2. My SQL

Furthermore, MySQL excels in performance optimization. It incorporates features


such as indexing, caching, and query optimization, ensuring that database queries are
executed with speed and efficiency. The ability to handle large datasets and perform
complex queries makes it suitable for a wide range of applications.

MySQL's versatility is evident in its compatibility with various operating systems,


including Linux, Windows, and macOS. Additionally, it supports numerous programming
languages, fostering integration with popular web development technologies such as PHP,
Python, and Java.

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

WampServer, commonly referred to as Wamp, is an open-source software stack that


facilitates the seamless development and deployment of web applications on Windows
operating systems. The name "Wamp" is derived from the combination of Windows,
Apache, MySQL, and PHP/Python/Perl – the key components included in this stack. It
serves as a local server environment, providing developers with a platform to build and test
web applications before deploying them to a live 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.

Fig 3.3.3 Wamp Server

One of Wamp's significant advantages is its user-friendly installation process,


allowing developers to set up a local server environment effortlessly. Once installed, Wamp
provides a convenient control panel where users can start or stop the Apache server, manage
the MySQL database, and configure various settings. The inclusion of phpMyAdmin, a
web-based database administration tool, further simplifies the management of MySQL
databases.

WampServer is a valuable tool for developers working with content management


systems like WordPress, Joomla, or Drupal, as well as those engaged in custom web
application development. It facilitates a local testing environment that closely mirrors a live
server setup, reducing the likelihood of issues when transitioning from development to
production.
While Wamp is tailored for Windows environments, similar software stacks such as
LAMP (Linux, Apache, MySQL, PHP/Python/Perl) and MAMP (Macintosh, Apache,
MySQL, PHP/Python/Perl) cater to Linux and macOS, respectively. WampServer's ease of
use and comprehensive features make it a popular choice among developers seeking a local
server environment for efficient and effective web application development on Windows
systems.
3.3.4. FEATURES

PHP

 Server-side scripting language designed for web development.

 Simple and easy to learn syntax, similar to C, Java, and Perl.

 Supports a wide range of operating systems, including Windows, Linux, Unix, and
macOS.

 Integrates seamlessly with HTML for creating dynamic web pages.

 Offers a vast ecosystem of frameworks and libraries for rapid development,


including Laravel, Symfony, and CodeIgniter.

 Provides support for various databases, including MySQL, PostgreSQL, SQLite,


and more.

 Open-source and actively maintained with a large community of developers


contributing to its development.

Wamp Server

 A software stack for Windows operating system that includes Apache web server,
MySQL database management system, and PHP scripting language.

 Provides a convenient and easy-to-install environment for developing and testing


web applications on Windows.

 Enables developers to set up a local web server environment quickly without the
need for separate installations of Apache, MySQL, and PHP.

 Offers a user-friendly interface for managing Apache and MySQL services, as


well as configuring PHP settings.

 Ideal for beginners and experienced developers alike for local web development
and testing purposes.
2. SYSTEM DESIGN

4.1. MODULE DESCRIPTION

4.1.1. MODULE FOR USER


The user module within the old age home management system is designed to provide
residents and their families with seamless access to relevant uninformation and
communication channels. It includes features such as resident profile access, where
residents can review their personal details, medical records, and care plans, fostering greater
involvement in their own care journey. Family members are offered a dedicated portal
through which they can stay updated on their loved one's status, care plans, and facility
activities, as well as communicate with staff and other residents. An interactive activity
calendar allows users to participate in scheduled events and activities, with the option to
RSVP and receive reminders. Integrated messaging functionality enables secure
communication between residents, families, and staff, facilitating quick exchanges of
information and support. Additionally, users have the opportunity to provide feedback and
suggestions, contributing to ongoing improvements in service delivery. Access to essential
documents and external support resources further enhances the user experience, promoting
engagement, transparency, and a sense of community within the facility.

4.1.2. MODULE FOR ADMIN


3.3.2. ANACONDA IDE

Anaconda is an amazing collection of scientific Python packages, tools,


resources, and IDEs. This package includes many important tools that a Data Scientist
can use to harness the incredible force of Python. Anaconda individual edition is free
and open source.

Fig 3.1 Anaconda

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

Anaconda Navigator is a desktop graphical user interface included in


Anaconda distribution that allows user to launch applications and manage conda
packages, environments and channels without using command line commands.
Navigator can search for packages on Anaconda Cloud or in a local Anaconda
Repository, install them in an environment, run the packages and update them. It is
available for windows, MacOS and Linux. The following applications are available
by default in navigator

 JupyterLab
 Jupyter Notebook
 QiConsole
 Spyder
 Glue
 Orange
 Rstudio
 Visual Studio code

3.3.4. PACKAGES AVAILABLE IN ANACONDA

 Over 250 packages are automatically installed with Anaconda.


 Over 7,500 additional open-source packages (including R) can be
individually installed from the Anaconda repository with the conda install
command.
 Thousands of other packages are available from Anaconda Cloud.
 You can download other packages using the pip install command that is
installed with Anaconda. Pip packages provide many of the features of
conda packages and in some cases they can work together. However, the
preference should be to install the conda package if it is available.
 You can also make your own custom packages using the conda build
command, and you can share them with others by uploading them to
Anaconda Cloud, PyPI, or other repositories.

17
3.3.5. SPYDER

Spyder is an open source cross platform integrated development environment


(IDE) for scientific programming in the python language.

Fig 3.2 Spyder

Spyder, the Scientific Python Development Environment, is a free integrated


development environment (IDE) that is included with Anaconda. Spyder is a free and
open source scientific environment written in Python, for Python, and designed by
and for scientists, engineers and data analysts. It features a unique combination of the
advanced editing, analysis, debugging, and profiling functionality of a comprehensive
development tool with the data exploration, interactive execution, deep inspection,
and beautiful visualization capabilities of a scientific package.

Furthermore, Spyder offers built-in integration with many popular scientific


packages, including NumPy, SciPy, Pandas, IPython, QtConsole, Matplotlib, SymPy,
and more. Beyond its many built-in features, Spyder can be extended even further via
third-party plugins. Spyder can also be used as a PyQt5 extension library, allowing
you to build upon its functionality and embed its components, such as the interactive
console or advanced editor, in your own software. Spyder uses Qt for its GUI and is
designed to use either of the PyQt or PySide Python bindings. QtPy, a thin abstraction
layer developed by the Spyder project and later adopted by multiple other packages,
provides the flexibility to use either backend.

3.3.6. FEATURES

 An editor with syntax highlighting, introspection, code completion


 Support for multiple IPython consoles
 The ability to explore and edit variables from a GUI

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

Seaborn is a high-level interface for drawing attractive statistical graphics with


just a few lines of code

3.4.5. scikit-learn

Do you want to run a regression? Or maybe you have a data classification


problem? scikit-learn is an efficient and beginner-friendly tool for predictive data
analysis.

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

4.1. MODULE DESCRIPTION


4.1.1. MODULE TO LOAD IMAGES
Images of the eggs, basket, bomb, minion, explosion was loaded and make the
make the images move. If the bomb or minion fall in basket, the explosion image will
appear. Create a display surface object using display.set_mode() method of pygame.
Create a Image surface object i.e. surface object in which image is drawn on it,
using image.load() method of pygame. Copy the image surface object to the display
surface object using blit() method of pygame display surface object. Show the
display surface object on the pygame window using display.update() method of
pygame.

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

4.1.2. MODULE TO CREATE THE MAIN MENU

Functions in Pygame are a way to contain different menus or levels by


defining an event type in each function, then calling the functions from their
respective container function. Main menu of the game displays buttons play,
instructions and best score. When play button was clicked the game starts to play.

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)

4.1.3. MODULE TO MOVE THE EGG IMAGES


Images of basket and eggs were inserted and make them moves randomly.
The eggs were fall from sky randomly and basket will move to catch the egg by using
appropriate keys. The main concept of doing this is by changing the co-ordinates of
the object and refreshing the screen. When the screen refreshes every time window
color gets filled with original color and the new rectangle is formed, so when arrow
keys get pressed co-ordinates changes and it appears that the object is moving.

# X and Y co-ordinates of the basket.


basket_x = display_width / 2 - 200

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)

4.1.4. MODULE TO CONTROL THE MOVES OF THE BASKET


The basket image moves by using right and left arrow keys, and the down
arrow key is used to stop the basket move from the position. These three keys
handling the moving positions of the basket. K_LEFT is used to perform an action
when the left arrow is pressed on the keyboard, K_RIGHT is used to perform an
action when the right arrow is pressed on the keyboard and K_DOWN is used to
perform an action when the down arrow is pressed on the keyboard.

for event in pygame.event.get():


# Event handling
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
x_change = unit
elif event.key == pygame.K_LEFT:
x_change = -unit
elif event.key == pygame.K_DOWN:
x_change = 0
basket_x += x_change
y += image_speed
# Placing the Basket in position
play_window.blit(basket, (basket_x, basket_y))

24
4.2. DIAGRAM

4.2.1. DATAFLOW DIAGRAM

Fig 4.2.1 Dataflow Diagram of Egg Hunt Game

4.2.2. USECASE DIAGRAM

Fig 4.2.2 Usecase Diagram of Egg Hunt Game

25
4.2.3. SEQUENCE DIAGRAM

Fig 4.2.3 Sequence Diagram of Egg Hunt Game

4.2.4. ACTIVITY DIAGRAM

Fig 4.2.4 Activity Diagram of Egg Hunt Game

26
4. TESTING

27
5.1. TEST CASES

28
Check in Landscape/Portrait mode.

Check for animation, movement of character,


graphics, Zoom In/Out (all gestures) etc.

There should not be any clipping (cutted


background).

Test whether one object overlaps with another.

User Interface Verify if loading indicator is displayed wherever


required.

Character should not move out of the


screen/specified area.

Test for enable and disable images/ icons/ buttons


etc.

Check for screen title.

Check for message title, message description,


label (should be appropriate).

Check scrolling.

Font displayed (color, size etc).

Performance Check other objects too (ex -if its a car race- you
need to look at road, people, other objects like
buildings etc).

Make sure that any action is not taking


considerable time, game flow should be fast.

Should be in easily understandable format.

Help & About Screen free from spelling mistakes.

URL should be hyperlinked (depends).

Check the loading time of a game.

Check for localization Check the game when device memory is low.

Check for time format Should be Support of different languages.

Size Change the device time, format etc.

User wont like if your game takes lot of device 29


Device, OS space, so keep one eye on game file size.

Check in supported screen sizes and os versions


6. FUTURE ENHANCEMENT

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

# Initialized resource path for cross platform compatibility


BASE_DIR = os.path.dirname(__file__)
RESOURCE_PATH = os.path.join(BASE_DIR, '..', 'res')
IMAGE_PATH = os.path.join(RESOURCE_PATH, 'Images')

# 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

# Setting the title and dimensions of the window


pygame.display.set_caption('Egg Hunt!')
gameDisplay = pygame.display.set_mode((display_width, display_height))

# Defining the clock to set the FPS rates


clock = pygame.time.Clock()

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 setText(text, font_size, position, foreground_color, background_color=None,


font_family="Times New Roman"):
# Setting the font and related font features as per the parameters supplied.
font = pygame.font.SysFont(font_family, font_size)
text_to_display = font.render(text, 1, foreground_color, background_color)
gameDisplay.blit(text_to_display, position)
pygame.display.update()

# Defining functions for file operations.


def file_open_write(high_score):
f = open(os.path.join(RESOURCE_PATH, 'File', 'high_score.txt'), 'w')
f.write(high_score)
return f

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

# Game Play starts here!!!


def game_play():
33
# Images section

# Relatively small sized images to be placed in the main menu


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

# Initializing the speed variable which denotes the speed with which the images
move.
image_speed = 3

# Intialiaing the score variable.


score = 0

# Pixels being moved by the basket under keystrokes (10 px)


unit = 7
# Initialising a boolean variable user_click to False to keep track of the user
clicking any button in the main menu
user_clicked = False

34
# 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)

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

gameDisplay.blit(bomb_image, (display_width / 2 + 340, 25))

start = display_height + 40
end = 299
value = 0

# Setting the basket image to move from start to end.


gameDisplay.blit(basket_image, (display_width / 2 - 550, 300))
gameDisplay.blit(minion_image, (display_width / 2 - 470, 355))

time.sleep(1)

# Play Button
pygame.draw.rect(gameDisplay, (225, 10, 20), (display_width / 2 - 100, 260, 230,
100))

# Setting Play text on the button with setText() method


setText("Play !", 80, (530, 260), (255, 255, 255), None, "forte")

time.sleep(1)

# Instructions Button
pygame.draw.rect(gameDisplay, (30, 220, 20), (display_width / 2 - 200, 400, 440,
100))

# Setting Instructions text on the button with setText() method


setText("Instructions", 80, (435, 400), (255, 255, 255), None, "forte")

time.sleep(1)
# Best Scores Button

36
pygame.draw.rect(gameDisplay, (30, 22, 240), (display_width / 2 - 200, 540, 440,
100))

# Setting Best Scores text on the button with setText() method


setText("Best Scores", 80, (450, 540), (255, 255, 255), None, "forte")

pygame.display.update()

while not user_clicked:

# (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()

# Checking whether the mouse is within the boundaries of the respective


buttons in order (Hovered / Not)
if display_width / 2 - 100 + 230 > mouse_cord[0] > display_width / 2 - 100
and 360 > mouse_cord[1] > 260:
pygame.draw.rect(gameDisplay, (150, 220, 200), (display_width / 2 - 100,
260, 230, 100))
setText("Play !", 80, (530, 260), (225, 10, 20), None, "forte")

# Checking whether the user has clicked the play button


if event.type == pygame.MOUSEBUTTONDOWN:
37
user_clicked = True
play_clicked = True

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

if display_width / 2 - 200 + 440 > mouse_cord[0] > display_width / 2 - 200


and 500 > mouse_cord[1] > 400:
pygame.draw.rect(gameDisplay, (225, 100, 200), (display_width / 2 - 200,
400, 440, 100))
setText("Instructions", 80, (435, 400), (30, 220, 20), None, "forte")

# Checking whether the user has clicked the Instructions button


if event.type == pygame.MOUSEBUTTONDOWN:
user_clicked = True
instruction_clicked = True
else:
pygame.draw.rect(gameDisplay, (30, 220, 20), (display_width / 2 - 200,
400, 440, 100))
setText("Instructions", 80, (435, 400), (255, 255, 255), None, "forte")

if display_width / 2 - 200 + 440 > mouse_cord[0] > display_width / 2 - 200


and 640 > mouse_cord[1] > 540:
pygame.draw.rect(gameDisplay, (16, 140, 122), (display_width / 2 - 200,
540, 440, 100))
setText("Best Scores", 80, (450, 540), (75, 22, 205), 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("Instructions", 120, (display_width / 2 - 360, 50), (125, 20, 220), None,


"Elephant")
pygame.draw.line(instruction_window, (255, 0, 0), (display_width / 2 - 360,
180), (display_width / 2 + 400, 180), 5)
pygame.draw.line(instruction_window, (0, 255, 0), (display_width / 2 - 360,
185), (display_width / 2 + 400, 185), 5)
pygame.draw.line(instruction_window, (0, 0, 255), (display_width / 2 - 360,
190), (display_width / 2 + 400, 190), 5)

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

setText("5. Points Awarded: 1, 3, 5 and 10 depending up on the kind of egg.",


45, (40, 500), (255, 0, 255))

pygame.draw.rect(instruction_window, (0, 128, 255), (display_width / 2 - 180,


560, 160, 80))
setText("Back", 60, (display_width / 2 - 160, 570), (255, 255, 255))

while instruction_clicked:

for event in pygame.event.get():


mouse = pygame.mouse.get_pos()

if event.type == pygame.QUIT:
pygame.quit()
sys.exit()

if display_width / 2 - 20 > mouse[0] > display_width / 2 - 180 and 640 >


mouse[1] > 560:
pygame.draw.rect(instruction_window, (255, 255, 255), (display_width / 2 -
180, 560, 160, 80))

setText("Back", 60, (display_width / 2 - 160, 570), (0, 128, 255))

setText("Best of Luck!!", 60, (display_width / 2, 560), (185, 0, 0), None,


"Forte")

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("Back", 60, (display_width / 2 - 160, 570), (255, 255, 255))


instruction_window.fill((69, 250, 245), (display_width / 2, 570, 500, 70))
pygame.display.update()
instruction_clock.tick(30)
# Shows previous best high score stored in files in the same directory where the
game lies
if best_scores_clicked:
score_window = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption('High Score')
score_clock = pygame.time.Clock()
score_window.fill((255, 255, 255))

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)

file_object, high_score = file_open_read()


setText(high_score, 100, (display_width / 2, display_height / 2), (0, 255, 0))
pygame.draw.rect(score_window, (212, 3, 108), (display_width / 2 - 130,
display_height / 2 + 160, 300, 130))
setText("Go Back", 80, (display_width / 2 - 120, display_height / 2 + 180), (255,
255, 255))
file_close(file_object)

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 display_width / 2 + 170 > mouse_position[0] > display_width / 2 - 130 and


display_height / 2 + 290 > mouse_position[1] > display_height / 2 + 160:

pygame.draw.rect(score_window, (212, 3, 108), (display_width / 2 - 130,


display_height / 2 + 160, 300, 130))

setText("Go Back", 80, (display_width / 2 - 120, display_height / 2 + 180),


(255, 255, 255))

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

setText("Go Back", 80, (display_width / 2 - 120, display_height / 2 + 180),


(255, 255, 255))

pygame.display.update()
score_clock.tick(30)

# X and Y co-ordinates of the basket.


basket_x = display_width / 2 - 200
basket_y = display_height - 270
42
# 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)

# Game in action !!!


while play_clicked:

# 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()

play_window.blit(random_eggs, (x, y))

# Horizontal line carrying the basket.


pygame.draw.line(play_window, (175, 115, 0), (0, display_height - 20),
(display_width, display_height - 20))

# Color beneath the line.


pygame.draw.rect(play_window, (243, 128, 12), (0, display_height - 18,
display_width, display_height))
for event in pygame.event.get():

# Event handling
43
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()

elif event.type == pygame.KEYDOWN:

if event.key == pygame.K_RIGHT:
x_change = unit

elif event.key == pygame.K_LEFT:


x_change = -unit

elif event.key == pygame.K_DOWN:


x_change = 0

basket_x += x_change
y += image_speed

# Placing the Basket in position


play_window.blit(basket, (basket_x, basket_y))

# Placing score on the game window.


setText("Your Score:" + str(score), 40, (0, 0), (107, 20, 99), (128, 255, 255))

# Checking egg and basket crossover.


if y + 80 >= basket_y and y + 80 <= basket_y + 15:

if x >= basket_x - 40 and x + 100 <= basket_x + display_width / 2 - 240:


# Checks collision with bomb and minion image
if random_images == egg_images[9] or random_images == egg_images[7]:
score -= 5
setText("Your Score:" + str(score), 40, (0, 0), (107, 20, 99), (128, 255,
255))

44
# Checking whether the current score is greater than the best score.
file, current_best_score = file_open_read()
file_close(file)

if score > int(current_best_score):


file = file_open_write(str(score))
file_close(file)

setText("Crashed", 150, (display_width / 2 - 240, 35), (0, 0, 0))


setText(None, 40, (0, 0), (255, 255, 255))
play_window.blit(explosion, (basket_x, basket_y - 80))
pygame.display.update()

time.sleep(3)

for k in range(0, display_width + 1, 5):


setText("Your Score:" + str(score), 40, (k, 0), (107, 20, 99), (128, 255,
255))
pygame.time.wait(20)

time.sleep(2)

game_over = True
play_clicked = False

# Makes the egg disappear !


y = display_height

# Incrementing the score appropriately.


if random_images == egg_images[6]:
score += 1

elif random_images == egg_images[0] or random_images ==


egg_images[1] or random_images == egg_images[3]:
45
score += 3

elif random_images == egg_images[4] or random_images ==


egg_images[5] or random_images == egg_images[8]:
score += 5
elif random_images == egg_images[2]:
score += 10

# Checking whether the egg image had crossed the floor.


if y >= display_height + 200:

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

# Increasing the speed in which the basket moves both the directions.
if unit != 15:
unit += 1

# Increasing the speed in which the images moves down.


if image_speed != 16:
image_speed += 1

# Restricting the basket within the width of the Game window


if basket_x <= 0:
basket_x = 0

elif basket_x >= display_width - 300:


basket_x = display_width - 300

46
pygame.display.update()
play_clock.tick(60)

# Game Over window


if game_over:

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

setText("G", 90, (180, 250), (255, 255, 255), None, "Elephant")


pygame.time.wait(400)

setText("A", 90, (270, 250), (255, 255, 255), None, "Elephant")


pygame.time.wait(400)

setText("M", 90, (360, 250), (255, 255, 255), None, "Elephant")


pygame.time.wait(400)

setText("E", 90, (460, 250), (255, 255, 255), None, "Elephant")


pygame.time.wait(400)

setText("O", 90, (630, 250), (5, 96, 196), None, "Elephant")


pygame.time.wait(400)

setText("V", 90, (720, 250), (5, 96, 196), None, "Elephant")


pygame.time.wait(400)

setText("E", 90, (810, 250), (5, 96, 196), None, "Elephant")


pygame.time.wait(400)

setText("R", 90, (900, 250), (5, 96, 196), None, "Elephant")


47
pygame.time.wait(400)

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

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

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 display_width / 2 + 70 > mouse[0] > display_width / 2 - 110 and 635 >


mouse[1] > 540:
pygame.draw.rect(game_over_window, (235, 125, 255), (display_width /
2 - 110, 540, 180, 95))
setText("Credits", 60, (display_width / 2 - 110, 550), (0, 128, 127), None,
"Forte")

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)

# Variables required for foreground colors.


i=65
j=64
k=65

if credit_clicked:
credits_window = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption("CREDITS")

49
credits_clock = pygame.time.Clock()

credits_window.fill((0, 255, 255))


setText("CREDITS", 150, (display_width / 2 - 280, 20), (127, 178, 68), None,
"Algerian")

pygame.draw.line(credits_window, (0, 0, 255), (display_width / 2 - 280, 160),


(display_width / 2 + 280, 160), 3)
pygame.draw.line(credits_window, (0, 255, 0), (display_width / 2 - 280, 165),
(display_width / 2 + 280, 165), 3)
pygame.draw.line(credits_window, (255, 0, 0), (display_width / 2 - 280, 170),
(display_width / 2 + 280, 170), 3)

pygame.time.wait(1000)

setText("Developer:", 120, (display_width / 2 - 240, display_height / 2 - 150), (0,


170, 0), None, "Forte")

setText("Merlin", 100, (display_width / 2 - 170, display_height / 2 - 20), (i, j, k),


None, "Elephant")

pygame.time.wait(1500)

setText("Jenifer", 100, (display_height / 2 + 90, display_height / 2 + 80), (k, j, i),


None, "Elephant")

pygame.time.wait(1500)

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

while credit_clicked:

50
if i >= 255:
i = 64
if j >=255:
j = 65
if k >=255:
k = 64

setText("Merlin", 100, (display_width / 2 - 170, display_height / 2 - 20), (i, j, k),


None, "Elephant")

setText("Jenifer", 100, (display_height / 2 + 90, display_height / 2 + 80), (k, j, i),


None, "Elephant")

for event in pygame.event.get():

mouse_pos = pygame.mouse.get_pos()

if event.type == pygame.QUIT:
pygame.quit()
sys.exit()

if display_width / 2 + 260 > mouse_pos[0] > display_width / 2 - 230 and


display_height / 2 + 300 > mouse_pos[1] > display_height / 2 + 200:
pygame.draw.rect(credits_window, (0, 0, 160), (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")

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

Fig 8.2.1. Main Menu

Fig 8.2.2. Game Play

53
Fig 8.2.3. Bomb / Minion Crashed

Fig 8.2.4. Game Over

54
Fig 8.2.5. Instuctions

Fig 8.2.6. High Score

55
Fig 8.2.7. Credits

56
9. REFERENCES

9.1. BOOKS
1. Learn Python the Hard Way: 3rd Edition

2. Python Programming: An Introduction to Computer Science (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

You might also like