首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
ITP 115编程讲解、辅导Python编程语言、Python程序讲解 辅导Database|辅导P
项目预算:
开发周期:
发布时间:
要求地区:
ITP 115 – Programming in Python
2021-06-25 Page 1 of 13
Final Project – Pocket Monster Simulation
Goals
Complete a project that demonstrates problem solving skills and logical thinking.
Demonstrate knowledge of Python programming concepts learned throughout the
semester. You are not allowed to use Python concepts that were not taught this
semester in this course.
Overview
You will be writing a program that simulates catching, storing, and releasing Pocket
Monsters. You will implement different types of Pocket Monsters and balls.
It is recommended that you implement the code in the order listed below. After
completing each part, it is also recommended that you test the functionality of your
existing code before proceeding to the next part.
To best understand the structure and flow of the simulation, please read all the
directions through before beginning any code.
Requirements
In PyCharm, create a new project named project_last_first where last is your
last/family name and first is your preferred first name.
This project will be a folder containing the required class files you write, the given
helper file, the given txt file, and the given CSV file.
Use proper coding styles and comments.
Name newly created Python files as directed below.
Project should perform error-checking (on all inputs).
Use the Python concepts that we have covered during this semester.
You may NOT import the CSV or other modules.
ITP 115 – Programming in Python
2021-06-25 Page 2 of 13
Files Provided
Download the following Python files and put them in your newly created project.
GrassyField.py
We have provided a helper file for you called GrassyField.py which includes helper
methods to allow Pocket Monsters to randomly appear.
You will not need to interact directly with this file, however it is important that you add
it to your directory with the other project files.
Run.py
We have also provided a main function and one other function for you in a file called
Run.py which starts the simulation. This is the only file that you will need to run and it
should also be placed in the same directory as your project files.
You will need to update the trainer name (currently an empty string) to your own
trainer name.
pm.csv
A CSV (comma-separated values) file with PocketMonsters
Each line in the file represents a menu item:
o Name,Type,Strength,Rarity
CSV file example:
Bulbasaur,Grass,318,2
Ivysaur,Grass,405,3
Venusaur,Grass,525,5
Charmander,Fire,309,2
Charmeleon,Fire,405,3
There is not a header row in the CSV file.
ITP 115 – Programming in Python
2021-06-25 Page 3 of 13
Part 1 – Creating the Pocket Monsters
To represent a Pocket Monster, you will be creating two separate classes: PocketMonster
and PMIndex.
PocketMonster Class
Start by defining the PocketMonster class in a file titled PocketMonster.py.
This class will represent a single Pocket Monster.
The class will have the following instance attributes:
o self.name: a string containing the name of the item
o self.type: a string containing the category of the item
o self.strength: a float containing the price of the item
o self.rarity: a string containing a description of the item
Define the following methods:
o __init__
Parameters (4): name (string), type (string), strength (int), and rarity (int)
of the PocketMonster
Return value: None
Assign the inputs to the 4 instance attributes listed above.
o Define get methods for all the instance attributes. There is no need to define set
methods for the instance attributes.
o __str__
Parameters (0): None
Return value: a string
Construct a message containing all 4 attributes, formatted in a readable
manner such as:
Name (Type)
Strength: ___
Rarity: ___
For example:
Kangaskhan (Normal)
Strength: 490
Rarity: 4
ITP 115 – Programming in Python
2021-06-25 Page 4 of 13
PMIndex Class
Next, define the PMIndex class in a file titled PMIndex.py. This class will make use of
PocketMonster objects, so be sure to include the proper import statement.
This class represents the entire collection of pocket monsters categorized by their
different types.
The class will have a following class (or static) variable:
o TYPES: a list containing 15 strings, representing the 15 possible types of Pocket
Monsters: “Bug”, “Dragon”, “Electric”, “Fighting”, “Fire”, “Fairy”, “Ghost”,
“Grass”, “Ground”, “Ice”, “Normal”, “Poison”, “Psychic”, “Rock”, “Water”
The class will have the following instance attributes:
o self.bug: a list containing PocketMonster objects that are of the Bug type
o self.dragon: a list containing PocketMonster objects that are of the
Dragon type
o self.electric: a list containing PocketMonster objects that are of the
Electric type
o self.fighting: a list containing PocketMonster objects that are of the
Fighting type
o self.fire: a list containing PocketMonster objects that are of the Fire type
o self.fairy: a list containing PocketMonster objects that are of the Fairy
type
o self.ghost: a list containing PocketMonster objects that are of the Ghost
type
o self.grass: a list containing PocketMonster objects that are of the Grass
type
o self.ground: a list containing PocketMonster objects that are of the
Ground type
o self.ice: a list containing PocketMonster objects that are of the Ice type
o self.normal: a list containing PocketMonster objects that are of the
Normal type
o self.poison: a list containing PocketMonster objects that are of the Poison
type
o self.psychic: a list containing PocketMonster objects that are of the
Psychic type
o self.rock: a list containing PocketMonster objects that are of the Rock type
o self.water: a list containing PocketMonster objects that are of the Water
type
o Extra credit
ITP 115 – Programming in Python
2021-06-25 Page 5 of 13
Instead of 15 lists, you can use a single dictionary self.monsters: a
dictionary containing all the Pocket Monsters. The keys are strings
representing the types in the PMIndex class, and each value is a list of
PocketMonster objects depending on the key.
Use the TYPES class variable for the keys whenever possible.
Define the following methods:
o __init__
Parameter (1): the name of the CSV file (string) that contains the
information for the Pocket Monsters
Return value: None
Initialize each instance attribute to an empty list.
Open and read the CSV file.
Create a PocketMonster object from each line in the file. Use the type
to add the new object to one of the instance attributes. Note that each
line in the file contains the 4 pieces of information needed to create a
Pocket Monster object.
Close the file object.
o getMonster
Parameters (2): a type (string) and an index (integer) which is the
position of the Pocket Monster
Return value: a PocketMonster object from the appropriate instance
attribute using the index parameter
For error checking, make sure that the type parameter is one of the
TYPES.
For error checking, make sure that the index parameter is in the range of
the appropriate list.
Return the correct PocketMonster using its category and index
position.
If the type and/or index were not valid, then do not return anything.
o getMonsterType
Parameter (1): a type (string)
Return value: a list of Pocket Monsters of the appropriate type
For error checking, make sure that the type parameter is one of the
TYPES. If it is not, then don’t return anything.
o printMonsterType
Parameter (1): a type (string)
Return value: None
Print the list of Pocket Monsters given by the type input
ITP 115 – Programming in Python
2021-06-25 Page 6 of 13
For error checking, make sure that the type parameter is one of the
TYPES. If it is not, then don’t print anything.
Print a header with the type of Pocket Monster, followed by a numbered
list of all the menu items of that category. Start the numbering at 0.
Example:
TYPE: Rock
Geodude (Rock)
Strength: 300
Rarity: 1
Graveler (Rock)
Strength: 390
Rarity: 3
Golem (Rock)
Strength: 495
Rarity: 4
Onix (Rock)
Strength: 385
Rarity: 3
o getNumMonsterType
Parameter (1): a type (string)
Return value: an integer which is the number of PocketMonsters in the
appropriate list based on the type parameter
For error checking, make sure that the type parameter is one of the
TYPES. If it is not, then return 0.
o You do not need to define any get and set methods for the instance attributes of
this class.
o You are welcome to create the __str__ method that returns a string
containing the full Pocket Monster lists (all 15 of them). This can be used after
you create a PMIndex object by calling print() on the PMIndex object. By looking
at the output in the console window, you can make sure the menu was created
correctly in the __init__ method. This is not required.
At this point, you should be able to test the methods in the PMIndex class.
ITP 115 – Programming in Python
2021-06-25 Page 7 of 13
Part 2 – Creating Trainers
Next, define the Trainer class in a file titled Trainer.py. This class represents a
trainer who will use Catch Capsules to capture Pocket Monsters
The class will have the following class (or static) variables:
o MAXPM: this is the maximum Pocket Monsters a trainer is allowed to have at any
time. The value will be set at 6
o MAXCC: this is the maximum number of Catch Capsules a trainer is allowed to
have at any time. The value will be set at 10
The class will use the following instance attributes:
o self.name: a string containing the trainer’s name
o self.caught: a list of the PocketMonster objects caught by the trainer
o self.capsules: an integer corresponding to the number of capsules the
trainer has currently
Define the following methods:
o __init__
Parameter (1): a string containing the trainer’s name
Return value: None
Set the trainer’s name attribute to the input value. Set the trainer’s
caught attribute to an empty list (the trainer has not caught any Pocket
Monsters yet). Set the capsules attribute to 0
o Define get methods for all the instance attributes. There is no need to define set
methods for the instance attributes.
o getNumCaught
Parameters (0): None
Return value: integer representing the number of Pocket Monsters
caught by the trainer
o buyCapsules
Parameter (1): an integer representing how many capsules to buy
Return value: None
Checks the input amount and makes sure it is valid. Input amount should
be greater than 0 and the current capsule count plus the input amount
should not exceed the MAXCC value
o addMonster
Parameters (1): PocketMonster to add to list
Return value: None
Appends the Pocket Monster to the list of Pocket Monsters caught by
the trainer
o releaseMonster
ITP 115 – Programming in Python
2021-06-25 Page 8 of 13
Parameters (1): an integer representing an index
Return value: None
This function should remove the proper Pocket Monster (based on the
index given) from the list of caught Pocket Monsters and print a
“Goodbye” message
o encounter
Parameters (1): a PocketMonster to encounter
Return value: an integer which indicates how the encounter ended
This function should print the Pocket Monster that the user encountered
and then ask the user to perform one of two actions until the encounter
is over. The actions are:
0: Throw a Catch Capsule
1: Run
If the user chooses to throw a capsule, then decrease the trainer’s
capsule count by 1 and do the following:
Create a random integer value from 0-3900 (inclusive)
If the random integer is greater than or equal to the monster’s
strength * rarity then the user caught the monster. Return 1
If it’s not, the monster escaped the capsule
o If the random integer is less than the monster’s strength,
then the monster ran away. Return -1
o If the random integer is greater than or equal to the
monster’s strength, then ask for a new action
If the user runs out of capsules, the encounter is over. Return -2
If the user chooses to run, the encounter is over. Return 0
This function is fairly complex so to help diagram the flow of control, see
the following flowchart:
ITP 115 – Programming in Python
2021-06-25 Page 9 of 13
S
Get/validate
action
Action?
E
Run
Generate
random int
Caught?
Did it flee?
Capsules >
0?
Throw
Yes
No
Yes
No
No
Yes
ITP 115 – Programming in Python
2021-06-25 Page 10 of 13
o __str__
Parameters (0): None
Return value: a string
Construct a message containing the trainer’s name, number of capsules,
and the list of monsters they currently have caught.
Examples:
Trainer Stats:
Ray
Capsules: 1
Monsters:
Dratini (Dragon)
Strength: 300
Rarity: 2
Gastly (Ghost)
Strength: 310
Rarity: 1
ITP 115 – Programming in Python
2021-06-25 Page 11 of 13
Part 3 – Making it Work
Now you will make it all work. We have already defined the main function and one
other function for you, you simply need to write the following functions in Run.py to
make it all work.
Define the following functions:
o getMenuSelection
Parameter (0):
Return value: an integer representing the user’s menu choice
Print a list of options for the user to choose from. The options should be:
0: Explore the Grassy Fields
1: Release monsters
2: Enter the shop to purchase capsules
3: Print the trainer stats
4: Quit
Get the user’s input and validate that it’s one of the choices.
Return the user’s choice as an integer
o releaseMonsters
Parameter (1): a Trainer object
Return value: None
Print the list of monsters that the trainer has.
Ask the user to select which monster to release by selecting their index
Validate the user’s selection
Release the monster by calling the appropriate Trainer method
o enterShop
Parameters (1): a Trainer object
Return value: None
Ask the user how many capsules they would like to purchase. Make sure
the number they purchase is greater than 0. Also make sure the number
they purchase will not make the trainer’s capsule count exceed MAXCC
Call the appropriate Trainer method to set the new capsule count
ITP 115 – Programming in Python
2021-06-25 Page 12 of 13
Extra Credit (Up to 10% total)
Update the PMIndex class to use a single dictionary instead of 15 lists.
o Create an instance attribute self.monsters: a dictionary which contains all
the Pocket Monsters. The keys are strings representing the types of the menu
item, and each value is a list of PocketMonster objects depending on the
key.
o Update the methods in the PMIndex class appropriately.
o Use the TYPES class variable for the keys whenever possible.
ITP 115 – Programming in Python
2021-06-25 Page 13 of 13
Sample Output
Sample is shown a separate file.
Deliverables
Project that do not run will subject to an automatic 50% penalty.
Late submissions will not be accepted.
Submission Instructions
Compress your Python project folder (project_last_first) which contains your Python
source code. Your folder should contain the following files:
– PocketMonster.py, PMIndex.py, Trainer.py
– GrassyField.py, Run.py
– pm.csv
You should have a zip file entitled project_last_first.zip where last is replaced with
your last/family name and first is replaced with your first name.
Under Final Project on Blackboard, upload the zip file.
Grading
Item Points
PocketMonster Class 10
PMIndex Class 25
Trainer Class 25
Run.py Functions 20
Project executes successfully and has error checking 10
Proper coding style and detailed comments 10
Total* 100
* Points will be deducted for poor code style, or improper submission.
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做ceng0013 design of a pro...
2024-11-13
代做mech4880 refrigeration a...
2024-11-13
代做mcd1350: media studies a...
2024-11-13
代写fint b338f (autumn 2024)...
2024-11-13
代做engd3000 design of tunab...
2024-11-13
代做n1611 financial economet...
2024-11-13
代做econ 2331: economic and ...
2024-11-13
代做cs770/870 assignment 8代...
2024-11-13
代写amath 481/581 autumn qua...
2024-11-13
代做ccc8013 the process of s...
2024-11-13
代写csit040 – modern comput...
2024-11-13
代写econ 2070: introduc2on t...
2024-11-13
代写cct260, project 2 person...
2024-11-13
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!