Example #1
0
    def place_objects(self, room):
        """Place random objects in a room."""
        # Choose random number of monsters
        for i in xrange(SS.map_rand.randrange(cfg.MAX_ROOM_MONSTERS)):
            x = SS.map_rand.randrange(room.x1 + 1, room.x2 - 1)
            y = SS.map_rand.randrange(room.y1 + 1, room.y2 - 1)

            # Don't place monsters on the up stairs, as that's where the player
            # will be placed.
            if not self.blocks_movement(x, y) and (x, y) != self.upstairs:
                if SS.map_rand.randrange(0, 100) < 60:
                    mon = Monster(x, y, 'orc', ai=ai.StupidAI())
                else:
                    mon = Monster(x, y, 'troll', ai=ai.StupidAI())

                mon.place_on_map(self)

        # Choose random number of items
        for i in xrange(SS.map_rand.randrange(cfg.MAX_ROOM_ITEMS)):
            x = SS.map_rand.randrange(room.x1 + 1, room.x2 - 1)
            y = SS.map_rand.randrange(room.y1 + 1, room.y2 - 1)

            if not self.blocks_movement(x, y):
                dice = SS.map_rand.randrange(0, 100)
                if dice < 40:
                    item = Item(x, y, 'healing potion')
                elif dice < 40 + 20:
                    item = Item(x, y, 'scroll of fireball')
                elif dice < 40 + 20 + 20:
                    item = Item(x, y, 'scroll of lightning')
                else:
                    item = Item(x, y, 'scroll of confusion')

                item.place_on_map(self)
Example #2
0
class AttackTest(unittest.TestCase):

    """Test Monster Class attack function"""

    def setUp(self):
        print(self.shortDescription())
        self.test_monster = Monster("The Boogie Monster")

    def test_ideal_attack(self):
        """test ideal attack, won't ko"""
        self.assertEqual(5, self.test_monster.attack(5))

    def test_kod_attack(self):
        """test kod attack"""
        self.test_monster.attack(15)
        self.assertEqual("K.O.'d", self.test_monster.status)

    def test_incorrect_type_attack(self):
        """test if we prevent bad types"""
        with self.assertRaises(TypeError):
            self.test_monster.attack("some bad types")

    def test_negative_healt(self):
        """we should test for negative health catches"""
        pass
	def __init__(self):

		Hero.__init__(self)
		Monster.__init__(self)


		self.where = "on shoulders"
Example #4
0
 def __init__(self,
              x,
              y,
              name,
              oid=None,
              ai=None,
              hp=None,
              max_hp=None,
              mp=None,
              max_mp=None,
              death=None,
              fov_radius=cfg.TORCH_RADIUS,
              inventory=None):
     if death is None:
         death = player_death
     Monster.__init__(self,
                      x,
                      y,
                      name,
                      oid=oid,
                      ai=ai,
                      hp=hp,
                      max_hp=max_hp,
                      mp=mp,
                      max_mp=max_mp,
                      death=death,
                      fov_radius=fov_radius,
                      inventory=inventory)
Example #5
0
def creat_monster(screen, monsters, monster_wid, monster_number, number_row):
    monster = Monster(screen)

    monster.x = monster_wid + 2 * monster_wid * monster_number
    monster.rect.x = monster.x
    monster.rect.y = monster.rect.height + 2 * monster.rect.height * number_row
    monsters.add(monster)
Example #6
0
 def __possibleMonsters(self):
     return {
         "Rat":
         Monster(
             name="Rat",
             health=30,
             attack=10,
             defense=15,
             speed=50,
             reward_min=1,
             reward_max=5,
         ),
         "Gnoll":
         Monster(
             name="Gnoll",
             health=60,
             attack=30,
             defense=40,
             speed=20,
             reward_min=5,
             reward_max=10,
         ),
         "Wolf":
         Monster(
             name="Wolf",
             health=40,
             attack=25,
             defense=30,
             speed=60,
             reward_min=10,
             reward_max=15,
         ),
     }
Example #7
0
class InTokyoTest(unittest.TestCase):
    """Test the functionality of the Monster class in_tokyo function."""

    def setUp(self):
        self.new_monster = Monster("Cookie")

    def tearDown(self):
        del self.new_monster

    def test_in_tokyo_yes(self):
        """Set status to "In Tokyo" on a Monster class object, new_monster.
        Check that in_tokyo() returns True."""
        self.new_monster.status = "In Tokyo"
        self.assertEqual(self.new_monster.in_tokyo(), True)

    def test_in_tokyo_no(self):
        """Set status to "" on a Monster class object, new_monster.
        Check that in_tokyo() returns False."""
        self.new_monster.status = ""
        self.assertEqual(self.new_monster.in_tokyo(), False)

    def test_in_tokyo_invalid(self):
        """Set status to -78.3 on a Monster class object, new_monster.
        Check that in_tokyo() returns False."""
        self.new_monster.status = -78.3
        self.assertEqual(self.new_monster.in_tokyo(), False)
Example #8
0
class InTokyoTest(unittest.TestCase):
    """Test the functionality of the Monster class in_tokyo function."""
    def setUp(self):
        self.new_monster = Monster("Cookie")

    def tearDown(self):
        del self.new_monster

    def test_in_tokyo_yes(self):
        """Set status to "In Tokyo" on a Monster class object, new_monster.
        Check that in_tokyo() returns True."""
        self.new_monster.status = "In Tokyo"
        self.assertEqual(self.new_monster.in_tokyo(), True)

    def test_in_tokyo_no(self):
        """Set status to "" on a Monster class object, new_monster.
        Check that in_tokyo() returns False."""
        self.new_monster.status = ""
        self.assertEqual(self.new_monster.in_tokyo(), False)

    def test_in_tokyo_invalid(self):
        """Set status to -78.3 on a Monster class object, new_monster.
        Check that in_tokyo() returns False."""
        self.new_monster.status = -78.3
        self.assertEqual(self.new_monster.in_tokyo(), False)
Example #9
0
class ResetTest(unittest.TestCase):

    """Test Monster Class reset function"""

    def setUp(self):
        print(self.shortDescription())
        self.test_monster = Monster("The Boogie Monster")
        self.test_monster.health = 5
        self.test_monster.victory_points = 5
        self.test_monster.status = "waka"
        self.test_monster.victory_points = 2
        self.test_monster.reset()

    def test_health_status(self):
        """is our health 10"""
        self.assertEqual(10, self.test_monster.health)

    def test_victory_points(self):
        """victory should be 0"""
        self.assertEqual(0, self.test_monster.victory_points)

    def test_status(self):
        """status should be Out of tokyo"""
        self.assertEqual("Out of Tokyo", self.test_monster.status)

    def test_name(self):
        """our name should be boogie monster"""
        self.assertEqual("The Boogie Monster", self.test_monster.name)
Example #10
0
	def __init__(self):
		# Takes this instance(self) of Monster and adds all init properties from Monster class
		Monster.__init__(self)
		# Takes this instance(self) of Monster and adds all init properties from Monster class
		Hero.__init__(self)
		#MonsterHero to have a second weapon
		self.second_weapon = "second weapon!"
Example #11
0
class MonsterResetTest(unittest.TestCase):

    def setUp(self):
        self.monsta = Monster()
        print(self.shortDescription())

    def test_valid_health_reset(self):
        """
        Tests for valid health reset
        """
        self.monsta.health = 5
        self.monsta.reset()
        expected = 10
        actual = self.monsta.health

        assertEqual(expected, actual)

    def test_valid_victory_reset(self):
        """
        Tests for valid victory point reset
        """
        self.monsta.victory_points = 5
        self.monsta.reset()
        expected = 0
        actual = self.monsta.victory_points

        assertEqual(expected, actual)
class test_attack(unittest.TestCase):
    def setUp(self):
        self.monsta = Monster()
        print(self.shortDescription())

    #Tests if heal function works
    def test_attack_live(self):
        self.monsta.health = 6
        expected = 1
        actual = self.monsta.attack(5)
        self.assertEqual(expected, actual)

    #Heal function should not work if total > 10
    def test_attack_die(self):
        self.monsta.health = 4
        expected = -1
        actual = self.monsta.attack(5)
        self.assertEqual(expected, actual)

    #Tests if invalid output was printed
    @patch ('sys.stdout', new_callable=StringIO)
    def test_attack_die_KO(self, mock_stdout):
        health = self.monsta.health(4)

        expected = "K.O.'d"
        actual = self.monsta.attack(6)
        self.assertNotEqual(mock_stdout.getValue(), text)
Example #13
0
class InTokyoTest(unittest.TestCase):
    """Test Monster Class in_tokyo function"""
    def setUp(self):
        print(self.shortDescription())
        self.test_monster = Monster("The Boogie Monster")

    def test_is_in_tokyo_on_init(self):
        """check if we initialize correctly"""
        self.assertEqual("Out of Tokyo", self.test_monster.status)

    def test_is_not_in_tokyo(self):
        """return False if we're not in tokyo"""
        self.assertFalse(self.test_monster.in_tokyo())

    def test_is_in_tokyo(self):
        """check if return is true, when status is 'In Tokyo'"""
        self.test_monster.status = "In Tokyo"
        self.assertTrue(self.test_monster.in_tokyo())

    def test_is_non_default_dirty_status(self):
        """check if return is false, when status is not the default or 'In Tokyo'"""
        self.test_monster.status = "H e double hockey sticks o"
        self.assertFalse(self.test_monster.in_tokyo())

    def test_is_bad_type(self):
        """check if return is false, when status is not the default or 'In Tokyo'"""
        self.test_monster.status = ["H e double hockey sticks o"]
        self.assertFalse(self.test_monster.in_tokyo())
Example #14
0
class ResetTest(unittest.TestCase):
    """Test Monster Class reset function"""
    def setUp(self):
        print(self.shortDescription())
        self.test_monster = Monster("The Boogie Monster")
        self.test_monster.health = 5
        self.test_monster.victory_points = 5
        self.test_monster.status = "waka"
        self.test_monster.victory_points = 2
        self.test_monster.reset()

    def test_health_status(self):
        """is our health 10"""
        self.assertEqual(10, self.test_monster.health)

    def test_victory_points(self):
        """victory should be 0"""
        self.assertEqual(0, self.test_monster.victory_points)

    def test_status(self):
        """status should be Out of tokyo"""
        self.assertEqual("Out of Tokyo", self.test_monster.status)

    def test_name(self):
        """our name should be boogie monster"""
        self.assertEqual("The Boogie Monster", self.test_monster.name)
Example #15
0
def create_monster(mi_settings, screen, monsters, number, row_number):
    monster = Monster(mi_settings, screen)
    monster_width = monster.rect.width
    monster.x = monster_width + 2 * monster_width * number
    monster.rect.x = monster.x
    monster.rect.y = monster.rect.height + 2 * monster.rect.height * row_number
    monsters.add(monster)
Example #16
0
class InTokyoTest(unittest.TestCase):

    """Test Monster Class in_tokyo function"""

    def setUp(self):
        print(self.shortDescription())
        self.test_monster = Monster("The Boogie Monster")

    def test_is_in_tokyo_on_init(self):
        """check if we initialize correctly"""
        self.assertEqual("Out of Tokyo", self.test_monster.status)

    def test_is_not_in_tokyo(self):
        """return False if we're not in tokyo"""
        self.assertFalse(self.test_monster.in_tokyo())

    def test_is_in_tokyo(self):
        """check if return is true, when status is 'In Tokyo'"""
        self.test_monster.status = "In Tokyo"
        self.assertTrue(self.test_monster.in_tokyo())

    def test_is_non_default_dirty_status(self):
        """check if return is false, when status is not the default or 'In Tokyo'"""
        self.test_monster.status = "H e double hockey sticks o"
        self.assertFalse(self.test_monster.in_tokyo())

    def test_is_bad_type(self):
        """check if return is false, when status is not the default or 'In Tokyo'"""
        self.test_monster.status = ["H e double hockey sticks o"]
        self.assertFalse(self.test_monster.in_tokyo())
Example #17
0
 def __init__(self):
     """
     Sets up a game gui with the player and starts it
     :return:
     """
     pygame.init()
     self.view = View()
     self.map = Map()
     self.map.player = Player()
     self.map.player_loc = (1 * TILE_SIZE, 1 * TILE_SIZE)
     self.player = self.map.player
     self.player.set_location(self.map.player_loc)
     #self.time = pygame.time.Clock()
     self.map.set_player_location(self.map.player_loc)
     self.treasure = Treasure()
     self.inventory_button = Button("Inventory", 480, 0, 20, 20)
     self.save_button = Button("Save", 590, 0, 20, 20)
     self.load_button = Button("Load", 590, 50, 20, 20)
     self.view.draw_layers(self.map, self.treasure,
                           self.map.player.inventory, self.inventory_button,
                           self.save_button, self.load_button)
     self.monster = Monster()
     self.map.monster_loc = self.monster.loc
     while self.map.set_monster_location(self.monster.loc) is False:
         self.monster.set_location()
     self.map.treasure_loc = self.treasure.x_y
     while self.map.add_item(self.treasure.x_y) is False:
         self.treasure = Treasure()
Example #18
0
	def __init__(self):
		Monster.__init__(self) # we don't use super here because weird things will happen and overlap with multiple
		#inheritance
		Hero.__init__(self) # instead of super, we must specificy each parent class from which MonsterHero
		#is inheriting

		self.second_weapon = None # staying consistent with weapon variable
Example #19
0
    def run(self):
        self.player = Monster(name='Player')
        self._load_history(self.player)

        monster = random.choice(list(monsters.viewkeys()))
        self.monster = Monster(monsters[monster][0], monster, description=monsters[monster][1])
        self.ui = UI(self.player)
        self.ui.monster = self.monster

        self.ui.welcome()
        
        a = 1
        while a != 0:
            self._load_history(self.monster)

            a = self.run_loop()

            if a != 0:
                self.ui.update_display()

            self._save_history(self.player)
            self._save_history(self.monster)
            
            monster = random.choice(list(monsters.viewkeys()))
            self.monster = Monster(monsters[monster][0], monster, description=monsters[monster][1])
            self.ui.monster = self.monster
Example #20
0
 def __init__(self, x, y, name, oid=None, ai=None, hp=None, max_hp=None,
              mp=None, max_mp=None, death=None, fov_radius=cfg.TORCH_RADIUS,
              inventory=None):
     if death is None:
         death = player_death
     Monster.__init__(self, x, y, name, oid=oid, ai=ai, hp=hp,
                      max_hp=max_hp, mp=mp, max_mp=max_mp, death=death,
                      fov_radius=fov_radius, inventory=inventory)
Example #21
0
 def setUp(self):
     print(self.shortDescription())
     self.test_monster = Monster("The Boogie Monster")
     self.test_monster.health = 5
     self.test_monster.victory_points = 5
     self.test_monster.status = "waka"
     self.test_monster.victory_points = 2
     self.test_monster.reset()
    def setUp(self):
        """ Initialize fixtures """

        self.logMonster()
        self.monster = Monster("dragon", "easy")
        self.server = CharacterManager(
            "ACIT", "test_characters.sqlite")
        self.assertIsNotNone(self.monster)
Example #23
0
def main(argv):
    foe = Monster('scyter', 123, 0, 100, 100)
    ally = Monster('bulbasaur', 1, 0, 100, 100)
    battle = Battle(foe, ally)
    att = Attack('splash', 0, 100, False, True)
    for effect in att.effects():
        sys.stdout.write(effect(battle))
    sys.stdout.write('\n')
Example #24
0
 def _create_monster(self, monster_number, row_number):
     # Create a monster and place it in a row.
     monster = Monster(self)
     monster_width, monster_height = monster.rect.size
     monster.x = monster_width + 2 * monster_width * monster_number
     monster.rect.x = monster.x
     monster.rect.y = monster.rect.height + 2 * monster.rect.height * row_number
     self.monsters.add(monster)
Example #25
0
 def make_monsters(self):
     #make 2 monster
     for i in range(2):
         monster = Monster(BLUE, 20, 80, self)
         monster.rect.x = self.x + random.randint(0,self.platform.rect.right - 20)
         monster.rect.y = self.y - monster.rect.h
         monster.level = self
         self.monster_group.add(monster)
Example #26
0
def main():

	#ogre = Monster(name="Ogre", color="green", weapon="Machine Gun", hit_points=10, sound="Argh! I'm going to eat you!")
	#ogre.present_yourself();

	ogre = Monster(name="Marty the Ogre", color="green", weapon="Light Saber")

	ogre.present_yourself()
Example #27
0
 def __init__(self, terrain, initialPos, target, aiWorld, size, name):
     #terrain, initialPos, modelPath, movingSpeed, scale, lifePoint, volumicMass, target, aiWorld, detectionDistance, name, specificUpdate
     Monster.__init__(self, terrain, initialPos,
                      "assets/models/kamikaze.egg", 175, size, 1, 100,
                      target, aiWorld, 1000, name, self.Hpr)
     self.AIbehaviors.pursue(self.target.model)
     self.dx = 0
     self.dy = 0
     self.posx2, self.posy2 = self.pos[0], self.pos[1]
Example #28
0
 def place_monsters(self):
     self.monsters = []
     for i in range(0, 30):
         monster = Monster(self.game_map)
         monster.x = random.randint(0, game_map.MAP_WIDTH * game_map.SQUARE_WIDTH)
         monster.y = random.randint(0, game_map.MAP_HEIGHT * game_map.SQUARE_HEIGHT)
         monster.level = int(math.sqrt((self.center.x - monster.x) ** 2 + (self.center.y - monster.y) ** 2) / 50) + 1
         self.monsters.append(monster)
         self.game_map[monster.x][monster.y].units.append(monster)
Example #29
0
def give_monster(specie, use_special_name=False):
    mySpecieStats = MONSTER_SPECIES[specie]
    x = Monster(mySpecieStats[0], mySpecieStats[1], mySpecieStats[2], mySpecieStats[3])
    if use_special_name:
        # Generating a name using MONSTER_VARIATION
        adjective = choice(MONSTER_VARIATION)
        MONSTER_VARIATION.remove(adjective)
        x.name = '{} {}'.format(adjective,  x.name)
    return x
Example #30
0
    def __init__(self,x,y):
        Monster.__init__(self,x,y,0,BAT_RADIUS,BAT_MOVE_SPEED)

        self._color = BAT_COLOR
        self._hp    = BAT_HP
        self._timer = BAT_TIMER
        self._base_speed = self._speed
        self._boost = self._speed * BAT_BOOST_SPEED
        self._randangle = choice([1,-1])
Example #31
0
   def __init__(self):
      #super is a builtin python function that represents the parent class of
      #this object (parent class = Creature here). This makes a monster inside  
      #the parent class of creature, with all the properties of creature. 

      Monster.__init__(self)
      Hero.__init__(self)
      
      self.weapon2 = None
Example #32
0
 def create_monster(self, col_number, row_number):
     monster = Monster(self.settings, self.screen)
     monster_height = monster.rect.height
     monster.y = monster_height + 2 * monster_height * row_number
     monster_width = monster.rect.width
     monster.rect.x = self.settings.screen_width - 2 * monster_width * col_number
     print("monster x: " + str(monster.rect.x))
     monster.rect.y = monster.y
     print("monster y: " + str(monster.rect.y))
     self.monsters.add(monster)
Example #33
0
class ScoreTEst(unittest.TestCase):

    """Test Monster Class score function"""

    def setUp(self):
        print(self.shortDescription())
        self.test_monster = Monster("The Boogie Monster")

    def test_score_init(self):
        """make sure score is initialized."""
        self.assertEqual(0, self.test_monster.victory_points)

    def test_score_ideal(self):
        """make sure score is added."""
        self.assertEqual(5, self.test_monster.score(5))

    def test_winning_score_is_20(self):
        """make sure we set the status to winning if vp equal 20"""
        self.test_monster.score(20)
        self.assertEqual("WINNING", self.test_monster.status)

    def test_winning_score_is_over_20(self):
        """make sure we set the status to winning if vp equal to or exceeds 20"""
        self.test_monster.score(25)
        self.assertEqual("WINNING", self.test_monster.status)

    def test_make_sure_status_doesnt_chage(self):
        """ make sure we aren't greedy with winning status"""
        self.test_monster.score(5)
        self.assertNotEqual("WINNING", self.test_monster.status)

    def test_type_checking(self):
        """ can we handle types!"""
        with self.assertRaises(TypeError):
            self.test_monster.heal("something")
    def handle_event(self):
        if self.story["action"] == "death":
            if self.story["sprite"] == "player":
                self.game.story_manager.display_speech(["GAME OVER"], "bottom")
                self.game.story_manager.set_unblockable(False)
                self.game.perso.kill()
            elif self.story["sprite"]:
                sprite_name = self.story["sprite"]
                sprite = self.game.layer_manager.get_sprite(sprite_name)
                time.sleep(2)
                sprite.kill()
        elif self.story["action"] == "spawn":
            if self.story["spawn_type"] == "npc":
                npc = Npc(self.story["name"],
                          os.path.join(self.game.config.get_sprite_dir(),
                                       self.story["sprite_img"]),
                          self.story["destination"],
                          self.game.layer_manager["npcs"])
                npc.definir_position(self.story["destination"][0],
                                     self.story["destination"][1])
            else:
                monster = Monster(self.story["name"],
                                  os.path.join(self.game.config.get_sprite_dir(),
                                               self.story["sprite_img"]),
                                  self.story["destination"],
                                  self.game.layer_manager["monster"])
                monster.definir_position(self.story["destination"][0],
                                         self.story["destination"][1])
        elif self.story["action"] == "speech":
            self.game.story_manager.display_speech(self.story['text'],
                                                   self.story['position'])
        elif self.story["action"] == "move":
            self.game.story_manager.blocking = True
            self.game.story_manager.set_unblockable(False)
            sprite = self.game.layer_manager.get_sprite(self.story["sprite"])
            dest = self.story["destination"]
            sprite.saveLastPos()
            if sprite.collision_rect.x != dest[0]:
                if sprite.collision_rect.x < dest[0]:
                    sprite.move(sprite.speed * sprite.accel, 0, "right")
                else:
                    sprite.move(-(sprite.speed * sprite.accel), 0, "left")
                self.game.story_manager.events.insert(0, self)
                return
            if sprite.collision_rect.y != dest[1]:
                if sprite.collision_rect.y < dest[1]:
                    sprite.move(0, sprite.speed * sprite.accel, "down")
                else:
                    sprite.move(0, -(sprite.speed * sprite.accel), "up")
                self.game.story_manager.events.insert(0, self)
                return

            if self.game.story_manager.blocking:
                self.game.story_manager.set_unblockable(True)
                self.game.story_manager.blocking = False
Example #35
0
 def build_mob(self, monster, location):
     mon = Monster(monster['file'],self)
     mon.rect.x = int(location['x'])*50
     mon.rect.y = int(location['y'])*50
     if mon.is_boss():
         self.boss = True
         if self.boss_beat:
             return False
         else:
             self.boss_mob = mon
     return mon
Example #36
0
    def __init__(self):
        global grass, bg, portal
        portal = Portal2()
        for n, speed in [(1, 30)]:
            bg = HorzScrollBackground('image/background1.png')
            bg.speed = speed
        #background = load_image('image/background1.png')
        grass = Grass()
        Monster.load_all_images()
        global zombie_time

        zombie_time = 3
Example #37
0
 def setUp(self):
     self.pos_x_zero = 0
     self.pos_x_over_pos = 1500
     self.pos_x_over_neg = -1000
     self.pos_x_limit_pos = 1400
     self.pos_x_limit_neg = -100
     self.monster1 = Monster(pygame.sprite.Sprite)
     self.value_x = [-1000, -100, 0, 100, 1400, 1500]
     print(self.monster1.rect.x)
     self.monster1.rect.x = -200
     self.monster1.forward()
     print(self.monster1.rect.x)
Example #38
0
 def __init__(self, move_time, nodes):
     Monster.__init__(self, move_time, nodes)
     self.image = Surface((20, 20)).convert()
     self.image_inside = Surface((18, 18)).convert()
     self.image_inside.fill((255, 255, 0))
     self.image.blit(self.image_inside, (1, 1))
     self.rect = Rect(self.pos, (40, 40))
     self.speed = 4
     self.diag_speed = 3
     self.value = 0.5
     self.health = 50
     self.name = "Fast Monster"
     self.description = "A small monster with very quick movement speed, but low health."
  def __init__(self, move_time, nodes):
    Monster.__init__(self, move_time, nodes)
    self.image_inside.fill((142, 163, 12))
    self.image.blit(self.image_inside, (1, 1))
    self.rect = Rect(self.pos, (40, 40))
    self.speed = 1
    self.diag_speed = 3
    self.value = 10
    self.health = 100
    self.armor = 500

    self.name = "Armored Monster"
    self.description = "An armored monster that takes progressively more damage as it is hit"
Example #40
0
    def __init__(self, move_time, nodes):
        Monster.__init__(self, move_time, nodes)
        self.image_inside.fill((142, 163, 12))
        self.image.blit(self.image_inside, (1, 1))
        self.rect = Rect(self.pos, (40, 40))
        self.speed = 1
        self.diag_speed = 3
        self.value = 10
        self.health = 100
        self.armor = 500

        self.name = "Armored Monster"
        self.description = "An armored monster that takes progressively more damage as it is hit"
Example #41
0
class test_reset(unittest.TestCase):
    def setUp(self):
        self.monsta = Monster()

    #Tests if stats reset
    def test_reset(self):
        self.monsta.health = 5
        self.monsta.victory_points = 5
        self.monsta.reset()
        if self.monsta.health == 10 and self.monsta.victory_points == 0:
            self.reset = True

        self.assertTrue(self.reset, "Monster does not reset")
 def __init__(self, move_time, nodes):
     Monster.__init__(self, move_time, nodes)
     self.image = Surface((20, 20)).convert()
     self.image_inside = Surface((18, 18)).convert()
     self.image_inside.fill((255, 255, 0))
     self.image.blit(self.image_inside, (1, 1))
     self.rect = Rect(self.pos, (40, 40))
     self.speed = 4
     self.diag_speed = 3
     self.value = 0.5
     self.health = 50
     self.name = "Fast Monster"
     self.description = "A small monster with very quick movement speed, but low health."
def test_monster_health():
    monster = Monster("health")
    assert monster.health == 100
    assert monster.current_health == monster.health

    monster.set_health(70)
    assert monster.current_health == 70
    monster.set_health(50)
    assert monster.current_health == 50
    monster.set_health(20)
    assert monster.current_health == 20
    monster.set_health(10)
    assert monster.current_health == 10
Example #44
0
def start_fight(player):
    monster = Monster(10, 2)
    print('--- Start fight ---')
    monster.show_stats()

    while True:
        print('Choose an action : ')
        print('Tape 1 for attack')
        print('Tape 2 for show the monster stats')
        print('Tape 3 for leave the fight')
        action = input()
        if action == '':
            continue

        if int(action) == 1:
            player.attack_monster(monster)
            print('BIM !!!')
            monster.show_stats()
            print(' --- Press enter to continue ---')
            input()

        if int(action) == 2:
            monster.show_stats()

        if int(action) == 3:
            print('Your leave the fight')
            break

        if monster.life == 0:
            print("YOU WIN !!!")
            break

    return player
Example #45
0
 def __init__(self, terrain, initialPos, target, aiWorld, size, name):
     #terrain, initialPos, modelPath, movingSpeed, scale, lifePoint, volumicMass, target, aiWorld, detectionDistance, name, specificUpdate
     Monster.__init__(self, terrain, initialPos,
                      "assets/models/evil_slime.egg", 10, size,
                      50 + size // 2, 10, target, aiWorld, 500, name,
                      self.detection)
     #initialise AI stuff related to this object
     targetDistance = distance(self.pos, self.target.pos)
     self.statusD = (targetDistance < self.detectionDistance)
     self.statusS = (self.target.scale < self.scale)
     self.AIbehaviors.pursue(self.target.model, 1)
     self.AIbehaviors.flee(self.target.model, 500, 500)
     self.AIbehaviors.wander(50, 0, 50, 1)
     self.AIbehaviors.pauseAi("pursue")
     self.AIbehaviors.pauseAi("flee")
Example #46
0
def run_game():
    pygame.init()  #initializes pygame modules
    #create an instance of Settings class and assign it to game_settings
    game_settings = Settings()
    #set screen size, need double parenthesis, or set width and height to variable
    screen = pygame.display.set_mode(game_settings.screen_size)
    #set msg on status bar
    pygame.display.set_caption("Monster Attack")

    #music
    pygame.mixer.music.load('sounds/music.wav')
    pygame.mixer.music.play(-1)

    #create a play button and assign it to a var
    play_button = Play_button(screen, 'Start')

    #set variable equal to the class and pass it to the screen
    hero = Hero(screen)

    #set the bullets to group(built-in of pygame, upgrade to list)
    bullets = Group()
    monsters = Group()
    new_monster = Monster(screen)
    monsters.add(new_monster)
    #init counter at 0
    tick = 0

    while 1:  #1 is true, run this loop forever...
        #call gf (aliased from game_functions), get the check_event method
        gf.check_events(hero, bullets, monsters, screen, game_settings,
                        play_button)
        #call to update the screen
        gf.update_screen(game_settings, screen, hero, bullets, monsters,
                         play_button)
        tick += 1
        if game_settings.game_active:
            hero.update()  #update the hero flags
            bullets.update()
            monsters.update()
            if tick % 150 == 0:
                new_monster = Monster(screen)
                monsters.add(new_monster)
            #get rid of bullets that are off the screen
            dict = groupcollide(bullets, monsters, True, True)
            if dict:
                print "you hit a monster"
                pygame.mixer.music.load('sounds/lose.wav')
                pygame.mixer.music.play(-1)
Example #47
0
 def __init__(self):
     """
     Sets up a game gui with the player and starts it
     :return:
     """
     pygame.init()
     self.view = View()
     self.map = Map()
     self.map.player = Player()
     self.map.player_loc = (1*TILE_SIZE, 1*TILE_SIZE)
     self.player = self.map.player
     self.player.set_location(self.map.player_loc)
     #self.time = pygame.time.Clock()
     self.map.set_player_location(self.map.player_loc)
     self.treasure = Treasure()
     self.inventory_button = Button("Inventory", 480, 0, 20, 20)
     self.save_button = Button("Save", 590, 0, 20, 20)
     self.load_button = Button("Load", 590, 50, 20, 20)
     self.view.draw_layers(self.map, self.treasure, self.map.player.inventory, self.inventory_button, self.save_button, self.load_button)
     self.monster = Monster()
     self.map.monster_loc = self.monster.loc
     while self.map.set_monster_location(self.monster.loc) is False:
         self.monster.set_location()
     self.map.treasure_loc = self.treasure.x_y
     while self.map.add_item(self.treasure.x_y) is False:
         self.treasure = Treasure()
Example #48
0
    def __init__(self):
        #window setup
        pygame.display.set_caption('Necromonster')
        path = ['rec', 'misc', 'icon.png']
        os.path.sep.join(path)
        pygame.display.set_icon(pygame.image.load(os.path.sep.join(path)))
        #pygame.display.set_icon(pygame.image.load('rec\\misc\\icon.png'))
        self.main_path = os.getcwd()

        # initiate the clock and screen
        self.clock = pygame.time.Clock()
        self.last_tick = pygame.time.get_ticks()
        self.screen_res = [900, 650]
        self.screen = pygame.display.set_mode(self.screen_res, pygame.HWSURFACE, 32)
        self.DEBUG = 1

        #Init custom game classes
        self.Player = Player(self)
        self.Monsters = Monster(self)
        self.ItemHandler = Item(self)
        self.Invent = Invent(self)
        self.HUD = HUD(self)

        # load fonts, create font list
        self.text_list = []
        self.default_font = pygame.font.SysFont(None, 20)

        # get the map that you are on
        self.blit_list = mapLoader.load('home', self)

        self.Monsters.create('goop', [300, 300], 2, 'neutral')

        while 1:
            self.Loop()
Example #49
0
def wealthdrops():
    hero = Hero._test_hero()
    monster = Monster.monster_spawn(1)
    test_drops = [wealth_drop(monster, hero) for i in range(1000)]
    real_drops = [t for t in test_drops if t != 0]
    print("{} drops out of {} chances".format(len(real_drops),
                                              len(test_drops)))
Example #50
0
    def __init__(self, width, height):
        self.width = width
        self.height = height

        layout = []
        for _ in range(self.width):
            # To start out, just do a "maze" with doors between all rooms.
            row = []
            for _ in range(self.height):
                room = Room()
                room.doors = [NORTH, SOUTH, EAST, WEST]
                row.append(room)
            layout.append(row)

        # Remove the doors in the outer walls
        for room in layout[0]:
            room.doors.remove(WEST)
        for inner_column in layout:
            inner_column[0].doors.remove(SOUTH)
            inner_column[-1].doors.remove(NORTH)
        for room in layout[-1]:
            room.doors.remove(EAST)

        self.layout = layout

        self._remove_random_doors()

        self.player_location = self.get_random_location()
        self.monster_location = self.get_random_location()

        self.monster = Monster()
Example #51
0
def load_game(save_file):
    """Load a saved game from a file."""
    with open(save_file, 'r') as f:
        exec(f.read())

    # Replace the map structure in the save file with actual cells.
    SS.map = map

    for x in xrange(SS.map.w):
        for y in xrange(SS.map.h):
            SS.map.grid[x][y] = Cell(
                SS.map.grid[x][y]['n'], explored=SS.map.grid[x][y]['e'])

    # Re-create monsters
    for m_str in monster_defs:
        mon = Monster.unserialize(m_str)
        mon.place_on_map()

    # Re-create items
    for i_str in item_defs:
        item = Item.unserialize(i_str)
        item.place_on_map()

    # Re-create the player
    SS.u = Player.unserialize(u)
Example #52
0
 def __init__(self, x, y, level, game):
     Monster.__init__(self,
                      x=x,
                      y=y,
                      game=game,
                      name="player",
                      disp="@",
                      color="Player",
                      description="A hero of might and courage.",
                      blocks=True,
                      fighter_comp=Fighter(st=14, dx=12, iq=14, ht=14))
     self.fighter_comp.equipped['right hand'] = weapon.Weapon(
         'Longsword', ')', 'player', game, None, 5, 'slashing', self,
         'Longswords')
     self.fighter_comp.add_skill("Longswords", 'ST', 10, 0, 'attack')
     self.fighter_comp.add_skill("Defense", 'DX', 0, 0, 'defense')
Example #53
0
    def test_is_suitable_rune_2(self):
        preset = Preset(monster=Monster('any', stats={}))
        preset.include(violent, will)

        self.assertTrue(
            preset.is_suitable_rune(make_rune(slot=1, set='Violent')))
        self.assertTrue(preset.is_suitable_rune(make_rune(slot=2, set='Will')))
Example #54
0
class test_in_tokyo(unittest.TestCase):
    #Defines status
    def setUp(self):
        self.monsta = Monster()
        self.monsta.status = "In Tokyo"

    #Tests if monster shows up in Tokyo
    def test_in_toyko_true(self):
        tokyo = self.monsta.in_tokyo()

        self.assertTrue(tokyo, "Monster not showing up in Tokyo")

    #Tests if monster does not show up in Tokyo
    def test_in_tokyo_false(self):
        self.monsta.status = "Out of Tokyo"
        tokyo = self.monsta.in_tokyo()
        self.assertFalse(tokyo,"Monster is showing up in Tokyo")
Example #55
0
class HealTest(unittest.TestCase):
    """Test the functionality of the Monster class heal function."""

    def setUp(self):
        self.new_monster = Monster("Cookie")

    def tearDown(self):
        del self.new_monster

    def test_heal_health_gt_10(self):
        """
        Call the heal method with 6 to add to the initial value of 10.
        Check that the health attribute remains unchanged.
        """

        health = self.new_monster.health

        # Call function
        self.new_monster.heal(6)

        self.assertEqual(health, self.new_monster.health)

    def test_heal_health_le_10(self):
        """
        Set health to 2. Call the heal method with 6 to add.
        Check that the health attribute changes to 8.
        """

        self.new_monster.health = 2

        # Call function
        self.new_monster.heal(6)

        self.assertEqual(self.new_monster.health, 8)

    def test_heal_negative_health_le_10(self):
        """
        Call the heal method with -6 to add.
        Check that the health attribute changes to 4.
        """

        # Call function
        self.new_monster.heal(-6)

        self.assertEqual(4, self.new_monster.health)

    def test_heal_negative_health_lt_0(self):
        """
        Call the heal method with -16 to add.
        Check that the health attribute changes to -6.
        """

        # Call function
        self.new_monster.heal(-16)

        self.assertEqual(-6, self.new_monster.health)
Example #56
0
 def setUp(self):
     print(self.shortDescription())
     self.test_monster = Monster("The Boogie Monster")
     self.test_monster.health = 5
     self.test_monster.victory_points = 5
     self.test_monster.status = "waka"
     self.test_monster.victory_points = 2
     self.test_monster.reset()
Example #57
0
class AttackTest(unittest.TestCase):

    """Test Monster Class attack function"""

    def setUp(self):
        print(self.shortDescription())
        self.test_monster = Monster("The Boogie Monster")

    def test_ideal_attack(self):
        """test ideal attack, won't ko"""
        self.assertEqual(5, self.test_monster.attack(5))

    def test_kod_attack(self):
        """test kod attack"""
        self.test_monster.attack(15)
        self.assertEqual("K.O.'d", self.test_monster.status)

    def test_kod_attack_health(self):
        """test kod attack"""
        self.test_monster.attack(15)
        self.assertEqual(-5, self.test_monster.health)

    def test_incorrect_type_attack(self):
        """test if we prevent bad types"""
        with self.assertRaises(TypeError):
            self.test_monster.attack("some bad types")

    def test_negative_healt(self):
        """we should test for negative health catches"""
        pass
Example #58
0
File: main.py Project: Kupoman/thor
	def __init__(self, _base):
		GameState.__init__(self, _base)
		self.accept("enter", self.cb_next_turn)

		self.clock = ClockObject()

		g_race = "golem" if self.player.monster.race.lower() == "ogre" else "ogre"
		hpr_list = ((-90, 0, 0), (90, 0, 0))
		pos_list = ((-2, 2, 0), (2, 2, 0))
		monster_list = ((self.player.monster,)*3, (Monster.new_from_race(g_race),)*3)
		# self.teams = [CombatTeam(monster_list[i], pos_list[i], hpr_list[i]) for i in range(2)]
		self.combat_world = CombatWorld()
		self.combat_world.add_team(monster_list[0], pos_list[0], hpr_list[0])
		self.combat_world.add_team(monster_list[1], pos_list[1], hpr_list[1])
		self.teams = self.combat_world.teams

		self.teams[0].set_targets(self.teams[1])
		self.teams[1].set_targets(self.teams[0])

		# Combatants
		self.combatants = {}
		self.combatants['red'] = self.player.monster
		self.combatants['red'].current_stamina = 50
		self.combatants['red'].current_hp = self.combatants['red'].hp
		g_race = "golem" if self.player.monster.race.lower() == "ogre" else "ogre"
		self.combatants['green'] = Monster.new_from_race(g_race)
		self.combatants['green'].current_hp = self.combatants['green'].hp
		self.combatants['green'].current_stamina = 50

		self.combatants['red'].target = self.combatants['green']
		self.combatants['green'].target = self.combatants['red']

		# Combat vars
		self.combat_time = 60.0
		self.turn = 60
		self.player_spells = [
			commands.Attack,
			commands.Wait,
			]

		self.base.background.setImage("art/background.png")

		self.player_command = None

		self.setup_ui()