def test_shoot1(self): world = World() bot = UserBot(Point(0, 0), world, 2, 10, True, 'player', None) self.assertEqual(bot.is_alive(), True) bot1 = EnemyBot(Point(1, 1), world, 1, 10, True, 'enemy1', None) self.assertEqual(bot1.is_alive(), True) bot2 = EnemyBot(Point(2, 2), world, 1, 10, True, 'enemy2', None) self.assertEqual(bot2.is_alive(), True) bot3 = EnemyBot(Point(3, 3), world, 1, 10, True, 'enemy3', None) self.assertEqual(bot3.is_alive(), True) try: bot.shoot(Point(3, 3), blocking=False) world.update() self.assertEqual(bot1.is_alive(), False) bot.shoot(Point(3, 3), blocking=False) world.update() self.assertEqual(bot2.is_alive(), False) bot.shoot(Point(3, 3), blocking=False) world.update() self.assertEqual(bot3.is_alive(), False) except GameOver as e: self.assertEqual(e.game_won, True) self.assertEqual(len(world.objects), 1)
def test_shoot3(self): world = World() try: bot = UserBot(Point(0, 0), world, 2, 10, True, 'player', None) wall = Wall(Point(2, 2), world, 1, 1, True) bot1 = EnemyBot(Point(3, 3), world, 1, 10, True, 'enemy1', None) bot.shoot(Point(3, 3), blocking=False) world.update() self.assertEqual(wall.is_alive(), False) self.assertEqual(bot.is_alive(), True) bot.shoot(Point(3, 3), blocking=False) world.update() except GameOver: pass self.assertEqual(bot1.is_alive(), False)
def test_shoot_diagonal(self): world = World() bot = UserBot(Point(1, 1), world, 2, 2, True, 'player', None) self.assertEqual(bot.is_alive(), True) wall1 = Wall(Point(0, 0), world, 1, 1, True, 'wall1') self.assertEqual(wall1.is_alive(), True) wall2 = Wall(Point(0, 1), world, 1, 1, True, 'wall2') self.assertEqual(wall2.is_alive(), True) wall3 = Wall(Point(0, 2), world, 1, 1, True, 'wall3') self.assertEqual(wall3.is_alive(), True) wall4 = Wall(Point(1, 2), world, 1, 1, True, 'wall4') self.assertEqual(wall4.is_alive(), True) wall5 = Wall(Point(2, 2), world, 1, 1, True, 'wall5') self.assertEqual(wall5.is_alive(), True) wall6 = Wall(Point(2, 1), world, 1, 1, True, 'wall6') self.assertEqual(wall6.is_alive(), True) wall7 = Wall(Point(2, 0), world, 1, 1, True, 'wall7') self.assertEqual(wall7.is_alive(), True) wall8 = Wall(Point(1, 0), world, 1, 1, True, 'wall8') self.assertEqual(wall8.is_alive(), True) bot1 = EnemyBot(Point(3, 3), world, 1, 1, True, 'enemy1', None) self.assertEqual(bot1.is_alive(), True) try: bot.shoot(Point(3, 3), blocking=False) world.update() self.assertEqual(bot.is_alive(), True) self.assertEqual(wall1.is_alive(), True) self.assertEqual(wall2.is_alive(), True) self.assertEqual(wall3.is_alive(), True) self.assertEqual(wall4.is_alive(), True) self.assertEqual(wall5.is_alive(), False) self.assertEqual(wall6.is_alive(), True) self.assertEqual(wall7.is_alive(), True) self.assertEqual(wall8.is_alive(), True) self.assertEqual(bot1.is_alive(), True) bot.shoot(Point(3, 3), blocking=False) world.update() self.assertEqual(bot.is_alive(), True) self.assertEqual(wall1.is_alive(), True) self.assertEqual(wall2.is_alive(), True) self.assertEqual(wall3.is_alive(), True) self.assertEqual(wall4.is_alive(), True) self.assertEqual(wall5.is_alive(), False) self.assertEqual(wall6.is_alive(), True) self.assertEqual(wall7.is_alive(), True) self.assertEqual(wall8.is_alive(), True) self.assertEqual(bot1.is_alive(), False) except GameOver as e: self.assertEqual(e.game_won, True) self.assertEqual(len(world.objects), 8)