コード例 #1
0
    def setUp(self):

        self.dungeonGame = DungeonGame()
        #initializing map with 2 cells
        DungeonGame.dmap.initialize(2, 1, 0, [], Position(0, 0))

        #setting enemy and player position to be the same
        DungeonGame.player.position = Position(0, 0)
        DungeonGame.enemy.position = Position(0, 0)
class HostileEncounterTest(unittest.TestCase):


    def setUp(self):

        self.dungeonGame = DungeonGame()

        DungeonGame.player.health = len(Player.proficiencies)\
                                   * (len(enemies_list) + len(traps_list))


    def testEnemyEncounter(self):

        for proficiency in Player.proficiencies:
            DungeonGame.player.proficiency = proficiency
            player_immunity = Player.proficiency_immunity[proficiency]

            for enemy_character in enemies_list:

                player_health_before = DungeonGame.player.health
                self.dungeonGame.process_hostile_encounter(enemy_character)

                #check that health points decrreased by one if player not immune to enemy
                if (player_immunity != enemy_character.enemy_type):
                    self.assertEqual(player_health_before- 1,\
                     DungeonGame.player.health)

                #otherwise check that health remained the same
                else:
                    self.assertEqual(player_health_before,\
                     DungeonGame.player.health)


    def testTrapEncounter(self):

        for proficiency in Player.proficiencies:
            DungeonGame.player.proficiency = proficiency
            player_immunity = Player.proficiency_immunity[proficiency]

            for trap in traps_list:

                player_health_before = DungeonGame.player.health
                self.dungeonGame.process_hostile_encounter(trap)

                #check that health points decrreased by one if player not immune to trap
                if (player_immunity != trap.enemy_type):
                    self.assertEqual(player_health_before- 1,\
                     DungeonGame.player.health)

                #otherwise check that health remained the same
                else:
                    self.assertEqual(player_health_before,\
                     DungeonGame.player.health)

    def tearDown(self):

        print('Hostile encounter test ended.')
コード例 #3
0
class GameEndTest(unittest.TestCase):
    def setUp(self):

        self.dungeonGame = DungeonGame()

    def testHealthGameEnd(self):

        self.dungeonGame.player.health = 0
        self.dungeonGame.player.bag = 0

        self.assertTrue(self.dungeonGame.is_game_ended())

    def testBagGameEnd(self):
        self.dungeonGame.player.health = DungeonGame.default_health
        self.dungeonGame.player.bag = DungeonGame.treasure_to_win

        self.assertTrue(self.dungeonGame.is_game_ended())

    def tearDown(self):

        print('Game end test ended.')
コード例 #4
0
class EnemyRespawnCheck(unittest.TestCase):
    def setUp(self):

        self.dungeonGame = DungeonGame()
        #initializing map with 2 cells
        DungeonGame.dmap.initialize(2, 1, 0, [], Position(0, 0))

        #setting enemy and player position to be the same
        DungeonGame.player.position = Position(0, 0)
        DungeonGame.enemy.position = Position(0, 0)

    def testEncounter(self):

        self.dungeonGame.respawn_enemy()

        #check that enemy position is not the same after respawn
        self.assertNotEqual(DungeonGame.player.position,\
         DungeonGame.enemy.position)

    def tearDown(self):

        print('Enemy respawn test ended.')
コード例 #5
0
from game import DungeonGame

current_game = DungeonGame()
current_game.game_loop()
コード例 #6
0
    def setUp(self):

        self.dungeonGame = DungeonGame()
    def setUp(self):

        self.dungeonGame = DungeonGame()

        DungeonGame.player.health = len(Player.proficiencies)\
                                   * (len(enemies_list) + len(traps_list))