Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added __init__.py
Empty file.
Binary file added __pycache__/character.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/hero.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/weapons.cpython-39.pyc
Binary file not shown.
20 changes: 20 additions & 0 deletions character.py
Original file line number Diff line number Diff line change
@@ -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.'


37 changes: 37 additions & 0 deletions hero.py
Original file line number Diff line number Diff line change
@@ -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}')





142 changes: 108 additions & 34 deletions rpg-0.py
Original file line number Diff line number Diff line change
@@ -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()
10 changes: 10 additions & 0 deletions weapons.py
Original file line number Diff line number Diff line change
@@ -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}'