Esempio n. 1
0
    def testUseItem(self):
        w = Warrior("Yup", 50)
        a = Apple(1, 30)

        yup_health_before_apple_use = w.health
        #item must be in the inventory, else an Exception is raised
        with self.assertRaises(Exception):
            w.use(a)

        w.pick(a)
        w.use(a)

        #After a item was used, it must be removed from the inventory
        self.assertTrue(a not in w.inventory)

        #A apple use will add its gain to the character health
        self.assertEquals(w.health, yup_health_before_apple_use + a.gain)

        #A spell use will decrease the amount of mana of the character if > 0
        yup_mana_before_spell_use = w.mana
        s = Spell("Fire", 1, 10, 30)
        w.pick(s)
        w.use(s)

        self.assertEquals(w.mana, yup_mana_before_spell_use) # because a Warrior has no mana


        w = Wizard("Plop")
        plop_mana_before_spell_use = w.mana
        s = Spell("Fire", 1, 10, 30)
        w.pick(s)
        w.use(s)
        self.assertEquals(w.mana, plop_mana_before_spell_use - s.cost)
Esempio n. 2
0
 def testWizardConstructor(self):
     w = Wizard("Plop")
     self.assertEqual(w.name, "Plop")
     self.assertEqual(w.health, 100)
     self.assertEqual(w.mana, 100)
     self.assertEqual(w.power, 50)
     self.assertEqual(w.xp, 0)
     self.assertListEqual(w.inventory, [])
     self.assertListEqual(w.spells, [])
Esempio n. 3
0
    def testDisplay(self):
        board = Board(20, 20)

        expected_display = "- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n"
        self.assertEqual(board.display(), expected_display)

        w = Wizard("Plop")
        board.move(w, 0, 0)
        expected_display = "X - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n"
        self.assertEqual(board.display(), expected_display)

        board.move(w, 2, 4)
        expected_display = "- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - X - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n- - - - - - - - - - - - - - - - - - - - \n"
        self.assertEqual(board.display(), expected_display)
Esempio n. 4
0
    def testWizardInvocation(self):
        w = Wizard("Plop")
        enemy = Warrior("Yup", 50)

        yup_health_before_apple_use = enemy.health
        plop_mana_before_spell_use = w.mana

        s = Spell("Fire", 1, 10, 30)

        with self.assertRaises(Exception):
            w.invoke(s, enemy)

        w.pick(s)
        w.invoke(s, enemy)

        self.assertTrue(s not in w.inventory)
        self.assertEquals(w.mana, plop_mana_before_spell_use - s.cost)
        self.assertEquals(enemy.health, yup_health_before_apple_use - s.damage)
Esempio n. 5
0
    def testCharacterMove(self):
        board = Board(50, 50)
        w = Wizard("Plop")
        self.assertEqual(w.x, None)
        self.assertEqual(w.y, None)

        board.move(w, 0, 0)
        self.assertEqual(w.x, 0)
        self.assertEqual(w.y, 0)
        cell = board.grid[0][0]
        self.assertTrue(w in cell)

        cell_before_move = board.grid[w.x][w.y]
        board.move(w, 2, 4)
        self.assertEqual(w.x, 2)
        self.assertEqual(w.y, 4)
        cell = board.grid[2][4]
        self.assertTrue(w not in cell_before_move)
        self.assertTrue(w in cell)