Codecademy export
class Pokemon: | |
#constructor | |
def __init__(self, name, level, poke_type, max_health, health, experience, knocked_out): | |
self.name = name | |
self.level = level | |
self.knocked_out = knocked_out | |
self.max_health = max_health | |
self.health = health | |
self.experience = experience | |
self.knocked_out = knocked_out | |
#repr methon (Tells us about the pokemon) | |
def __repr__(self): | |
return "Name: " + self.name + "\nLevel: " + str(self.level) + "\nType: " + self.poke_type + "\nMaximum health: " + str(self.max_health) + "\nCurrent health: " + str(self.curr_health) + "\nExperience: " + str(self.experience) + "\nIs this pokemon knocked out: " + str(self.knocked_out) | |
#lose health method | |
def lose_health(self, value): | |
self.health -= value | |
return "ALERT! " + self.name + "'s health level has decreased!!! \nHis\Her current health: " + str(self.health) | |
#gain health method | |
def gain_health(self, amount): | |
self.health += amount | |
return self.name + " has gained " + str(amount) + " health points!\nCurrent health: " + str(self.health) | |
#knock out method | |
def knock_out(self): | |
self.knocked_out = True | |
self.health = 0 | |
return "ALERT! " + self.name + " has been knocked out! \nCurrent health: " + str(self.health) + "\nIs this pokemon knocked out: " + str(self.knocked_out) | |
#revive pokemon method | |
def revive(self): | |
self.knocked_out = False | |
return self.name + " has been revived!\nCurrent health: " + str(self.health) + "\nIs this pokemon knocked out: " + str(self.knocked_out) | |
#attack method | |
def attack(self, pokemon): | |
#if your type is electric | |
if (self.poke_type == "electric"): | |
if (pokemon.poke_type == "water"): | |
pokemon.health -= (self.level) * 1.5 | |
self.experience += 15 | |
elif (pokemon.poke_type == "fire"): | |
pokemon.health -= self.level | |
self.experience += 10 | |
elif (pokemon.poke_type == "electric"): | |
self.experience += 10 | |
pokemon.health -= self.level | |
elif (pokemon.poke_type == "grass"): | |
self.experience += 10 | |
pokemon.health -= self.level | |
#if your type is water | |
elif (self.poke_type == "water"): | |
if (pokemon.poke_type == "electric"): | |
pokemon.health -= (self.level) * 1.5 | |
self.experience += 15 | |
elif (pokemon.poke_type == "fire"): | |
pokemon.health -= (self.level) * 1.5 | |
self.experience += 15 | |
elif (pokemon.poke_type == "water"): | |
pokemon.health -= self.level | |
self.experience += 10 | |
elif (pokemon.poke_type == "grass"): | |
pokemon.health -= (self.level) * 1.25 | |
self.experience += 12.5 | |
#if your type is fire | |
elif (self.poke_type == "fire"): | |
if (pokemon.poke_type == "electric"): | |
pokemon.health -= (self.level) * 1.5 | |
self.experience += 15 | |
elif (pokemon.poke_type == "water"): | |
pokemon.health -= (self.level) * 0.5 | |
self.experience += 5 | |
elif (pokemon.poke_type == "fire"): | |
pokemon.health -= self.level | |
self.experience += 10 | |
elif (pokemon.poke_type == "grass"): | |
pokemon.health -= self.level | |
self.experience += 10 | |
#if your type is grass | |
elif (self.poke_type == "grass"): | |
if (pokemon.poke_type == "electric"): | |
pokemon.health -= self.level | |
self.experience += 10 | |
elif (pokemon.poke_type == "water"): | |
pokemon.health -= (self.level) * 1.5 | |
self.experience += 15 | |
elif (pokemon.poke_type == "fire"): | |
pokemon.health -= self.level | |
self.experience += 10 | |
elif (pokemon.poke_type == "grass"): | |
pokemon.health -= self.level | |
self.experience += 10 | |
return "You (" + self.name + ") are attacking: " + pokemon.name + "\n" + "(Your) "+ self.name + "'s type is: " + self.poke_type + "\n" + pokemon.name + "'s type is: " + pokemon.poke_type + "\n(Your) " + self.name + "'s level is: " + str(self.level) + "\n" + pokemon.name + "'s health level after " + self.name + "'s attack is: " + str(pokemon.health) + "\n" + self.name + "'s experience is: " + str(self.experience) | |
class Trainer: | |
def __init__(self, name, pokemons, potions, curr_poke, health, level, experience): | |
self.name = name | |
self.pokemons = pokemons | |
self.potions = potions | |
self.curr_poke = curr_poke | |
self.health = health | |
self.level = level | |
self.experience = experience | |
def __repr__(self): | |
return "Name: " + self.name + "\nPokemon's: " + str(self.pokemons) + "\nPotions: " + str(self.potions) + "\nCurrent pokemon: " + self.curr_poke + "\nHealth: " + self.health + "\nLevel: " + self.level + "\nExperience: " + self.experience | |
def attack(self, trainer): | |
return "You (" + self.name + ") are attacking " + trainer.name + "\n" +self.curr_poke.attack(trainer.curr_poke) | |
class Potion: | |
def __init__(self, name, health_points, level_inc, experience_points, who_to_use_on): | |
self.name = name | |
self.health_points = health_points | |
self.experience_points = experience_points | |
self.level_inc = level_inc | |
self.who_to_use_on = who_to_use_on | |
def __repr__(self): | |
return "Potion name: " + self.name + "\nHealth points (for who you use it on): " + str(self.health_points) + "\nExperience points (for you): " + str(self.experience_points) + "\nLevel increase (for you): " + str(self.level_inc) + "\nWho to use this potion on: " + self.who_to_use_on | |
def use_potion(self, who_uses_it, on_who): | |
who_uses_it.experience += self.experience_points | |
who_uses_it.level += self.level_inc | |
on_who.health += self.health_points | |
return "\n" + self.name.upper() + "! " + "\nYou (" + who_uses_it.name + ") are using " + self.name + " on " + on_who.name + ".\nNow " + on_who.name + "'s current health is: " + str(on_who.health) + "\n" + who_uses_it.name + "'s current level is: " + str(who_uses_it.level) + "\n" + who_uses_it.name + "'s experience is: " + str(who_uses_it.experience) | |
"""USING THE POKEMON CLASS""" | |
"""We've got: | |
- A lose health method (lose_health) | |
- A gain health method (gain_health) | |
- A knock out method (knock_out) | |
- A revive method (revive) | |
- An attack method (attack) | |
""" | |
"""POKEMONS""" | |
#Name, level, type, max health, health, experience, is knocked out | |
#Electric pokemons | |
nika = Pokemon("Nika", 100, "electric", 200, 170, 0, False) | |
#Water pokemons | |
ovail = Pokemon("Ovail", 100, "water", 150, 100, 0, False) | |
kyle = Pokemon("Kyle", 100, "water", 150, 100, 0, False) | |
#Fire pokemons | |
chase = Pokemon("Chase", 100, "fire", 150, 100, 0, False) | |
#Grass pokemons | |
grute = Pokemon("Grute", 100, "graww", 150, 100, 0, False) | |
grayora = Pokemon("Grayora", 100, "graww", 150, 0, 100, False) | |
#This is Trainer("Marie")'s current pokemon: | |
tikki = Pokemon("Tikki", 100, "fire", 150, 100, 0, False) | |
#This is Trainer("Ash")'s current pokemon: | |
pikachu = Pokemon("Pickachu", 100, "electric", 200, 170, 0, False) | |
"""POTIONS""" | |
#Name, health, level, experience, who to use on | |
electrify = Potion("Electrify", -50, 59, 5, "Rival") | |
firewall = Potion("FireWall", -50, 50, 5, "Rival") | |
river = Potion("River", -100, 100, 10, "Rival") | |
digdeeper = Potion("Dig Deeper", -100, 75, 7.5, "Rival") | |
"""TRAINERS""" | |
#Name, pokemons, potions, current pokemon, health, level, experience | |
ash_pokes = [pikachu, nika, grute, grayora] | |
mari_pokes = [chase, tikki, ovail, kyle] | |
ash_potions = [] | |
mari_potions = [] | |
ash = Trainer("Asher", ash_pokes, ash_potions, pikachu, 100, 50, 0) | |
mari = Trainer("Mari", mari_pokes, mari_potions, tikki, 100, 50, 0) | |
print(electrify.use_potion(pikachu, nika)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment