Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 3 . 1 2 PA 4 Q 2 : Fight! Now we want a way to make our monsters fight! Before two monsters can
PA Q: Fight!
Now we want a way to make our monsters fight!
Before two monsters can fight, we need to give new class methods that update their stats. Implement a method for "winfight" and "losefight". Winfight should add to the monster's self.exp and reset their hp to maxhp "losefight" should also reset their hp but only adds exp to self.exp.
Now write a function that takes instances of the monster class and makes them fight. This function should be defined outside the Monster class, ie it is not a Monster method. A fight goes as follows:
The monster that entered as the first function goes first.
Each monster takes a turn using one attack move. The monster selects this attack move from the strongest to the weakest in a circular function.
For example:
A monster has a dictionary of possible attack as follows:
firestorm": "doublehit": "earthquake": "icestorm":
Monster will select the following attacks:
tableRound NoMove,doublehit,Highest hit pointsfirestorm,Same hit points as icestorm but comes first alphabeticallyicestorm,earthquake,doublehit,firestorm,icestorm,
And so on
An attack is always successful and will decrease the opponent's hp by the given number of points in self attacks dictionary. The monsters continue taking turns until their current becomes less than or equal to zero.
At this point, the winfight and losefight method should be invoked. Once this complete, return things from the function.
Roundnumber
Monster that won return the corresponding Monster object
List of attacks the monster used
Special Edge Case: If both monster only have "wait" as an attack, return
roundnumber
None for monster name that won
None for list of attack that monster use
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started