Beispiel #1
0
    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))
Beispiel #2
0
    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))
Beispiel #3
0
    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))
Beispiel #4
0
    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))
Beispiel #5
0
    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))
Beispiel #6
0
def create_board_wizard():
    global game
    global is_modified
    global current_file
    global default_map_dir
    game.clear_screen()
    print(Utils.blue_bright("\t\tNew board"))
    print("First we need some information on your new board:")
    name, width, height = None, None, None
    if game.config(
            "settings")["last_used_board_parameters"]["name"] is not None:
        name = game.config("settings")["last_used_board_parameters"]["name"]
    else:
        name = "New Board"
    name = str(input(f"Name (default: {name}): ")) or name
    if game.config(
            "settings")["last_used_board_parameters"]["width"] is not None:
        width = game.config("settings")["last_used_board_parameters"]["width"]
    else:
        width = 20
    width = int(
        input_digit(f"Width (in number of cells) (default: {width}): ")
        or width)
    if game.config(
            "settings")["last_used_board_parameters"]["height"] is not None:
        height = game.config(
            "settings")["last_used_board_parameters"]["height"]
    else:
        height = 20
    height = int(
        input_digit(f"Height (in number of cells) (default: {height}): ")
        or height)
    game.add_board(
        1,
        Board(
            name=name,
            size=[width, height],
            ui_borders=Utils.WHITE_SQUARE,
            ui_board_void_cell=Utils.BLACK_SQUARE,
        ),
    )
    is_modified = True
    current_file = os.path.join(default_map_dir,
                                name.replace(" ", "_") + ".json")
    game.config("settings")["last_used_board_parameters"] = {
        "name": name,
        "width": width,
        "height": height,
    }
    if game.get_board(1).size[0] > 20 or game.get_board(1).size[1] > 20:
        game.enable_partial_display = True
        game.partial_display_viewport = [10, 10]
Beispiel #7
0
    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))
Beispiel #8
0
 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")
Beispiel #9
0
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)
Beispiel #10
0
            "height": None,
        }
        game.config("settings")["object_library"] = []


# Main program
game = Game()
current_file = ""
game.player = Player(model="[]")
key = "None"
current_object = BoardItemVoid(model="None")
current_object_instance = BoardItemVoid(model="None")
object_history = []
viewport_board = Board(
    name="Viewport testing board",
    size=[viewport_width * 2, viewport_height * 2],
    ui_borders=Utils.GREEN_SQUARE,
    ui_board_void_cell=Utils.RED_SQUARE,
)
game.add_board(2, viewport_board)
current_menu = "main"
while True:
    game.clear_screen()
    print(
        Utils.cyan_bright("HAC-GAME-LIB - EDITOR v" +
                          Constants.HAC_GAME_LIB_VERSION))
    # Create config_dir if not exist and populate it with a directories.json file.
    if (not os.path.exists(config_dir) or not os.path.isdir(config_dir)
            or not os.path.exists(base_config_dir)
            or not os.path.isdir(base_config_dir)
            or not os.path.isdir(editor_config_dir) or not os.path.exists(
                os.path.join(editor_config_dir, "settings.json"))):
Beispiel #11
0
    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))