def game_loop(): creatures = [ Creature('Toad', 1), Creature('Tiger', 12), Creature('Bat', 3), Creature('Dragon', 50), Creature('Evil Wizard', 1000) ] hero = Wizard('Gandalf', 75) while True: active_creature = random.choice(creatures) print('A {} of level {} has appeared from the forbidden forest...'.format(active_creature.name, active_creature.level)) cmd = input('Do you want to [a]ttack, [l]ook around or [r]un away?') if cmd == 'a': if hero.attack(active_creature): creatures.remove(active_creature) else: print('{} has been defeated and must hide in the forest to regain his strength'.format(hero.name)) time.sleep(5) print('{} has regained his strength and is ready to wander forth'.format(hero.name)) elif cmd == 'l': print('{} has a look around and sees...') for c in creatures: print(' * {} of level {}'.format(c.name, c.level)) elif cmd == 'r': print('The Wizard has become unsure of his power and flees...') else: print('Exiting game, bye!') break
def new_game(self, slot): self.slot = slot self.party_gold = 0 self.party_food = 400 self.level = 1 self.map.level = 1 self.pc_list = [ Creature('Fighter', is_pc=True), Creature('Barbarian', is_pc=True), Creature('Archer', is_pc=True), Creature('Wizard', is_pc=True), Creature('Enchantress', is_pc=True), ] self.pc_position = self.map.gen_random()
def main(): print_header() creatures = [ Creature("Bat", 5), Creature("Toad", 1), Creature("Tiger", 12), Dragon("Black Dragon", 50, False), Wizard("Evil Wizard", 1000) ] hero = Wizard("Harry", 75) while True: active_creature = random.choice(creatures) print( f"A {active_creature.name} of level {active_creature.level} has appear from a dark and foggy forest...\n" ) cmd = input("Do you [a]ttack, [r]unaway, or [l]ook around? ") if cmd == "a": if hero.attack(active_creature): creatures.remove(active_creature) print(f"The wizard defeated {active_creature.name}") else: print( f"The wizard has been defeat by the powerful {active_creature.name}" ) elif cmd == "r": print("The wizard has become unsure of his power and flees!!!") elif cmd == "l": print( f"The wizard {hero.name} takes in the surroundings and sees: ") for c in creatures: print(f" * {c.name} of level {c.level}") else: print("OK, exiting game ... bye!") break if not creatures: print("You've defeated all the creatures, well done!") break print()
def main_loop(): creatures = [ Small_creatures("Toad", 1), Creature("Tiger", 12), Small_creatures("wolf", 9), Creature("crocodile", 20), Small_creatures("dog", 6), Creature("dwarf", 30), Dragon("Dragon", 50, 20, True), Wizard("Evil Wizard", 1000) ] hero = Wizard("gandolf", 75) # print(creatures) while True: active_creature = random.choice(creatures) print('A {} of level {} has appeared from the foggy forest'.format( active_creature.name, active_creature.level)) print('') cmd = input( "What do you want to do ? [a]ttack, [r]un or [l]ookaround ") if cmd == "a": if hero.attack(active_creature): creatures.remove(active_creature) else: print("The wizard needs to rest for a while") time.sleep(5) print("Wizard returns revitalized") elif cmd == "r": print("The Wizard runs beacuase he doesn't want to fight") elif cmd == "l": print("the wizard {} lookaround and sees :".format(hero.name)) for c in creatures: print("* A {} of level {}".format(c.name, c.level)) else: print("ok exiting") break if not creatures: print("The Wizard {} has defeated all creatures".format(hero.name))
def spawn_creatures(self, pcs, mobs): i = 0 for pc, gt in pcs: if pc.health > 0: pc.set_in_combat(self, GameTile(*gt), i) i += 2 i = 1 mob_zone = [ gt for gt in GameTile.all_tiles(self.MAP_RADIUS) if gt.y < -3.25 ] for mobdef in mobs: gt = random.choice(mob_zone) mob_zone.remove(gt) c = Creature(mobdef) c.set_in_combat(self, gt, i) i += 2
def game_loop(): creatures = [ SmallAnimal('Toad', 1), Creature('Tiger', 12), SmallAnimal('Bat', 3), Dragon('Red Dragon', 50, 75, True), Wizard('Evil Wizard', 150) ] hero = Wizard('Gandelf', 75) while True: active_creature = random.choice(creatures) print( f'A {active_creature.name} of level {active_creature.level} has appeared from the forest.' ) cmd = input("Do you [a]ttack, [r]un away or [l]ook around? ") print() if cmd == 'a': if hero.attack(active_creature): creatures.remove(active_creature) else: print('The wizard runs away to recover from battle...') time.sleep(3) print('The wizard returns, ready to fight!') elif cmd == 'r': print('The Wizard is unsure of his power and runs away!') elif cmd == 'l': print(f'Wizard {hero.name} takes a long look around and sees:') for c in creatures: print(f'A {c.name} of level {c.level}') else: print('Exiting game, bye') break if not creatures: print('You killed all the creatures!') break print()
def game_loop(): creatures = [ SmallAnimal('Toad', 1), Creature('Tiger', 12), SmallAnimal('Bat', 3), Dragon('Dragon', 50, 20, True), Wizard('Evil Wizard', 100) ] hero = Wizard('Magic Mike', 75) while True: active_creature = random.choice(creatures) print('A {} of level {} has appeared in front of you'.format(active_creature.name, active_creature.level)) cmd = input('Do you [a]ttack, [r]unaway, or [l]ook around?') if cmd == 'a': if hero.attack(active_creature): creatures.remove(active_creature) else: print('You run away to recuperate') time.sleep(5) print('You are now ready to go forth again') elif cmd == 'r': print('You flee in terror, screaming like a frightened child.') elif cmd == 'l': print('You look around and see:') for c in creatures: print(' * A {} of level {}'.format(c.name, c.level)) else: print('Exiting Game') break if not creatures: print("You've done it! All your enemies have been vanquished!") break print()
from random import randint, shuffle import math import matplotlib.pyplot as plt import numpy as np from creatures import Creature plt.style.use('fivethirtyeight') creaturelist = [ Creature(0, randint(-100, 100), randint(-100, 100), 0, 0) for i in range(100) ] fig = plt.figure() ax = fig.add_subplot(1, 1, 1) creaturelist.extend([ Creature(1, -randint(-100, 100), randint(-100, 100), 20, 10) for i in range(50) ]) creaturelist.extend([ Creature(2, -randint(-100, 100), randint(-100, 100), 20, 10) for i in range(10) ]) while True: ax.clear() ax.scatter([creature.x for creature in creaturelist], [creature.y for creature in creaturelist],
def create_creature(Creature: Creature, config): return Creature(name=config.get("name", "creature"), replication_chance=config.get("replication_chance", 0.1), death_chance=config.get("death_chance", 0.1))
space.gravity = 0, 0 space.damping = 0.95 # basically global friction for every body # defining genome and genes of creature karl_genome = Genome() shape_gene = Gene("shape", [0.4, 0.8, 0.7, 0.3]) width_gene = Gene("width", 50) length_gene = Gene("length", 200) thr1_gene = Gene("thruster", [1, True, 0, 90]) thr2_gene = Gene("thruster", [3, True, 90, 180]) karl_genepool = [shape_gene, width_gene, length_gene, thr1_gene, thr2_gene] # adding genes to karl karl_genome.append_genes(karl_genepool) # creating creature with given genome karl = Creature(karl_genome) karl.birth() space.add(karl.body, karl.shape) # temporary obstacle setup line_moment = pymunk.moment_for_segment(0, (0, 0), (500, 300), 10) line_body = pymunk.Body(10, line_moment, body_type=pymunk.Body.STATIC) line_body.position = (350, -80) line_shape = pymunk.Segment(line_body, (0, 0), (500, 300), 10) space.add(line_shape) # Main loop game_running = True while game_running: ev = pygame.event.poll()
from collections import namedtuple from creatures import make_kart, Creature from objects import town_objects Level = namedtuple( "Level", "m num_gobbos num_villagers num_gold time inhabitants objects name") shopkeeper1 = Creature(47, 3, "v", 17, "shoppo") shopkeeper1.speek = "Welcome to the Flaming Cauldron, home to some of the greatest potions in the underdark." shopkeeper2 = Creature(47, 9, "v", 17, "shoppo") shopkeeper2.speek = "Gooday, traveler. What kind of magical clothing do you wish to buy from Devon Malikar's Mystical Garb?" shopkeeper3 = Creature(2, 3, "v", 17, "shoppo") shopkeeper3.speek = "So, how can we help you here at the Useful Junk Shoppe?" old_wizardio = Creature(45, 19, "R", 1, "wizardio") old_wizardio.speek = "I hear you are going into the gobblin stronghold. 'Tis a perilous place. You shall need this." levels = [ Level(m="floorplan_0.txt", name="The Begining", num_gobbos=0, num_villagers=5, num_gold=0, time=99999, inhabitants=[old_wizardio], objects=[]), Level(m="floorplan.txt", name="Surface Stronghold", num_gobbos=5, num_villagers=0, num_gold=5,
def game_loop(): creatures = \ [SmallAnimal('Toad', 1), SmallAnimal('Bat', 3), Creature('Wolf', 12), Dragon('Dragon', 50, scaliness=20, breathes_fire=True), Wizard('Evil Wizard', 500)] settings = [ 'Misty forest', 'Dark lake', 'Rickety bridge', 'Mysterious cave', 'Derelict shack' ] character_name = input('Please input your name: ') character = Wizard(character_name, 75) print() print('The Wizard {0} starts their journey seeking after the evil wizard. ' '{0} gets the feeling that evil creatures are close.'.format( character_name)) print('{} is level {}'.format(character_name, character.level)) print() while creatures: active_creature = random.choice(creatures) active_setting = random.choice(settings) print('{} stumbles upon a {}'.format(character_name, active_setting)) print() print('A level {0} {1} appears from the {2}.'.format( active_creature.level, active_creature.name, active_setting)) print() action = input( 'Would you like to [A]ttack, [R]un, [L]ook around or E[x]it game?: ' ) print() if action.lower().strip() == 'a': if character.attack(active_creature): creatures.remove(active_creature) character.level = character.level + (active_creature.level * 0.5) print('{} has grown to level {}.'.format( character_name, character.level)) print('-----------------------') else: print('{} cowers and flees to rest and recover.'.format( character_name)) time.sleep(10) character.level = character.level + (active_creature.level / 3) print( '{} returns, having grown to level {} from the mistakes of the previous battle.' .format(character_name, character.level)) print('-----------------------') elif action.lower().strip() == 'r': print( 'The Wizard {} fears their powers are not strong enough to match the {} and flees.' .format(character_name, active_creature.name)) print('-----------------------') elif action.lower().strip() == 'l': print('{} takes in the {} and sees foes circling.'.format( character_name, active_setting)) print('The remaining foes: ') for c in creatures: print('The {} of level {}.'.format(c.name, c.level)) print('-----------------------') elif action.lower().strip() == 'x': print('Okay, leaving the game') break else: print('Please enter a valid command.') if not creatures: print( '{} has been triumphant, all the evil creatures have been banished!' .format(character_name))
def apply_ability(self, creature, target): super().apply_ability(creature, target) from creatures import Creature c = Creature(self.defkey) c.set_in_combat(creature.combat, target, creature.next_action + 100) c.is_pc = creature.is_pc