from gamelib.Board import Board from gamelib.Structures import Wall walls = [] for i in range(0, 11): walls.append(Wall()) b = Board(size=[10, 10]) for i in range(0, 10): b.place_item(walls[i], i, i) b.place_item(Wall(model="*", type="round"), 0, 9) b.place_item(Wall(model="*", type="round"), 1, 9) print(b.get_immovables()) for i in b.get_immovables(type="round"): print(f"{i}: {i.name} pos: {i.pos} ({id(i)})") print("DISCARDING") b._immovables.discard(b.item(1, 9)) for i in b.get_immovables(type="round"): print(f"{i}: {i.name} pos: {i.pos} ({id(i)})")
player_starting_column = random.randint(0,49) bonus_board = Board(name='Bonus Stage', size=[50,30], player_starting_position=[player_starting_row,player_starting_column], ui_borders=Utils.YELLOW_SQUARE, ui_board_void_cell=Utils.BLACK_SQUARE) g.add_board(2,bonus_board) # To place the treasures we have 30*50 = 1500 cells available on the map, minus the player it brings the total to 1499. # Now let's randomely place 300 money bags. Each bag increase the score by 100. for k in range(0,300): row = None column = None retry = 0 while True : if row == None: row = random.randint(0,bonus_board.size[1]-1) if column == None: column = random.randint(0,bonus_board.size[0]-1) # print(f"Game.add_npc() finding a position for NPC {npc.name} trying ({x},{y})") if isinstance(bonus_board.item(row,column), BoardItemVoid): break elif retry > 20: break else: row = None column = None retry += 1 bonus_board.place_item(Treasure(model=Sprites.MONEY_BAG, value=100, name=f'gold_bag_{k}'), row, column) # And finally let's put 100 diamonds. Each diamond increase the score by 1000. for k in range(0,100): row = None column = None retry = 0 while True :
class TestBoard(unittest.TestCase): def test_create_board(self): self.board = Board(name="test_board", size=[10, 10], player_starting_position=[5, 5]) self.assertEqual(self.board.name, "test_board") def test_sanity_size_is_list(self): with self.assertRaises(Exception) as context: self.board = Board(name="test_board", size="bad", player_starting_position=[5, 5]) self.assertTrue("must be a list." in str(context.exception)) def test_sanity_size_has_two_elements(self): with self.assertRaises(Exception) as context: self.board = Board(name="test_board", size=["one"], player_starting_position=[5, 5]) self.assertTrue( "must be a list of 2 elements" in str(context.exception)) def test_sanity_size_element_one_int(self): with self.assertRaises(Exception) as context: self.board = Board(name="test_board", size=["one", "two"], player_starting_position=[5, 5]) self.assertTrue("first element of the" in str(context.exception)) def test_sanity_size_element_two_int(self): with self.assertRaises(Exception) as context: self.board = Board(name="test_board", size=[10, "two"], player_starting_position=[5, 5]) self.assertTrue("second element of the" in str(context.exception)) def test_sanity_name_string(self): with self.assertRaises(Exception) as context: self.board = Board(name=100, size=[10, 10], player_starting_position=[5, 5]) self.assertTrue("must be a string" in str(context.exception)) def test_sanity_ui_border_bottom_string(self): with self.assertRaises(Exception) as context: self.board = Board(name=100, size=[10, 10], ui_border_bottom=[]) self.assertTrue("must be a string" in str(context.exception)) def test_sanity_ui_border_top_string(self): with self.assertRaises(Exception) as context: self.board = Board(name=100, size=[10, 10], ui_border_top=[]) self.assertTrue("must be a string" in str(context.exception)) def test_sanity_ui_border_left_string(self): with self.assertRaises(Exception) as context: self.board = Board(name=100, size=[10, 10], ui_border_left=[]) self.assertTrue("must be a string" in str(context.exception)) def test_sanity_ui_border_right_string(self): with self.assertRaises(Exception) as context: self.board = Board(name=100, size=[10, 10], ui_border_right=[]) self.assertTrue("must be a string" in str(context.exception)) def test_sanity_ui_board_void_cell_string(self): with self.assertRaises(Exception) as context: self.board = Board(name=100, size=[10, 10], ui_board_void_cell=[]) self.assertTrue("must be a string" in str(context.exception)) def test_item(self): self.board = Board(name="test_board", size=[10, 10], player_starting_position=[5, 5]) self.placed_item = BoardItem() self.board.place_item(self.placed_item, 1, 1) self.returned_item = self.board.item(1, 1) self.assertEqual(self.placed_item, self.returned_item) with self.assertRaises(HacOutOfBoardBoundException) as excinfo: self.board.item(15, 15) self.assertTrue( "out of the board boundaries" in str(excinfo.exception)) def test_clear_cell(self): self.board = Board(name="test_board", size=[10, 10], player_starting_position=[5, 5]) self.placed_item = BoardItem() self.board.place_item(item=self.placed_item, row=1, column=1) self.assertIsInstance(self.board.item(1, 1), BoardItem) self.board.clear_cell(1, 1) self.assertIsInstance(self.board.item(1, 1), BoardItemVoid)