Need to do it in Python... Define a “warrior” class: A warrior has four properti
ID: 3572582 • Letter: N
Question
Need to do it in Python...
Define a “warrior” class:
A warrior has four properties: Health, Strength, Dexterity, Stamina. Health is 100 initially for all warriors.
Strength, dexterity and stamina are integers between [0-100]. Now, define three inherited classes:
Human, Elf, Dwarf. These are all warriors. Therefore, they will have the properties of a general warrior in addition to their own:
A human warrior uses a sword: Short (weapon=10), normal (30), long (50)
An elf warrior uses a bow: Short (5), normal (20), long (60)
A dwarf warrior uses an axe: Short (5), normal (30), long (40)
Create two teams having three warriors of each type using random variables for their properties.
They will have a fight in a minute...
Before the fight, let each one scream her/his properties to fear the other team.
Now select two warriors randomly from each team and let them fight:
Calculate “strength+dexterity+stamina+weapon” for the two warriors (total1 and total2):
If total1>total2 : health2=health2-(total1-total2) , health1=health1
If total2>total1 : health1=health1-(total2-total1) , health2=health2
If total2=total1 : health1=health1 , health2=health2
Continue fighting until one of the teams is all dead. Print how many fights happened in the field.
Explanation / Answer
from random import randint
class warrior:
health = 100
strength = randint(0,100)
dexterity = randint(0,100)
stamina = randint(0,100)
class Human(warrior):
liH=[10,30,50]
weapon=liH[randint(0,2)]
class Elf(warrior):
liE = [5,20,60]
weapon=liE[randint(0,2)]
class Dwarf(warrior):
liD = [5,30,40]
weapon=liD[randint(0,2)]
team1=[Human(),Elf(),Dwarf()]
team2=[Human(),Elf(),Dwarf()]
fighter1=team1[randint(0,2)]
fighter2=team2[randint(0,2)]
total1=fighter1.strength+fighter1.dexterity+fighter1.stamina+fighter1.weapon
total2=fighter2.strength+fighter2.dexterity+fighter2.stamina+fighter2.weapon
print(total1," " ,total2)
count=0
while(fighter1.health >=0 and fighter2.health >=0):
if(total1>total2):
fighter1.health=fighter1.health
fighter2.health=fighter2.health-(total1-total2)
count=count+1
elif(total1<total2):
fighter2.health=fighter2.health
fighter1.health=fighter1.health-(total2-total1)
count=count+1
else:
fighter1.health=fighter1.health
fighter2.health=fighter2.health
print(count)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.