-
-
Save codecademydev/cb9910993fe1f37137efe2030511b5e0 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This is our main Pokemon class. We define what the pokemon is, how much health it has, etc. Then we must have methods for health loss, health regaining, reviving knockouts, etc, etc. Also the general game mechanics | |
import random | |
# let's start all over! I can do this! | |
class Pokemon: | |
def __init__(self, name, ptype, is_out, level = 5): | |
self.name = name | |
self.ptype = ptype | |
self.level = level | |
self.mh = level * 5 | |
self.ch = self.mh | |
self.is_out = False | |
def __repr__(self): | |
return "{name} is at {level} and has {health}".format(name = self.name, level = self.level, health = self.ch) | |
def revival(self): | |
if self.is_out == False: | |
print("This pokemon does not need reviving!") | |
else: | |
self.is_out = False | |
self.ch = self.mh | |
print("{name} has been revived and is at {health}!".format(name = self.name, health = self.ch)) | |
def gain_health(self): | |
if self.is_out == True: | |
print("You must revive your pokemon first! Don't fret we'll do it for you!") | |
self.revival() | |
elif self.ch >= self.mh: | |
self.ch = self.mh | |
print("Your pokemon is at max health!") | |
elif self.ch < self.mh: | |
self.ch = self.mh | |
print("{name} now is back at max health and you have one less potion!".format(name = self.name)) | |
def knock_out(self): | |
self.is_out = True | |
if self.ch != 0: | |
self.ch = 0 | |
print("Your pokemon is out of action! You must revive them!") | |
def lose_health(self, amount): | |
self.ch -= amount | |
if self.ch <= 0: | |
self.health = 0 | |
self.knock_out() | |
else: | |
print("{name} now has {health} health.".format(name = self.name, health = self.ch)) | |
def attack(self, opponent): | |
if self.is_out: | |
print("{name} can't attack, that pokemon is knocked out!".format(name = self.name)) | |
if (self.ptype == opponent.ptype) or (self.ptype == 'fire' and opponent.ptype == "poison") or (self.ptype == 'poison' and opponent.ptype == "fire") or (self.ptype == 'ice' and opponent.ptype == "poison") or (self.ptype == 'poison' and opponent.ptype == "ice") or (self.ptype == 'water' and opponent.ptype == "ice") or (self.ptype == 'ice' and opponent.ptype == "water") or (self.ptype == 'poison' and opponent.ptype == "water") or (self.ptype == 'water' and opponent.ptype == "poison"): | |
print("{name} attacked {enemy} for {damage} damage!".format(name = self.name, enemy = opponent.name, damage = self.level)) | |
opponent.lose_health(self.level) | |
#Now we're going to code for the advantages. Remember we are using 5 types fire, water, grass, ice, and poison. Fire beats grass, ice. Water beats fire, grass. Ice beats grass. Poison beats grass. | |
if (self.ptype == "fire" and opponent.ptype == "grass") or (self.ptype == "fire" and opponent.ptype == "ice") or (self.ptype == "water" and opponent.ptype == "grass") or (self.ptype == "water" and opponent.ptype == "fire") or (self.ptype == "ice" and opponent.ptype == "grass") or (self.ptype == "poison" and opponent.ptype == "grass"): | |
print("{name} attacked {enemy} for {damage} damage!".format(name = self.name, enemy = opponent.name, damage = self.level)) | |
print("It's devastating!") | |
opponent.lose_health(self.level * 2) | |
#Now for the disadvantages! Just flip the previous on its head! Pity that grass loses out to everyone! :D | |
if (self.ptype == "grass" and opponent.ptype == "fire") or (self.ptype == "grass" and opponent.ptype == "ice") or (self.ptype == "grass" and opponent.ptype == "water") or (self.ptype == "grass" and opponent.ptype == "poison") or (self.ptype == "fire" and opponent.ptype == "water"): | |
print("{name} attacked {enemy} for {damage} damage!".format(name = self.name, enemy = opponent.name, damage = self.level)) | |
print("It's lackluster!") | |
opponent.lose_health(round(self.level * 0.5)) | |
class Charmeleon(Pokemon): | |
def __init__(self, level = 5): | |
super().__init__("Charmeleon", "fire", level) | |
class Wartortle(Pokemon): | |
def __init__(self, level = 5): | |
super().__init__("Wartortle", "water", level) | |
class Vulpix(Pokemon): | |
def __init__(self, level = 5): | |
super().__init__("Vulpix", "ice", level) | |
class Tangela(Pokemon): | |
def __init__(self, level = 5): | |
super().__init__("Tangela", "grass", level) | |
class Nidoran(Pokemon): | |
def __init__(self, level = 5): | |
super().__init__("Nidoran", "poison", level) | |
class Trainer: | |
def __init__(self, name, stable, current_poke, potion = 5): | |
self.name = name | |
self.poke = stable | |
self.potion = potion | |
self.current_poke = self.poke[current_poke] | |
def __repr__(self): | |
print("The trainer is called {name} and currently has {potion} potion(s). His current pokemon is {current_poke} and has these pokemon: ".format(name = self.name, current_poke = self.current_poke, potion = self.potion)) | |
for mons in self.poke: | |
print(mons) | |
def attack_other_trainer(self, enemy): | |
if self.current_poke.is_out: | |
print("You can't fight now! {name} is knocked out!".format(name = self.current_poke)) | |
else: | |
self.current_poke.attack(enemy) | |
def switch_pokemon(self, new_poke): | |
if new_poke < len(self.poke) and new_poke >= 0: | |
if self.poke[new_poke].is_out: | |
print("{name} is out of action! You can't make it your active pokemon!".format(new_poke)) | |
elif new_poke == self.poke: | |
print("But that pokemon is already your active one!") | |
else: | |
self.current_poke = new_poke | |
print("Now {name} is your active pokemon!".format(name = self.poke[self.current_poke].name)) | |
def use_potion(self, potion): | |
if self.potion <= 0: | |
print("You cannot heal your pokemon! You have no more potions left!") | |
elif self.potion > 0: | |
self.potion -= 1 | |
self.current_poke.gain_health() | |
Charlie = Charmeleon() | |
Iceboy = Vulpix() | |
MaryJane = Tangela() | |
Waterman = Wartortle() | |
Ninja = Nidoran(9) | |
trainer_main = Trainer("Chainsaw",[Charlie, Iceboy], 1, 5) | |
trainer_enemy = Trainer("Buzzcut",[Ninja, Waterman], 0, 5) | |
trainer_main.attack_other_trainer(trainer_enemy) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment