Esempio n. 1
0
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
Esempio n. 2
0
 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()
Esempio n. 3
0
 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
Esempio n. 4
0
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 setUp(self):
		"""put what is needed to set up the test in this section"""
		""" 
		create an instance of the Create class the we can leverage its functions in tests.
		"""
		""" make the things that all of the tests will need"""

		self.creature = Creature()
Esempio n. 6
0
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))
Esempio n. 7
0
 def load_game(self, slot):
     self.slot = slot
     with open('save%d.json' % slot) as f:
         d = json.loads(f.read())
     self.party_gold = d['gold']
     self.pc_position = GameTile.from_string(d['pc_position'])
     self.level = d['level']
     self.party_food = d['food']
     self.map.level = self.level
     for key in d['inventory_dump']:
         item_class = items.ITEMS[key][0]
         item_args = items.ITEMS[key][1]
         self.inventory.append(item_class(*item_args))
     self.pc_list = [
         Creature.dict_load(pc, self.inventory) for pc in d['pcs']
     ]
     self.map.load_dict(d['map'])
     self.map.board[self.pc_position].on_step(self)
Esempio n. 8
0
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()
Esempio n. 9
0
 def calculate_light(self):
     creatures = [Creature.by_id(c) for c in self.__creatures]
     sources = set((c.where_is(), c.light) for c in creatures if c.light > 0)
     statlight = set(i for i in self.statics if i.light not in [None, 0])
     if sources != self.sources:
         self.lightmap = [[self.ambient_light] * self.w for i in range(self.h)]
         for s in statlight:
             d = int((s.light - 1) ** 0.5)
             for lx in range(max(0, s.x - d), min(self.w, s.x + d + 1)):
                 for ly in range(max(0, s.y - d), min(self.h, s.y + d + 1)):
                     self.lightmap[ly][lx] += int(s.light / (((s.x - lx) ** 2 + (s.y - ly) ** 2) + 1))
         for c in creatures:
             z = c
             if z:
                 zx, zy = z.where_is()
                 if z.light > 0:
                     d = int((z.light - 1) ** 0.5)
                     for lx in range(max(0, zx - d), min(self.w, zx + d + 1)):
                         for ly in range(max(0, zy - d), min(self.h, zy + d + 1)):
                             self.lightmap[ly][lx] += int(z.light / (((zx - lx) ** 2 + (zy - ly) ** 2) + 1))
     self.sources = sources
Esempio n. 10
0
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()
Esempio n. 11
0
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()
Esempio n. 12
0
 def get_hero(self):
     for c in self.__creatures:
         if Creature.by_id(c).controlled_by_player:
             return Creature.by_id(c)
     raise Exception("No hero found")
Esempio n. 13
0
 def get_creatures(self):
     return [Creature.by_id(c) for c in self.__creatures]
Esempio n. 14
0
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],
Esempio n. 15
0
def next_step_monster(new_x,new_y):
    if (rendered_map[new_x][new_y] == "."):
        return True
    else:
        return False

# Generating the player's initial position randomly
player_need_position = True
while(player_need_position):
    y = random.randint(0,max_y)
    x = random.randint(0,max_x)
    if (rendered_map[x][y] == "."):
        player_need_position = False

# Make the player
player = Creature(140,20,20,"@")

# Put the player onto the map
rendered_map[x][y] = player.symbol
player.move(x,y)

# Print the first iteration of the map
print_map(rendered_map)

# main game loop
while(still_playing):
    
    rendered_map = copy.deepcopy(board)
    d = screen.getkey()
    screen.addstr(len(rendered_map),0,"                     ") # worst hack ever
class CreatureAttackTest(unittest.TestCase):
	"""
	by putting unittest.TestCase within the parens, CreatureAttackTest is inheriting from unittest.TestCase
	"""

	# Make the tings and do the setup needed by all tests in the test case:
	def setUp(self):
		"""put what is needed to set up the test in this section"""
		""" 
		create an instance of the Create class the we can leverage its functions in tests.
		"""
		""" make the things that all of the tests will need"""

		self.creature = Creature()





	def teadDown(self):
		"""
		put what was needed for test and needs to be deleted to 'clean up' after test
		"""

		del self.creature


	def test_attack_return_int(self):
		"""
		Ensure that when attack is called, an int is returned.
		"""
		# Call the attack function of creature, 
		# and catch what it returns in value

		# make a variable
		value = self.creature.attack()

		self.assertIsInstance(value, int, "Reurned atk value is not an int")
		"""
		Assert function is used because if tells python to provide test feedback
		 """

	def test_no_weapon_return_base_damage(self):
	 	"""
	 	Ensure that with no weapon equiped, the creature does its base damage.
	 	"""

	 	#manually set the base damage to 3
	 	self.creature.attack_points = 2

	 	#get the creature's attack value
	 	value = self.creature.attack()

	 	self.assertEqual(value, 2, "expected base attack value not given." )

	def test_with_weapon_return_damage(self):
	 	"""
	 	Ensure that with a weapon, the creature does base damage + Weapon damage.
	 	"""
	 	# Make a weapon to give to creature
	 	weapon = Weapon (3)

	 	# Give the weapon to the creature
	 	self.weapon = mace

	 	# Set the creature's base attack value
	 	self.creature.attack_points = 2

	 	# Get the creature's total attack value
	 	value = self.creature.attack()

	 	# Assert the attack value is the base + weapon damage
	 	self.assertEqual(value, 5, "Computed attack value is not correct." )
Esempio n. 17
0
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))
Esempio n. 18
0
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,
Esempio n. 19
0
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))
Esempio n. 20
0
 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