diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/__pycache__/character.cpython-39.pyc b/__pycache__/character.cpython-39.pyc new file mode 100644 index 0000000..1e3659a Binary files /dev/null and b/__pycache__/character.cpython-39.pyc differ diff --git a/__pycache__/hero.cpython-39.pyc b/__pycache__/hero.cpython-39.pyc new file mode 100644 index 0000000..4c95a3a Binary files /dev/null and b/__pycache__/hero.cpython-39.pyc differ diff --git a/__pycache__/weapons.cpython-39.pyc b/__pycache__/weapons.cpython-39.pyc new file mode 100644 index 0000000..0e70eaa Binary files /dev/null and b/__pycache__/weapons.cpython-39.pyc differ diff --git a/character.py b/character.py new file mode 100644 index 0000000..cc4fcef --- /dev/null +++ b/character.py @@ -0,0 +1,20 @@ +class Character: + def __init__(self, name, health=100, power=5): + self.name = name + self.health = health + self.power = power + + def attack(self, other_person): + other_person.health -= self.power + print(f'\n{self.name} does {self.power} damage to {other_person.name}') + + def is_alive(self): + self.health > 0 + + # def print_status(self): + # return f'{self.name} has {self.health} and {self.power}.' + + def __str__(self): + return f'{self.name} has {self.health} HP and {self.power} power.' + + diff --git a/hero.py b/hero.py new file mode 100644 index 0000000..5ba59e1 --- /dev/null +++ b/hero.py @@ -0,0 +1,37 @@ +# class Hero: +# def __init__(self, name, health=10, power=5): +# self.name = name +# self.health = health +# self.power = power + +# def attack(self, bad_person): +# bad_person.health -= self.power +# print(f'You do {self.power} damage to the goblin.') + +# def is_alive(self): +# self.health > 0 + +# def print_status(self): +# print(f'You have {self.health} and {self.power}') + + +# class Goblin: +# def __init__(self, name, health=6, power=2): +# self.name = name +# self.health = health +# self.power = power + +# def attack(self, good_person): +# good_person.health -= self.power +# print(f'The goblin does {self.power} damage to you.') + +# def is_alive(self): +# self.health > 0 + +# def print_status(self): +# print(f'The goblin has {self.health} and {self.power}') + + + + + diff --git a/rpg-0.py b/rpg-0.py index 3551493..fbf174d 100644 --- a/rpg-0.py +++ b/rpg-0.py @@ -1,47 +1,121 @@ -""" -In this simple RPG game, the hero fights the goblin. He has the options to: +from character import Character +from weapons import Weapons +import random + +# ---------------- + +inventory = [] +banana = Weapons('Banana', 2) +sword = Weapons('Sword', 8) +monkey_bomb = Weapons('Monkey Bomb', 6) +duck = Weapons('DigitalCrafts Duck', 5) +bootcamp = Weapons('Coding Bootcamp',10) -1. fight goblin -2. do nothing - in which case the goblin will attack him anyway -3. flee -""" def main(): - hero_health = 10 - hero_power = 5 - goblin_health = 6 - goblin_power = 2 - - while goblin_health > 0 and hero_health > 0: - print("You have %d health and %d power." % (hero_health, hero_power)) - print("The goblin has %d health and %d power." % (goblin_health, goblin_power)) - print() - print("What do you want to do?") - print("1. fight goblin") - print("2. do nothing") - print("3. flee") + user_hero = input('What would you like to name your hero? ') + # hero = Character(user_hero) + goblin = Character('Goblin', health=20, power=4) + mamagoblin = Character('Mama Goblin', health=50, power=12) + special = int(input(f""" +What special would you like, {user_hero}? +1. MAX HP +2. + 10 Power +3. Cuddly Pet +> """)) + if special == 1: + hero = Character(user_hero, health=500) + print("\nYOU NOW HAVE A MAX HP OF 500.") + elif special == 2: + hero = Character(user_hero, power=15) + print("\n*10 POWER HAS BEEN ADDED*") + elif special == 3: + hero = Character(user_hero) + cuddlypet = Character('Cuddly Pet', health=99999, power=500) + # inventory.append(cuddlypet.name) + print(f"\n{cuddlypet.name} stored in inventory.") + + while hero.is_alive and goblin.is_alive: + print(f''' +~~~~~~~~~~CURRENT STATS~~~~~~~~~~~ +{hero} +{goblin} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~''') print("> ",) - user_input = input() - if user_input == "1": - # Hero attacks goblin - goblin_health -= hero_power - print("You do %d damage to the goblin." % hero_power) - if goblin_health <= 0: + print("""What do you want to do? +1: Punch goblin +2: Nothing +3. Flee """) + user_input = input('> ') + if user_input == '1': + hero.attack(goblin) + if goblin.health <= 0: print("The goblin is dead.") - elif user_input == "2": + # exit() + break + elif user_input == '2': pass - elif user_input == "3": - print("Goodbye.") + elif user_input == '3': + print(f"You escaped goblin.") break else: - print("Invalid input %r" % user_input) + print(f"Invalid input: {user_input}") + if goblin.is_alive: + goblin.attack(hero) + if hero.health <= 0: + print("You are dead.") + exit() + + if goblin.health <= 0: + print("\nMama Goblin did not like that.") + else: print("\nWhile fleeing, you encountered another fiend.") - if goblin_health > 0: - # Goblin attacks hero - hero_health -= goblin_power - print("The goblin does %d damage to you." % goblin_power) - if hero_health <= 0: + while hero.is_alive and mamagoblin.is_alive: + print(f''' +~~~~~~~~~~CURRENT STATS~~~~~~~~~~~ +{hero} +{mamagoblin} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~''') + user_input_2 = int(input('''What would you like to do? +1. Spin mystery box +2. Use Cuddly Pet to attack +3. Attempt to hug Mama Goblin +> ''')) + if user_input_2 == 1: + mystery_box = [sword, banana, monkey_bomb, bootcamp] + choice = random.choice(mystery_box) + print(f'{choice.use(mamagoblin)}') + if choice == bootcamp: + print("It was super effective!") + if mamagoblin.health <= 0: + print('Mama Goblin is ded') + exit() + elif user_input_2 == 2 and special == 3: + cuddlypet.attack(mamagoblin) + if mamagoblin.health <= 0: + print("""OVERKILL! Cuddly Pet is OP and needs a nerf! +Mama Goblin was demolished.""") + exit() + if user_input_2 == 2 and special != 3: + print("You do not have Cuddly Pet in your inventory.") + elif user_input_2 == 3: + mamagoblin.attack(hero) + print("Hug attempt not very effective.") + if mamagoblin.is_alive and user_input_2 != 3: + mamagoblin.attack(hero) + if hero.health <= 0: print("You are dead.") + exit() + + + + + + + + + +# Need to add try and except for invalid inputs ? main() diff --git a/weapons.py b/weapons.py new file mode 100644 index 0000000..5dd3e6b --- /dev/null +++ b/weapons.py @@ -0,0 +1,10 @@ +class Weapons: + def __init__(self, name, power): + self.name = name + self.power = power + + def use(self, enemy): + enemy.health -= self.power + return f'\n{self.name} did {self.power} damage to {enemy.name}' + +