Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- import random
- import pdb
- def get_input():
- return input('-->')
- def bug():
- pdb.set_trace()
- class Player:
- def __init__(self, name, maxhealth, description, attack, defense, damage, dodge, stamina, armor):
- self.name = name
- self.maxhealth = maxhealth
- self.health = self.maxhealth
- self.description = description
- self.attackbonus = attack
- self.defense = defense
- self.damage = damage
- self.dodge = dodge
- self.stamina = stamina
- self.armor = armor
- def __str__(self):
- print("Name: ", self.name, "\n""Health: ", self.health, "\n""Description: ", self.description, "\n""Attack: ",
- self.attack, "\n""Defense: ", self.defense, "\n""Damage: ", self.damage, "\n""Dodge: ", self.dodge, "\n"
- "Stamina: ", self.stamina, "\n""Armor: ", self.armor)
- 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.attack = 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.attack, "\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, dodge=10, stamina=10, armor=2)
- 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)
- # part 2. setting actions
- # a player should be able to do something, and the same goes for a monster
- # make sure both players and monsters can attack vs defense, gain or loose health and run away
- # also maybe you want to save the 'state' of the player
- # further, write down 3-5 monster categories
- # No need to go into deep detail and complex methods
- # class methods/static variables
- # set the monster categories as a class value to use as choice. and loading a character is a class method
- 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("""This is the mainmenu of the game.
- 1. Fight
- 2. Show current stats
- 3. Exit""")
- option = get_input()
- if option == "1":
- self.encounter()
- elif option == "2":
- self.stats()
- elif option == "3":
- sys.exit()
- else:
- print("You didn't make a valid choice try again.")
- return self.main_menu()
- def encounter(self):
- 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 stats(self):
- print(player.__str__())
- return self.main_menu()
- def fight(self):
- if self.enemy.health <= 0:
- print("The %s died of it's wounds." % self.enemy.description)
- else:
- print("""What do you want to do?
- 1. Attack
- 2. Run""")
- fight_option = get_input()
- if fight_option == "1":
- return self.attack()
- else:
- return self.runaway()
- def attack(self):
- self.player = player
- self.strike = random.randint(1, 20) + self.player.attackbonus
- self.mob_armor = 10 + self.enemy.defense
- if self.strike >= self.mob_armor:
- 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!")
- return self.fight()
- Game().main_menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement