Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Combat RPG
- # By Ethan Dee © 2019
- import math
- import random as rd
- import os
- # Common class shared by all classes
- class Common:
- def __init__(self):
- self.fullhp = 100
- self.hp = 100
- self.damage = 0
- def is_not_used(self):
- pass
- # Main attack function
- def attack(self, weapon):
- if self == enemy:
- if self.hp > 0:
- prevhp = player.hp
- player.hp -= enemy.damage
- print(f"The {enemy.name} attacks you and deals {prevhp - player.hp} damage")
- if "shield" in str(player.inv):
- player.hp += 5
- print("You had a shield and blocked 5 damage")
- input("Press enter to continue...")
- clear()
- else:
- input("Press enter to continue...")
- clear()
- else:
- prevhp = enemy.hp
- if weapon == 0:
- enemy.hp -= player.damage
- print(f"You punch the {enemy.name} and deal {prevhp - enemy.hp} damage.")
- else:
- if "shield" in str(weapon):
- print("You can't attack with a shield!")
- input("Press enter to continue...")
- clear()
- else:
- weapondamage = weapons[weapon]
- enemy.hp -= weapondamage
- print(f"You strike the {enemy.name} with your {weapon} and deal {prevhp - enemy.hp} damage.")
- # Enemy class shared by all enemies
- class Enemy(Common):
- def health(self):
- return f"Enemy Health:{self.hp}/{self.fullhp}"
- # Player class
- class Player(Common):
- def __init__(self):
- super(Common, self).__init__()
- self.fullhp = 100
- self.hp = 100
- self.damage = rd.randint(3, 7)
- self.inv = []
- self.infected = False
- # Print health bar
- def health_bar(self):
- healthbar = (math.floor(self.hp / 10))
- t1 = "#" * int(healthbar)
- num = 10 - healthbar
- t2 = " " * num
- return f"Health:[{t1 + t2}]{self.hp}/100"
- # ####Enemy Classes#### #
- class Wolf(Enemy):
- def __init__(self):
- super(Enemy, self).__init__()
- self.name = "Wolf"
- self.fullhp = 50
- self.hp = 50
- self.damage = rd.randint(5, 10)
- self.dead = False
- class TaintedWarrior(Enemy):
- def __init__(self):
- super(Enemy, self).__init__()
- self.name = "Tainted Warrior"
- self.fullhp = 110
- self.hp = 110
- self.damage = rd.randint(10, 15)
- self.dead = False
- class Zombie(Enemy):
- def __init__(self):
- super(Enemy, self).__init__()
- self.name = "Zombie"
- self.fullhp = 15
- self.hp = 15
- self.damage = rd.randint(5, 10)
- self.dead = False
- def bite(self):
- self.is_not_used()
- if "shield" in str(player.inv):
- print("You had a shield wich protected you from the zombie bite")
- elif rd.randint(1, 4) == 2:
- print("The zombie bites you and infects you which deals 5 damage to you each turn.")
- player.infected = True
- input("Press enter to continue...")
- # Function used to clear screen and print player health and enemy health
- def clear():
- os.system("cls")
- print(player.health_bar())
- print(f"Enemy:{enemy.name}")
- print(enemy.health())
- print(f"Infected:{player.infected}")
- print(f"Inventory:{player.inv}\n")
- weapons = {"rusty broadsword": 20,
- "knight's broadsword": 40,
- "battle axe": 75,
- "boko shield": 0}
- enemies = [Zombie(), Wolf(), TaintedWarrior()]
- player = Player()
- enemy = rd.choice(enemies)
- # Main loop
- while player.hp > 0:
- enemy = rd.choice(enemies)
- enemy.hp = enemy.fullhp
- clear()
- print(f"You encountered a {enemy.name}.")
- while enemy.hp > 0 or enemy.dead is False:
- if enemy.hp <= 0:
- break
- if player.hp <= 0:
- res = input("You Died! Play again?")
- if res == "yes":
- player.hp = 100
- player.inv = []
- player.infected = False
- break
- else:
- break
- if player.infected is True:
- clear()
- print("Player infected, loose 5 hp")
- player.hp -= 5
- choice = input("What do you want to do?\n1.Fight \n2.Run \n3.Cry\n")
- if choice == "1":
- clear()
- if len(player.inv) == 0:
- if enemy.name == "Zombie":
- player.attack(0)
- enemy.attack(0)
- enemy.bite()
- else:
- player.attack(0)
- enemy.attack(0)
- else:
- if enemy.name == "Zombie":
- enemy.bite()
- yn = input("Your inventory contains 1 or more weapons. \nWould you like to use one? yes/no\n")
- if yn == "yes":
- wepdict = {}
- for i in range(len(player.inv)):
- print(f"{i}.{player.inv[i]}")
- wepdict[i] = player.inv[i]
- wepchoice = input("Which one?")
- player.attack(wepdict[int(wepchoice)])
- enemy.attack(0)
- input("Press enter to continue...")
- clear()
- else:
- if enemy.name == "Zombie":
- enemy.bite()
- player.attack(0)
- enemy.attack(0)
- elif choice == "2":
- if rd.randint(1, 2) == 1:
- clear()
- randweapon = rd.choice(list(weapons))
- if randweapon in player.inv:
- randweapon = rd.choice(list(weapons))
- else:
- print(f"As you run you pick up a {randweapon}.")
- player.inv += [randweapon]
- input("Press enter to continue...")
- clear()
- if rd.randint(1, 2) == 1:
- clear()
- print(f"You were able to escape the {enemy.name}.")
- enemy.dead = True
- input("Press enter to continue...")
- clear()
- else:
- clear()
- print(f"The {enemy.name} is still hot on your heels and you can't escape.")
- enemy.attack(0)
- elif choice == "3":
- clear()
- print(f"You cry against a tree and are brutally murdered by the {enemy.name}.\n")
- player.hp = 0
- input("Press enter to continue...")
- if enemy.hp <= 0:
- print(f"The {enemy.name} dies and you continue on your journey.")
- input("Press enter to continue...")
- input("Press enter to close...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement