CIS4930 Exercise 2 Object Oriented Programming Constructs in Python Solved

 Practice working with object-oriented programming constructs in Python including classes and objects by building classes to represent creatures and a cataloguing system. 

Scenario
NOTE: This project concept is a work of satire. To state the obvious: we do not advise one to go around imprisoning creatures in small receptacles held in one’s pockets and/or having them fight for sport.

 

Pouch Creatures – abbreviated “Pakuri” – are the latest craze sweeping elementary schools around the world. Tiny magical creatures small enough to fit into one’s trouser pouches (with enough force applied, ‘natch) have begun appearing all around the world in forests. They come in all shapes and colors. When stolen from their parents at a young enough age, they can be kept in small spherical cages (for their own good) easily carried by elementary school children (though they are also popular with adults). This has led to an unofficial catch phrase for the phenomenon – “Gotta steal ‘em all!” – a play on the abbreviation “Pakuri” (which doubles as Japanese slang meaning “to steal”). Young children can then pit their Pakuri against one another in battle for bragging rights or to steal them from one another. (Don’t worry – they heal their wounds quickly!)

 

Lately, those without the resources to go with real Pakuri have latched onto “Pakuri ni Ikou”, with the English title “Pakuri: Let’s Go”. (The literal translation of the title is “Let’s Go Pakuri”, but localizers felt it was weird. They also changed all of the dialog, as they always do.) This game is a world-wide AR game using geolocation to collect data on users… purely for in-game purposes, of course.

 

Of course, keeping track of all these critters can be a real task, especially when you are trying to steal so many of them at such a young age! You’ve decided to cash in – hey, if you don’t someone else will – on the morally ambiguous phenomenon by developing an indexing system – a Pakudex – for kids and adult participants.

 

Requirements
Students will write two files to submit: a driver program with a main() entry point (pakudex.py) and a file containing the Pakuri class (pakuri.py).

Welcome to Pakudex: Let's Go!

 

Pakudex Main Menu

-----------------

1.  List Pakuri

2.  Show Pakuri

3.  Add Pakuri

4.  Remove Pakuri

5.  Change Pakuri Level

6.  Exit

 What would you like to do?
 

Driver Program
When run, the program should…

 

1)      Display a welcome message

2)      Display the menu & prompt for input

3)      Conduct input error checking

4)      Follow the output and formatting in this document 

 

Listing Pakuri

This should number and list creatures in Python lexigraphical order. For example, if “Chuchu” and “Allie” were added to the Pakudex (in that order), the list should be:

 

            Success                                                                           Failure
Pakuri In Pakudex:

1.  Allie (Gator, level 10)

2.  Chuchu (ShockRat, level 4)
 
No Pakuri in Pakudex yet!

 

Pakudex Main Menu
 

Show Pakuri

The program should prompt for a species and collect species information, then display it:

 

            Success                                                                           Failure
Enter the name of the pakuri to display: Quackers

 

Name: Quackers

Species: PsyGoose

Level: 15

CP: 324

HP: 57
 
Enter the name of the pakuri to display: PsyDuck

Error: No such Pakuri!

 

Pakudex Main Menu

-----------------

1.  List Pakuri

2.  Show Pakuri
 

Adding Pakuri

When adding a Pakuri, a prompt should be displayed to read in the individual’s name, species, and level. If the individual is already in the Pakudex, the program should return to the main menu.

 

            Success                                                                           Failure – Duplicate
Name: Quackers Error: Pakudex already contains this Pakuri!
Pakuri Information

------------------

Name: Quackers

Species: PsyGoose

Level: 15

 

Pakuri Quackers (PsyGoose, level 15) added!

 

Pakudex Main Menu

-----------------
Level: -15

Level cannot be negative.

Level: 500

Maximum level for Pakuri is 50. Level: NINE-THOUSAND

Invalid level!
Failure – Level

 

 

Removing Pakuri

The program should prompt for a name and then remove the Pakuri if it is in the Pakudex:

 

            Success                                                                           Failure
Enter the name of the Pakuri to remove: Quackers Pakuri Quackers removed.
 
Enter the name of the Pakuri to remove: PsyDuck Error: No such Pakuri!
 

Change Pakuri Level

Changing the Pakuri’s level should follow the same format used in other options:

 

            Success                                                                           Failure – Level

Enter the name of the Pakuri to change: Quackers Enter the new level for the Pakuri: -42

Level cannot be negative.

Enter the new level for the Pakuri: 500

Maximum level for Pakuri is 50.

Enter the new level for the Pakuri: GAJILLION

Invalid level!
Enter the name of the Pakuri to change: Quackers

Enter the new level for the Pakuri: 42
Enter the name of the Pakuri to change: PsyGoose

Error: No such Pakuri! 
Failure – No Element
 

 

Exit

On exit, the program should print “Thanks for using Pakudex: Let's Go! Bye!” to the screen.

Pakuri Class
This class will be the blueprint for the different creature objects that you will create. You will need to store information about the name, species, and level, along with three attributes: attack, defense, and stamina. All variables storing information about the critters must follow Python conventions for private variables.

 

The attributes are based on the Pakuri name and species according to the following formula:

 

 

Attribute = Species Base + Individual Value
                          

 

Species and individual attributes come from the little-endian md5 hash (UTF-8 encoding), plus offset, mod 16:

 

Attribute
Species Base
Individual Value
Attack
md5(species) % 16
md5(name) % 16
Defense
md5(species) + 5) % 16
md5(name) + 5) % 16
Stamina
md5(species) + 11) % 16
md5(name) + 11) % 16
 

While Pakuri attributes are never revealed to the user, they are used (along with level) to determine the combat power (CP) and healthy points (HP), as follows:

 

 

𝑯𝑯𝑯𝑯 = 𝐹𝐹𝐹𝐹𝐹𝐹𝐹𝐹𝐹𝐹(𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺 × 𝑳𝑳𝑳𝑳𝑳𝑳𝑳𝑳𝑳𝑳 / 𝟔𝟔)

 



𝑪𝑪𝑯𝑯 = 𝐹𝐹𝐹𝐹𝐹𝐹𝐹𝐹𝐹𝐹(𝑨𝑨𝑺𝑺𝑺𝑺𝑺𝑺𝑨𝑨𝑨𝑨 × 𝑫𝑫𝑳𝑳𝑫𝑫𝑳𝑳𝑺𝑺𝑫𝑫𝑳𝑳 × √𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺 × 𝑳𝑳𝑳𝑳𝑳𝑳𝑳𝑳𝑳𝑳 × 𝟎𝟎. 𝟎𝟎𝟎𝟎)

 
 

Required Methods

 

__init__(self, name, species, level)

This is one of two constructors for the Pakuri class. There should not be a default constructor!

 

__init__(self, name, species)

This constructor for Pakuri should set the initial level to 0.

 

Required Properties

 

name (read-only)

Returns the Pakuri object’s name attribute.

 

species (read-only)

Returns the Pakuri object’s species attribute.

 

species (read-only)

Returns the Pakuri object’s species attribute.

 

hp (read-only)

Calculates and returns the Pakuri object’s health points (HP).

 

cp (read-only)

Calculates and returns the Pakuri object’s combat power (CP).

 

level (read-write)

Gets, or sets, the Pakuri object’s level attribute.