当前位置: 首页>>代码示例>>Python>>正文


Python monster.Monster类代码示例

本文整理汇总了Python中monster.Monster的典型用法代码示例。如果您正苦于以下问题:Python Monster类的具体用法?Python Monster怎么用?Python Monster使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Monster类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

    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
开发者ID:schiem,项目名称:ai_project,代码行数:26,代码来源:world.py

示例2: place_objects

    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)
开发者ID:aruse,项目名称:Bludgeon,代码行数:34,代码来源:map.py

示例3: test_attack

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)
开发者ID:PDXDevCampJuly,项目名称:daniel_pearl,代码行数:27,代码来源:test_attack.py

示例4: __init__

	def __init__(self):

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


		self.where = "on shoulders"
开发者ID:PDXCodeGuildJan,项目名称:Shawn-s-Assignments-PDXCode-Guild-16,代码行数:7,代码来源:hero.py

示例5: InTokyoTest

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)
开发者ID:TheOneTAR,项目名称:atifar,代码行数:26,代码来源:test_in_tokyo.py

示例6: __init__

	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!"
开发者ID:PDXCodeGuildJan,项目名称:KatieCGBootcamp,代码行数:7,代码来源:hero.py

示例7: MonsterResetTest

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)
开发者ID:PDXDevCampJuly,项目名称:daniel_pearl,代码行数:27,代码来源:test_reset.py

示例8: __init__

	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
开发者ID:PDXCodeGuildJan,项目名称:AlexisRepo,代码行数:7,代码来源:hero.py

示例9: main

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()
开发者ID:IonatanSala,项目名称:Python,代码行数:8,代码来源:ogre.py

示例10: __init__

 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)
开发者ID:aruse,项目名称:Bludgeon,代码行数:8,代码来源:player.py

示例11: make_monsters

 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)
开发者ID:txcism,项目名称:pygame,代码行数:8,代码来源:level.py

示例12: __init__

    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])
开发者ID:tc30nguyen,项目名称:pyShotGame,代码行数:9,代码来源:bat.py

示例13: place_monsters

 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)
开发者ID:trid,项目名称:anticivilization,代码行数:9,代码来源:game_data.py

示例14: __init__

   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
开发者ID:Pjmcnally,项目名称:teaching,代码行数:9,代码来源:monsterhero.py

示例15: handle_event

    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
开发者ID:Projet5001,项目名称:projet5001-pyhton,代码行数:55,代码来源:storymanager.py


注:本文中的monster.Monster类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。