Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import random
- def get_input():
- return input('-->')
- class Player:
- def __init__(self, name, maxhealth, description, attack, defense, damage):
- self.name = name
- self.maxhealth = maxhealth
- self.health = self.maxhealth
- self.description = description
- self.attackbonus = attack
- self.defense = defense
- self.damage = damage
- def __str__(self):
- print("Name: ", self.name, "\n""Health: ", self.health, "\n""Description: ", self.description, "\n""Attack: ",
- self.attackbonus, "\n""Defense: ", self.defense, "\n""Damage: ", self.damage)
- class Monster:
- def __init__(self, name, maxhealth, description, attack, defense, damage, xp, category):
- self.name = name
- self.maxhealth = maxhealth
- self.health = self.maxhealth
- self.description = description
- self.attackbonus = attack
- self.defense = defense
- self.damage = damage
- self.xp = xp
- self.category = category
- def __str__(self):
- print("Name: ", self.name, "\n""Description: ", self.description, "\n""Category: ", self.category,
- "\n""Health: ", self.health, "\n""Attack: ", self.attackbonus, "\n""Defense: ", self.defense,
- "\n""Damage: ", self.damage, "\n""XP: ", self.xp)
- player = Player(name="Henk", maxhealth=100, description="Human player", attack=10, defense=10, damage=10)
- goblin = Monster(name="Goblin", description="Goblin", category="Humanoid", defense=15, maxhealth=7, attack=4, damage=6, xp=50)
- hobgoblin = Monster(name="Hobgoblin", description="Hobgoblin", category="Humanoid", defense=18, maxhealth=11, attack=3, damage=8, xp=10)
- goblinboss = Monster(name="Goblin Boss", description="Goblin Boss", category="Humanoid", defense=17, maxhealth=21, attack=4, damage=6, xp=200)
- skeleton = Monster(name="Skeleton", description="Skeleton", category="Undead", defense=13, maxhealth=13, attack=4, damage=6, xp=50)
- zombie = Monster(name="Zombie", description="Zombie", category="Undead", defense=8, maxhealth=22, attack=3, damage=6, xp=50)
- ghoul = Monster(name="Ghoul", description="Ghoul", category="Undead", defense=12, maxhealth=22, attack=2, damage=6, xp=200)
- class Actions:
- def encounter(self):
- self.player = player
- enemytype = random.randint(1, 10)
- if 1 <= enemytype <= 6:
- self.enemy = goblin
- elif 7 <= enemytype <= 9:
- self.enemy = hobgoblin
- elif enemytype == 10:
- self.enemy = goblinboss
- self.fight()
- def fight(self):
- if self.enemy.health <= 0:
- print("The %s died of it's wounds." % self.enemy.description)
- return Game().start()
- if self.player.health <= 0:
- print("You died!")
- return Game().main_menu()
- else:
- print("""You see a %s blocking your way.
- What do you want to do?
- 1. Attack
- 2. Run""" % self.enemy.description)
- fight_option = get_input()
- if fight_option == "1":
- return self.attack()
- elif fight_option == "2":
- return self.runaway()
- else:
- print("You didn't make a valid choice try again.")
- return self.fight()
- def attack(self):
- if random.randint(1, 20) + self.player.attackbonus >= 10 + self.enemy.defense:
- self.hit = random.randint(1, self.player.damage)
- print("You hit the %s for %s damage!" % (self.enemy.description, self.hit))
- self.enemy.health -= self.hit
- else:
- print("You missed!")
- if random.randint(1, 20) + self.enemy.attackbonus >= 10 + self.player.defense:
- self.hit = random.randint(1, self.enemy.damage)
- print("You are hit for %s damage!" % self.hit)
- self.player.health -= self.hit
- print("You have %s hitpoints left." % self.player.health)
- else:
- print("You dodged the attack!")
- return self.fight()
- def runaway(self):
- run = random.randint(1, 10)
- if 1 <= run <= 8:
- print("You managed to run away.")
- else:
- print("You didn't managed to run away.")
- return self.fight()
- class Game:
- def main_menu(self):
- print("""This is the mainmenu of the game.
- 1. Start
- 2. Exit""")
- option = get_input()
- if option == "1":
- self.start()
- elif option == "2":
- sys.exit()
- else:
- self.main_menu()
- def start(self):
- print("""You stand in an empty room.
- 1. Go to next room.
- 2. Show current stats
- 3. Exit""")
- option = get_input()
- if option == "1":
- Actions().encounter()
- elif option == "2":
- print(player.__str__())
- return self.start()
- elif option == "3":
- sys.exit()
- else:
- print("You didn't make a valid choice try again.")
- return self.main_menu()
- Game().main_menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement