class Pokemon:
def init(self, name, type, level = 5):
self.name = name
self.level = level
self.health = level * 5
self.max_health = level * 5
self.type = type
self.is_knocked_out = False
def __repr__(self):
return "This level {level} has {health} hitpoints remaining. They are a {type} type Pokemon".format(level = self.level, health = self.health, type = self.type)
def revive(self):
self.is_knocked_out = True
if self.health != 0:
self.health = 0
def lose_health(self, amount):
self.health -= amount
if self.health <= 0:
self.health = 0
self.knockout()
else:
print("{name} now has {health} health").format(name = self.name, health = self.health)
def gain_health(self, amount):
# Adds to a pokemon's heath
# If a pokemon goes from 0 heath, then revive it
if self.health == 0:
self.revive()
self.health += amount
# Makes sure the heath does not go over the max health
if self.health >= self.max_health:
self.health = self.max_health
print("{name} now has {health} health.".format(name = self.name, health = self.health))
def attack(self, other_pokemon):
# Checks to make sure the pokemon isn't knocked out
if self.is_knocked_out:
print("{name} can't attack because it is knocked out!".format(name = self.name))
return
# If the pokemon attacking has a disadvantage, then it deals damage equal to half its level to the other pokemon
if (self.type == "Fire" and other_pokemon.type == "Water") or (self.type == "Water" and other_pokemon.type == "Grass") or (self.type == "Grass" and other_pokemon.type == "Fire"):
print("{my_name} attacked {other_name} for {damage} damage.".format(my_name = self.name, other_name = other_pokemon.name, damage = round(self.level * 0.5)))
print("It's not very effective")
other_pokemon.lose_health(round(self.level * 0.5))
# If the pokemon attacking has neither advantage or disadvantage, then it deals damage equal to its level to the other pokemon
if (self.type == other_pokemon.type):
print("{my_name} attacked {other_name} for {damage} damage.".format(my_name = self.name, other_name = other_pokemon.name, damage = self.level))
other_pokemon.lose_health(self.level)
# If the pokemon attacking has advantage, then it deals damage equal to double its level to the other pokemon
if (self.type == "Fire" and other_pokemon.type == "Grass") or (self.type == "Water" and other_pokemon.type == "Fire") or (self.type == "Grass" and other_pokemon.type == "Water"):
print("{my_name} attacked {other_name} for {damage} damage.".format(my_name = self.name, other_name = other_pokemon.name, damage = self.level * 2))
print("It's super effective")
other_pokemon.lose_health(self.level * 2)
class Trainer:
def init(self, pokemon_list, num_potions, name):
self.pokemons = pokemon_list
self.potions = num_potions
self.current_pokemon = 0
self.name = name
def __repr__(self):
print("The trainer {name} has the following pokemon".format(name = self.name))
for pokemon in self.pokemon:
print(pokemon)
return "The current active pokemon is {name}".format(name = self.pokemons[self.current_pokemon].name)
def switch_active_pokemon(self, new_active):
if new_active < len(self.pokemons) and new_active >= 0:
if self.pokemons[new_active].is_knocked_out:
print("{name} is knocked out. You cannot make it your active pokemon".format(name = self.pokemons[new_active].name))
elif new_active == self.current_pokemon:
print("{name} is already your active pokemon").format(name = self.pokemons[new_active].name)
else:
self.current_pokemon = new_active
print("Go {name} it's your turn!").format(name = self.pokemons[self.current_pokemons].name)
def use_potions(self):
if self.potions >= 0:
print("You used a potion on {name}".format(name = self.pokemons[self.current_pokemon].name))
self.pokemons[self.current_pokemon].gain_health(20)
self.potions -= 1
else:
print("You do not have anymore potions")
def attack_other_trainer(self, other_trainer):
my_pokemon = self.pokemons[self.current_pokemon]
their_pokemon = other_trainer.pokemons[other_trainer.current_pokemon]
my_pokemon.attack(their_pokemon)
a = Pokemon(“Charmander”, “Fire”, 7)
b = Pokemon(“Squirtle”, “Water”)
c = Pokemon(“Lapras”, “Water”, 9)
d = Pokemon(“Bulbasaur”, “Grass”, 10)
e = Pokemon(“Vulpix”, “Fire”)
f = Pokemon(“Staryu”, “Water”, 4)
trainer_one_name = input("Welcome to the world of Pokemon. Please enter a name for player one and hit enter. ")
trainer_two_name = input("Hi, " + str(trainer_one_name) + "! Welcome! Let’s find you an opponent. Enter a name for the second player. ")
choice = input("Hi, " + trainer_two_name + "! Let’s pick our Pokemon! " + trainer_one_name + ", would you like a Level 7 Charmander, or a Level 7 Squirtle? " + trainer_two_name + " will get the other one. Type either ‘Charmander’ or ‘Squirtle’. ")
while choice != ‘Charmander’ and choice != ‘Squirtle’:
choice = input("Whoops, it looks like you didn’t choose ‘Charmander’ or ‘Squirtle’. Try selecting one again! ")
Keeping track of which pokemon they chose
trainer_one_pokemon =
trainer_two_pokemon =
if choice == ‘Charmander’:
trainer_one_pokemon.append(a)
trainer_two_pokemon.append(b)
else:
trainer_one_pokemon.append(b)
trainer_two_pokemon.append(a)
Selecting the second pokemon
choice = input(trainer_two_name + ", would you like a Level 9 Lapras, or a Level 10 Bulbasaur? " + trainer_one_name + " will get the other one. Type either ‘Lapras’ or ‘Bulbasaur’. ")
while choice != ‘Lapras’ and choice != ‘Bulbasaur’:
choice = input("Whoops, it looks like you didn’t choose ‘Lapras’ or ‘Bulbasaur’. Try selecting one again! ")
if choice == ‘Lapras’:
trainer_one_pokemon.append(d)
trainer_two_pokemon.append(c)
else:
trainer_one_pokemon.append(c)
trainer_two_pokemon.append(d)
Selecting the third pokemon
choice = input(trainer_one_name + ", would you like a Level 5 Vulpix, or a Level 4 Staryu? " + trainer_two_name + " will get the other one. Type either ‘Vulpix’ or ‘Staryu’. ")
while choice != ‘Vulpix’ and choice != ‘Staryu’:
choice = input("Whoops, it looks like you didn’t choose ‘Vulpix’ or ‘Staryu’. Try selecting one again! ")
if choice == ‘Vulpix’:
trainer_one_pokemon.append(e)
trainer_two_pokemon.append(f)
else:
trainer_one_pokemon.append(f)
trainer_two_pokemon.append(e)
Creating the Trainer objects with the given names and pokemon lists
trainer_one = Trainer(trainer_one_pokemon, 3, trainer_one_name)
trainer_two = Trainer(trainer_two_pokemon, 3, trainer_two_name)
print(“Let’s get ready to fight! Here are our two trainers”)
print(trainer_one)
print(trainer_two)
Testing attacking, giving potions, and switching pokemon. This could be built out more to ask for input
trainer_one.attack_other_trainer(trainer_two)
trainer_two.attack_other_trainer(trainer_one)
trainer_two.use_potion()
trainer_one.attack_other_trainer(trainer_two)
trainer_two.switch_active_pokemon(0)
trainer_two.switch_active_pokemon(1)
I can’t explain the errors help please