import os import sys import random class Water: def __init__(self, name): self.name = name self.type = "Water" self.level = 1 self.maxhealth = 150 self.health = self.maxhealth self.base_attack = 15 self.attack = self.base_attack self.inventory = [] self.equiped = [] self.xp = 0 self.xpneed = 100 self.gold = 115 self.pots = 0 class Fire: def __init__(self, name): self.name = name self.type = "Fire" self.level = 1 self.maxhealth = 100 self.health = self.maxhealth self.base_attack = 25 self.attack = self.base_attack self.inventory = [] self.equiped = [] self.xp = 90 self.xpneed = 100 self.gold = 0 self.pots = 0 class Earth: def __init__(self, name): self.name = name self.type = "Earth" self.level = 1 self.maxhealth = 250 self.health = self.maxhealth self.base_attack = 10 self.attack = self.base_attack self.inventory = [] self.equiped = [] self.xp = 0 self.xpneed = 100 self.gold = 0 self.pots = 0 class Air: def __init__(self,name): self.name = name self.type = "Air" self.level = 1 self.maxhealth = 150 self.health = self.maxhealth self.base_attack = 15 self.attack = self.base_attack self.inventory = [] self.equiped = [] self.xp = 0 self.xpneed = 100 self.gold = 0 self.pots = 0 class enemyWater: def __init__(self, name): self.name = name self.type = "Water" self.maxhealth = 150 self.health = self.maxhealth self.base_attack = 15 self.attack = self.base_attack self.goldgain = 5 self.potgain = 1 self.xpgain = 10 WaterIG = enemyWater("Water Dragon") class enemyFire: def __init__(self, name): self.name = name self.type = "Fire" self.maxhealth = 100 self.health = self.maxhealth self.base_attack = 25 self.attack = self.base_attack self.goldgain = 5 self.potgain = 1 self.xpgain = 10 FireIG = enemyFire("Fire Dragon") class enemyEarth: def __init__(self, name): self.name = name self.type = "Earth" self.maxhealth = 250 self.health = self.maxhealth self.base_attack = 10 self.attack = self.base_attack self.goldgain = 5 self.potgain = 1 self.xpgain = 10 EarthIG = enemyEarth("Earth Dragon") class enemyAir: def __init__(self,name): self.name = name self.type = "Air" self.maxhealth = 150 self.health = self.maxhealth self.base_attack = 15 self.attack = self.base_attack self.goldgain = 5 self.potgain = 1 self.xpgain = 10 AirIG = enemyAir("Air Dragon") def main(): os.system('cls') print("1.) start") print("2.) load") print("3.) quit") option = raw_input("->") if option == "1": start() elif option == "2": main() elif option == "3": quit() else: main() def start(): os.system('cls') print("Hello young dragon!") print("What is your name?") name = raw_input("->") print("What type of dragon are you?") print("1.) Water") print("2.) Fire") print("3.) Earth") print("4.) Air") global PlayerIG type = raw_input("->") if type == "1": PlayerIG = Water(name) elif type == "2": PlayerIG = Fire(name) elif type == "3": PlayerIG = Earth(name) elif type == "4": PlayerIG = Air(name) else: start() start1() def start1(): os.system('cls') if PlayerIG.health > PlayerIG.maxhealth: PlayerIG.health = PlayerIG.maxhealth if PlayerIG.xp >= PlayerIG.xpneed: levelup() print("Name: %s") % PlayerIG.name print("Type: %s") % PlayerIG.type print("Level: %i") % PlayerIG.level print("Xp: %i/%i") % (PlayerIG.xp, PlayerIG.xpneed) print("Health: %i/%i") % (PlayerIG.health, PlayerIG.maxhealth) print("Attack: %i") % PlayerIG.attack print("Inventory: %s") % PlayerIG.inventory print("Equiped items: %s") % PlayerIG.equiped print("Gold: %i") % PlayerIG.gold print("Potions: %i\n") % PlayerIG.pots print("1.) Fight") print("2.) Drink potion") print("3.) Shop") print("4.) Equip") print("5.) Save") print("6.) Quit") option = raw_input("->") if option == "1": prefight() elif option == "2": potion() elif option == "3": shop() elif option == "4": equip() elif option == "5": start1() elif option == "6": quit() else: start1() def prefight(): os.system('cls') global enemy enemynum = random.randint(1, 4) if enemynum == 1: enemy = WaterIG if PlayerIG.type == "Air": PlayerIG.attack*=2 elif enemynum == 2: enemy = FireIG if PlayerIG.type == "Water": PlayerIG.attack*=2 elif enemynum == 3: enemy = EarthIG if PlayerIG.type == "Fire": PlayerIG.attack*=2 else: enemy = AirIG fight() def fight(): os.system('cls') print("%s vs %s") % (PlayerIG.name, enemy.name) print("%i/%i %i/%i") % (PlayerIG.health, PlayerIG.maxhealth, enemy.health, enemy.maxhealth) print("Potions: %i\n") % PlayerIG.pots print("1.) Attack") print("2.) Drink potion") print("3.) Run") option = raw_input("->") if option == "1": attack() elif option == "2": midPotion() elif option == "3": run() else: fight() def attack(): damage = random.uniform(PlayerIG.attack/4, PlayerIG.attack) if damage == PlayerIG.attack/4: print("You missed!") else: enemy.health -= damage print("You delt %i damage!") % damage raw_input() if enemy.health <= 0: win() else: os.system('cls') enemydamage = random.uniform(enemy.attack/4, enemy.attack*1.5) if enemydamage == enemy.attack/4: print("The %s missed") % enemy.name else: PlayerIG.health -= enemydamage print("The %s delt %i damage") % (enemy.name, enemydamage) raw_input() if PlayerIG.health <= 0: loose() else: fight() def win(): os.system('cls') print("You have defeted the %s") % enemy.name enemy.health = enemy.maxhealth PlayerIG.gold += enemy.goldgain PlayerIG.pots += enemy.potgain PlayerIG.xp += enemy.xpgain PlayerIG.attack = PlayerIG.base_attack raw_input() start1() def loose(): os.system('cls') print("You have been defeted!") raw_input() main() def potion(): if PlayerIG.pots >= 1: print("You drank a potion!") PlayerIG.health += 30 PlayerIG.pots -= 1 else: print("You do not have any potions!") raw_input() start1() def midPotion(): if PlayerIG.pots >= 1: print("You drank a potion!") PlayerIG.health += 30 PlayerIG.pots -= 1 if PlayerIG.health > PlayerIG.maxhealth: PlayerIG.health = PlayerIG.maxhealth else: print("You do not have any potions!") raw_input() os.system('cls') enemydamage = random.randint(enemy.attack/4, enemy.attack) if enemydamage == enemy.attack/4: print("The %s missed") % enemy.name else: PlayerIG.health -= enemydamage print("The %s delt %i damage") % (enemy.name, enemydamage) raw_input() if PlayerIG.health <= 0: loose() else: fight() def run(): runnum = random.randint(1,5) if runnum <= 4: print("You could not escape!") raw_input() os.system('cls') enemydamage = random.randint(enemy.attack/4, enemy.attack) if enemydamage == enemy.attack/4: print("The %s missed!") % enemy.name else: PlayerIG.health -= enemydamage print("The %s delt %i damage!") % (enemy.name, enemydamage) raw_input() if PlayerIG.health <= 0: loose() else: fight() else: print("You escaped!") raw_input() start1() def levelup(): os.system('cls') print("You have earned enough xp to level up! These are your current stats") print("Name: %s") % PlayerIG.name print("Level: %i") % PlayerIG.level print("Health: %i/%i") % (PlayerIG.health, PlayerIG.maxhealth) print("Attack: %i") % PlayerIG.attack raw_input() os.system('cls') PlayerIG.maxhealth*=1.5 PlayerIG.health = PlayerIG.maxhealth PlayerIG.base_attack*=1.5 PlayerIG.attack = PlayerIG.base_attack PlayerIG.xp = 0 PlayerIG.xpneed*=2 PlayerIG.level+=1 PlayerIG.equiped = [] print("These are your new stats!") print("Name: %s") % PlayerIG.name print("Level: %i") % PlayerIG.level print("Health: %i/%i") % (PlayerIG.health, PlayerIG.maxhealth) print("Attack: %i") % PlayerIG.attack raw_input() start1() def shop(): os.system('cls') print("Welcome to the shop!") raw_input() print("What would you like?") print("1.) Potions-5") print("2.) Iron armour-65") print("3.) Steel claws") print("4.) Leave") option = raw_input("->") if option == "1": print("That will be 5 gold") raw_input() if PlayerIG.gold >= 5: PlayerIG.gold -= 5 PlayerIG.pots += 1 print("You have purchased a potion!") raw_input() shop() else: print("You do not have enough gold!") raw_input() shop() elif option == "2": if PlayerIG.gold >= 65: PlayerIG.gold -= 65 PlayerIG.inventory.append("Iron armour") print("You brought the set of Iron armour") raw_input() shop() else: print("You don't have enough money!") raw_input() shop() elif option == "3": if PlayerIG.gold >= 50: PlayerIG.gold -= 50 PlayerIG.inventory.append("Steel claws") print("You brought the Steel claws") raw_input() shop() else: print("You don't have enough money") raw_input() shop() elif option == "4": start1() else: print("I don't own that item!") raw_input() shop() def equip(): os.system('cls') print("What would you like to equip? or if ou want to leave type 'l'") print("%s") % PlayerIG.inventory option = raw_input("->") if option == "1": PlayerIG.equiped.append(PlayerIG.inventory[0]) if PlayerIG.inventory[0] == "Iron armour": PlayerIG.maxhealth += 20 PlayerIG.health = PlayerIG.maxhealth PlayerIG.attack += 5 elif PlayerIG.inventory[0] == "Steel claws": PlayerIG.attack += 10 print("You have equiped the %s") % PlayerIG.inventory[0] raw_input() equip() elif option == "2": PlayerIG.equiped.append(PlayerIG.inventory[1]) if PlayerIG.inventory[1] == "Iron armour": PlayerIG.maxhealth += 20 PlayerIG.health = PlayerIG.maxhealth PlayerIG.attack += 5 elif PlayerIG.inventory[1] == "Steel claws": PlayerIG.attack += 10 print("You have brought the %s") % PlayerIG.inventory[1] raw_input() equip() elif option == "l": start1() else: print("You don't own that item") raw_input() equip() main()
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