import time #Class for creating monsters class Monster(object): def __init__(self, name, level): self.name = name self.level = level self.alive = True if self.level == 1: self.exp = 10 self.gold = 100 self.health = 50 self.damage = 5 elif self.level == 2: self.exp = 25 self.gold = 250 self.health = 100 self.damage = 10 elif self.level == 3: self.exp = 50 self.gold = 500 self.health = 250 self.damage = 25 def attack(self): import random randomnum = random.randrange(0,3) if randomnum < 2: return self.damage # if User.health > self.damage: # User.health -= self.damage # print(self.name + " attacked you!") if randomnum == 3: self.blocking = True # print(self.name + " attempted to block the attack!") # else: # User.health = 0 # print("Oh no! You were killed by " + self.name + "!") #Class for creating Boss Monsters class BossMonster(Monster): def __init__(self, name, level): self.name = name self.level = level self.alive = True if self.level == 1: self.exp = 100 self.gold = 1000 self.health = 100 self.damage = 20 self.megaSwipeDamage = 40 self.scrapeDamage = 30 self.biteDamage = 35 self.abilities = [self.megaSwipeDamage, self.scrapeDamage, self.biteDamage] self.abilityNames = ["Mega Swipe", "Scrape", "Bite"] elif self.level == 2: self.exp = 250 self.gold = 2500 self.health = 200 self.damage = 40 self.fireBreathDamage = 65 self.megaSwipeDamage = 60 self.toxicOozeDamage = 70 self.abilities = [self.fireBreathDamage, self.megaSwipeDamage, self.toxicOozeDamage] self.abilityNames = ["Fire Breath", "Mega Swipe", "Toxic Ooze"] elif self.level == 3: self.exp = 500 self.gold = 5000 self.health = 500 self.damage = 75 self.fireBreathDamage = 100 self.toxicOozeDamage = 110 self.ultimateAttackDamage = 125 self.abilities = [self.fireBreathDamage, self.toxicOozeDamage, self.ultimateAttackDamage] self.abilityNames = ["Fire Breath", "Toxic Ooze", "Ultimate Attack"] def attack(self): import random randomnum = random.randrange(1,11) if randomnum > 3: if User.health > self.damage: User.health -= self.damage print(self.name + " attacked you!") else: User.health = 0 print("Oh no! You were killed by the boss " + self.name + "!") else: import random randomnum = random.randrange(0,3) self.tempUltimate = self.abilities[randomnum] if User.health > self.tempUltimate: User.health -= self.tempUltimate print(self.name + " used " + self.abilityNames[randomnum] + "!") else: User.health = 0 print(self.name + " used " + self.abilityNames[randomnum] + "!") print("Oh no! You were killed by the boss " + self.name + "!") #Class for player creation. (Might be useful for possible multiplayer.) class Player(object): def __init__(self, name): self.name = name self.exp = 0 self.level = 1 self.inv = [] self.health = 100 self.damage = 10 self.gold = 0 self.maxhealth = 100 def levelup(self): if self.level == 1: if self.exp >= 100: self.level = 2 self.damage = 25 self.maxhealth = 150 if self.level == 2: if self.exp >= 250: self.level = 3 self.damage = 50 self.maxhealth = 250 if self.level == 3: if self.exp >= 500: self.level = 4 self.damage = 100 self.maxhealth = 400 if self.level == 4: if self.exp >= 750: self.level = 5 self.damage = 125 self.maxhealth = 500 if self.level == 5: if self.exp >= 1000: self.level = 6 self.damage = 150 self.maxhealth = 750 def attack(self, monster): self.levelup() if monster.health > self.damage: monster.health -= self.damage print("You attacked " + monster.name + "!") else: print(self.name + " killed " + str(monster.name) + "!") monster.health = 0 self.exp += monster.exp self.gold += monster.gold self.levelup() monster.alive = False def displayStats(self): print("Your name is: " + self.name + ".") print("You have " + str(self.exp) + " experience.") print("You are at level " + str(self.level) + ".") print("The items you have are: " + str(self.inv)) print("You are at " + str(self.health) + "/" + str(self.maxhealth) + " health.") print("You currently deal " + str(self.damage) + " damage.") print("You have " + str(self.gold) + " gold.") print("\n \n") def block(self): print("You attempted to block the attack!") def makeMonster(level): import random randomnum = random.randrange(0, 6) monster = Monster(monsternames[randomnum], level) return monster def useItem(item): if item.used == False: if item.itemtype == "health": if User.maxhealth - User.health > item.amount: User.health += amount print("Healed by " + str(item.amount) + ".") item.used = True elif item.itemtype == "maxheal": User.maxhealth += item.amount print("Added " + str(item.amount) + " to max health.") item.used = True elif item.itemtype == "damage": User.damage += item.amount print("Damage increased by " + str(item.amount) + ".") item.used = True elif item.itemtype == "experience": User.experience += item.amount print("Added " + str(item.amount) + " experience.") item.used = True User.levelup() def debugMenu(): loop = True while loop == True: print("\n \n") print("This is the debug menu.") print("1. Open the admin menu. (Not currently functioning.)") print("2. Open the shop.") #print("3. Use an item.") print("3. Leave debug menu.") tempinput = input() if tempinput == "2": shop(User) elif tempinput == "3": loop = False print("\n \n") monsternames = ["Sugar", "Cupcake", "Tiger", "Creampuff", "David", "Fluffy"] print("Hello! Welcome to Wesley's Text Game!") playername = input("What would you like your name to be? ") User = Player(playername) tempinput = input("Would you like to see your info? Y/N: ") if tempinput == "y": print("\n \n") User.displayStats() else: print("\n \n") print("Okay then!") print("\n \n") time.sleep(3) print("You wake up in a cold, dark room.") #Story line stuff commented out down here. Work on later. #monster1 = makeMonster(1) #print("\n \n \n") #print("You seem to be in the first room of a large set of rooms. You look around.") #print("Oh no! In this room, there seems to be a monster! The monster's name is " + monster1.name + ".") #battleNormal(monster1) #boss1 = BossMonster("Harold", 1) #print("That was close! You managed to defeat the monster!") #print("But it seems that there is another one lurking in the shadows.") #print("It's a boss!") #print("The boss's name is " + boss1.name + ".") #User.health = 99999 #battleBoss(boss1) #monster1 = Monster("Harold", 1) #Battle.battleNormal(monster1, User) #User.gold = 10000 #shop(User)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question