def main(): pat = Hero('Pat') gobbles = Goblin('gobbles') while gobbles.is_alive and pat.is_alive: # print("You have %d health and %d power." % (pat.health, pat.power)) print(pat.health_power_status()) # print("The gobbles has %d health and %d power." % (gobbles.health, gobbles.power)) print(gobbles.health_power_status()) print() print("What do you want to do?") print("1. fight gobbles") print("2. do nothing") print("3. flee") print("> ", ) user_input = input() if user_input == "1": pat.attack(gobbles) elif user_input == "2": pass elif user_input == "3": print("Goodbye.") break else: print("Invalid input %r" % user_input) if gobbles.health > 0: gobbles.attack(pat) pat.die() gobbles.die()
def generateFoes(hero): monsters = [] number_of_monsters = int( raw_input("Welcome %s, how many monsters will you fight?\n> " % (hero.name))) for i in range(number_of_monsters): random_int = random.randint(1, 3) if random_int == 1: monsters.append(Goblin()) elif random_int == 2: monsters.append(Vampire()) elif random_int == 3: monsters.append(Dragon()) return monsters
def main(): # hero_health = 10 # hero_power = 5 # goblin_health = 6 # goblin_power = 2 hero = Hero("Lancelot", 10, 3) goblin = Goblin("Cretan", 8, 1) zombie = Zombie("Zombo", 5, 2) enemy = goblin while enemy.is_alive() and hero.is_alive(): hero.print_status() enemy.print_status() print() print("What do you want to do?") print("1. fight enemy") print("2. do nothing") print("3. flee") print("> ",) user_input = input() if user_input == "1": # Hero attacks enemy hero.attack(enemy) print("You do %d damage to the enemy." % hero.power) if not enemy.is_alive(): print("The enemy is dead.") elif user_input == "2": pass elif user_input == "3": print("Goodbye.") break else: print("Invalid input %r" % user_input) if enemy.is_alive(): # Goblin attacks hero enemy.attack(hero) print("The enemy does %d damage to you." % goblin.power) if not hero.is_alive(): print("You are dead.")
def generateWave(self): waveEnemies = [Goblin(), Beast(), Boss()] #only spawn enemies if wave spawn counter is greater than 0, keeps track of how many enemies we need to generate if self.waveSpawnCounter > 0: randEnemy = choice(waveEnemies, 1, p=[.5, .3, .2]) # append enemy object into our list of enemies self.enemies.append(randEnemy[0]) #decrement the count self.waveSpawnCounter -= 1 # if there are no more enemies to be spawned if self.waveSpawnCounter == 0: #make sure that there are no enemies in the list, meaning that round is over if len(self.enemies) == 0: self.wave += 1 self.waveSpawnCounter = self.wave * 5 #set pause back to true self.pause = True #change the image self.playPauseButton.changeImage()
import time from Hero import Hero from Battle import Battle from Goblin import Goblin from Store import Store from Wizard import Wizard from Spider import Spider from Snake import Snake from Medic import Medic from Shadow import Shadow from Zombie import Zombie if __name__ == "__main__": hero = Hero() enemies = [ Goblin(), Wizard(), Medic(), Shadow(), Zombie(), Spider(), Snake() ] battle_engine = Battle() shopping_engine = Store() for enemy in enemies: hero_won = battle_engine.do_battle(hero, enemy) if not hero_won: print("YOU LOSE!") exit(0)
# Contrib Modules - stuff we had to install #Core Modules - stuff thats already part of python, that we need import os #operating system from random import randint #get specifically the randint method from the random class # Custom modules - python modules we made! #from FILENAME.py import CLASS/member #basics of inheritance in Python from character import Character from Goblin import Goblin heroName = raw_input("What is thy name, brace adventurer? ") theHero = Character(heroName, 10, 5) # print theHero.name goblin = Goblin() # print goblin.health while goblin.is_alive() and theHero.is_alive(): print "You have %d health and %d power." % (theHero.health, theHero.power) print "%s has %d health and %d power" % (goblin.name, goblin.health, goblin.power) user_input = raw_input() if user_input == "1" goblin.take_damage(theHero.power) theHero.take_damage(goblin.power)
Legolas Frodo Aragon Gimbly Gandolf """ hero_name = raw_input("Who will you be in this fellowship? ") #there is only one hero theHero = Hero(hero_name, 4) theHero.cheer_hero() while (theHero.is_alive()): #while there are many monsters randMonster = randint(1, 2) if randMonster == 1: monster = Goblin() else: monster = Orc() print "you have encountered the terrifying %s" % monster.name while (theHero.is_alive() and monster.is_alive()): print """ _ _,-----------._ ___ (_,.- _,-'_,-----------._`-._ _)_) | ,'_,-' ___________ `-._`. ,',' _,-'___________`-._ `.`. ,',' ,'_,-' . `-._`. `.`. /,' ,',' >|< `.`. `.'
# Import relevant files and modules from Hero import Hero from Vampire import Vampire from Goblin import Goblin from Boss import Boss import asciiArt import dialogue import os # Get player name and instantiate a Hero object, and goblin object hero_name = raw_input("What is your name? ") theHero = Hero(hero_name) theHero.cheer_hero monster = Goblin() # hard code monster speed so you can't run away from first fight monster.speed = 15 # begin game loop while theHero.is_alive(): # print opening dialogue and first fight sequence print dialogue.openingSequence print asciiArt.goblin # begin while loop for first fight, necessary to move game along while theHero.health > 0 and monster.health > 0: print dialogue.battleStats % (theHero.health, theHero.power, monster.name, monster.health, monster.power) theHero.battle_choice() player_choice = raw_input("> ") if player_choice == "1": #fight monster.take_damage(theHero.power) print dialogue.battleStats % (theHero.health, theHero.power,
background1_velx = -5 else: background1_velx = 0 else: background1_velx = 0 if jugador.rect.x < -20: jugador.rect.x = -20 # Control Generadores for g in generadores: if g.temp < 0 and numero_goblins > 0: centro = list(g.rect.center) goblin = Goblin([centro[0], centro[1]], matriz_goblin) numero_goblins -= 1 g.temp = 30 print centro[0], centro[1] goblins.add(goblin) g.f_velx = background1_velx # Barra #posf_x = 110 # Control Goblins for g in goblins: if pygame.sprite.collide_circle(jugador, g): g.accion = 2 g.velx = 0
from Hero import Hero from Goblin import Goblin from Vampire import Vampire from random import randint #LOOK UP INHERITANCE hero_name = raw_input("What is your name, brave one? ") theHero = Hero(hero_name, 5) theHero.cheer_hero() gameOn = True while (gameOn): randMonster = randint(1, 2) if randMonster == 1: monster = Goblin() else: monster = Vampire() print "You have encountered the terrifying %s" % monster.name while (gameOn and theHero.isAlive() and monster.isAlive()): message = """ You have %d health and %d power. The %s has %d health and %d power. What do you want to do? 1. fight the %s 2. get jiggy with it 3. flee """
-.| | ; _.-'|| - ||`.!| || | ||_|,'| | |, || ;'|_,-'' - - `.`| || | ___|| ||\| |,', , | | | - - - ) '|__||\ || | \|,',' ; | | - - - |\ \\ || |_,',' /| | ; - - \\ \\|| |',' / | |/ \\ \|| |' """ print "How many monsters are you will to fight, brave %s?" % hero.name number_of_enemies = int(raw_input("> ")) # Load up the monster table based on user input...randomize which monster for i in range(0, number_of_enemies): rand_num = randint(0, 1) if(rand_num == 1): monsters.append(Goblin()) else: monsters.append(Vampire()) # Let the battles begin! battleEngine = BattleEngine() shoppingEngine = ShoppingEngine() for i, monster in enumerate(monsters): # enumerate hero_won = battleEngine.battle(hero, monster) if not hero_won or not hero.is_alive(): print "These foes have proven to be too powerful for you. Better luck next time!" break elif i < len(monsters):
import os from random import randint # 3rd party # pygame for instance here # Custom modules from Hero import Hero from Goblin import Goblin from Vampire import Vampire # from characters import Hero, Goblin # instantiate a hero object from the Hero class the_hero = Hero() # ditto a_goblin = Goblin() possible_monsters = [Goblin(), Vampire()] # possible_monsters[0]() # Make a list to hold all our monsters monsters = [] # Before the game starts, let's ask the hero for his or her name. print "What is thy name, brave adventurer?" the_hero.name = raw_input("> ") the_hero.cheer_for_hero() print "How many monsters are you willing to fight, brave %s?" % the_hero.name number_of_enemies = int(raw_input("> "))
import os import random from Hero import Hero from Goblin import Goblin from Vampire import Vampire hero_name = raw_input("What is your name?") theHero = Hero(hero_name, random.randint(10, 20), 0) theHero.cheer_hero() while (theHero.is_alive()): randMonster = random.randint(1, 2) if randMonster == 1: monster = Goblin(random.randint(10, 20)) else: monster = Vampire(random.randint(10, 20)) print "You have encountered the terrifying %s" % monster.name while (theHero.is_alive() and monster.is_alive()): message = """ You have %d health and %d power. The %s has %d health and %d power. What do you want to do? 1. fight %s 2. dance 3. flee 4. use potion 5. powerup""" print message % (theHero.health, theHero.power, monster.name, monster.health, monster.power, monster.name) user_input = raw_input() if user_input == "1": monster.take_damage(theHero.power)
# os.system("say Hooray. Thou hast killed the monster!") print("You have killed the monster!") Hero.reset_buffs(theHero) has_rested = False monster.giveGold(theHero) monsters_slain += 1 input(""" Hit enter to continue.""") os.system("clear") break input(""" Hit enter to continue.""") os.system("clear") if monsters_slain < 3: if randMonster == 1: monster = Goblin() if randMonster == 2: monster = Vampire() valid = True print("You have encountered the %s!" % monster.name) while (theHero.is_alive() and monster.is_alive()): player_can_move = True if valid == True: monsterResult = monster.getMonsterAction(theHero, monster) else: monsterResult = monster.getMonsterAction( theHero, monster, monsterResult) valid = True if monsterResult == "stun": player_can_move = False if player_can_move == True: