Exemplo n.º 1
0
class test_player_obj(unittest.TestCase):
    my_figter = main_player("Bob", "Female")
    boss = npc()
    test_user = main_player("test", "test_gender")
    test_equip = main_player("fred", "Bob")

    def test_gen_player(self):
        self.assertEqual(self.test_user.name, "test")
        self.assertEqual(self.test_user.gender, "test_gender")

    def test_have_stats(self):
        self.assertGreaterEqual(self.test_user.attack, 5,
                                "attack is generatored")
        self.assertEquals(self.test_user.health, 200, "health is generatored")
        self.assertGreaterEqual(self.test_user.defense, 5,
                                "defense is generatored")

    def test_fight(self):
        with patch('builtins.input', return_value='a'):
            self.my_figter.health = 50000000000000000
            __, win = self.my_figter.fight(self.boss)
            if win.name == self.my_figter.name:
                self.fail(
                    f"player fight script broken {win.name}{self.my_figter.name}"
                )

    def test_equip_potions(self):
        self.test_equip.health = 50
        potion = potions()
        potion.modifer = 1.25
        self.test_equip.user_equip(potion)
        self.assertEquals(self.test_equip.health, 62)

    def test_equip_weapons(self):
        self.test_equip.attack = 50
        knife = weapon()
        knife.modifer = 10
        self.test_equip.user_equip(knife)
        self.assertEquals(self.test_equip.attack, 60)

    def test_equip_armour(self):
        self.test_equip.defense = 50
        shield = armour()
        shield.modifer = 10
        self.test_equip.user_equip(shield)
        self.assertEquals(self.test_equip.defense, 60)
Exemplo n.º 2
0
 def reload():
     """ loads a player object with user input starts the location"""
     print('what was your character called?')
     while True:
         try:
             player = save_info.read(main_player("name","gender"),input("(abc)>>>"))
             break
         except FileNotFoundError:
             print('that is wrong which one is it?')
             continue
     print(f'here is your stats:\n {player.stats()}\n\nWelcome to this wonderful land.')
     main.move_to_location(player)
Exemplo n.º 3
0
 def on_boarding():
     """ creates a player object with user input ,writes to save and starts the location"""
     print(f"hello and welcome to my game!\n What is your name?")
     name = UI.ask("(abc)")
     print(f"Oh your name is {name} and what is your gender?")
     gender = UI.ask("(abc)")
     Player = main_player(name, gender)
     print(f'here is your stats:\n {Player.stats()}')
     print("""Sorry for i was only interseted, it's hard to see.
     Welcome to this wonderful land.""")
     save_info.write(Player,Player.name)
     main.move_to_location(Player)
Exemplo n.º 4
0
 def test_read(self):
     rewrite_player = main_player("o", "o")
     s = save_info.read(rewrite_player, "test_player")
     self.assertEqual(s.name, "best player")
Exemplo n.º 5
0
 def test_write(self):
     test_player = main_player("test_player", "they")
     s = save_info.write(test_player, "test_character")
     self.assertEqual(True, s)