def test_set_move(self): gb = Gameboard(self._testboard, self._characters) assert (gb._active_mob_name == u"") assert (gb._number_of_moves_remaining == 0) gb.set_active_mob(u"Mob1", 10) assert (gb._active_mob_name == u"Mob1") assert (gb._number_of_moves_remaining == 10)
def test_get_random_pos(self): gb = Gameboard(self._testboard, self._characters) unoccupied_ones = [(2, 6), (3, 5), (3, 6)] res = set() for i in range(100): res.add(gb.get_random_free_pos_in_room(1)) assert ((1, 5) not in res) for tile in unoccupied_ones: assert (tile in res)
def test_prohibit_room_reentry(self): gb = Gameboard(self._testboard, self._characters) gb.set_active_mob(u"Mob2", 10) assert (gb.move_mob(u"Mob2", u"down") == True) assert (gb.move_mob(u"Mob2", u"right") == True) assert (gb.move_mob(u"Mob2", u"right") == True) assert (gb.move_mob(u"Mob2", u"right") == True) assert (gb.move_mob(u"Mob2", u"left") == True) assert (gb.move_mob(u"Mob2", u"left") == False) assert (gb.get_active_mob_name() == u"Mob2")
def test_decrease_movement_ctr(self): gb = Gameboard(self._testboard, self._characters) gb.set_active_mob(u"Mob2", 2) gb.decrease_movement_counter() assert (gb._number_of_moves_remaining == 1) gb.decrease_movement_counter() assert (gb._active_mob_name == u"") assert (gb._number_of_moves_remaining == 0)
def test_move_through_door(self): gb = Gameboard(self._testboard, self._characters) gb.set_active_mob(u"Mob2", 10) mob = gb.get_mob(u"Mob2") assert (gb.move_mob(u"Mob2", u"down") == True) assert (gb.move_mob(u"Mob2", u"left") == True) assert (gb.move_mob(u"Mob2", u"left") == True)
def test_track_rooms(self): gb = Gameboard(self._testboard, self._characters) gb.set_active_mob(u"Mob2", 10) assert (gb.move_mob(u"Mob2", u"down") == True) assert (gb.move_mob(u"Mob2", u"right") == True) assert (gb.move_mob(u"Mob2", u"right") == True) assert (gb.move_mob(u"Mob2", u"right") == True) assert (gb._start_room == 2)
def test_finish_movement(self): gb = Gameboard(self._testboard, self._characters) gb.set_active_mob(u"Mob2", 3) gb.movement_done() assert (gb._active_mob_name == u"") assert (gb._number_of_moves_remaining == 0) assert (gb._start_room == 0)
def test_space_occupied(self): gb = Gameboard(self._testboard, self._characters) assert (gb.pos_occupied((0, 0)) == False) for name, pos in self._characters: assert (gb.pos_occupied(pos) == True)
def test_get_positions(self): gb = Gameboard(self._testboard, self._characters) for name, pos in self._characters: assert (pos in gb.get_mobs_pos())
def test_todict(self): gb = Gameboard(self._testboard, self._characters) data = gb.todict() assert (len(data) == len(self._characters)) for itm in self._characters: assert (data[itm[0]] == itm[1])
def test_get_room(self): gb = Gameboard(self._testboard, self._characters) assert (gb.get_room_no(u"Mob1") == 1) assert (gb.get_room_no(u"Mob2") == 2)
def test_is_in_hallway(self): gb = Gameboard(self._testboard, self._characters) assert (gb.is_in_hallway(u"Mob1") == True) assert (gb.is_in_hallway(u"Mob2") == False)
def test_move_into_room(self): gb = Gameboard(self._testboard, self._characters) gb.set_active_mob(u"Mob2", 10) assert (gb.move_mob(u"Mob2", u"down") == True) assert (gb.move_mob(u"Mob2", u"right") == True) assert (gb.move_mob(u"Mob2", u"right") == True) assert (gb.move_mob(u"Mob2", u"right") == True) assert (gb.move_mob(u"Mob2", u"right") == True) assert (gb.move_mob(u"Mob2", u"right") == True) assert (gb.move_mob(u"Mob2", u"up") == False) assert (gb.get_active_mob_name() == u"") assert (gb.get_mob(u"Mob2").pos in [(1, 8), (3, 8)])
def test_execute_move(self): class Fake: def up(self, dummy): self.up_set = True def down(self, dummy): self.down_set = True def left(self, dummy): self.left_set = True def right(self, dummy): self.right_set = True fb = Fake() gb = Gameboard(fb, []) gb.execute_movement((0, 0), u"up") assert (fb.up_set == True) fb = Fake() gb = Gameboard(fb, []) gb.execute_movement((0, 0), u"down") assert (fb.down_set == True) fb = Fake() gb = Gameboard(fb, []) gb.execute_movement((0, 0), u"left") assert (fb.left_set == True) fb = Fake() gb = Gameboard(fb, []) gb.execute_movement((0, 0), u"right") assert (fb.right_set == True)
def test_move_illegal_player(self): gb = Gameboard(self._testboard, self._characters) gb.set_active_mob(u"Mob1", 10) assert (gb.move_mob(u"Mob2", u"down") == False)
def test_enter_room(self): gb = Gameboard(self._testboard, self._characters) unoccupied_ones = [(2, 6), (3, 5), (3, 6)] gb.enter_room(u"Mob2", 1) assert (gb.get_mob(u"Mob2").pos in unoccupied_ones)