Exemplo n.º 1
0
    def __init__(self, screen: pygame.Surface, operator: GuiOperator):
        self.screen = screen
        self.operator = operator
        self.title = Text(screen, (250, 20), "Выбор режима", 50)
        builders = [
            ClassicModeBuilder(),
            AdvancedModeBuilder(),
            FlexSquareBuilder(),
            KingPoliceModeBuilder(),
            WallModeBuilder(),
            AllUnitsModeBuilder()
        ]

        director = Director()

        modes = [director.construct_game_mode(builder) for builder in builders]

        ai_mode = AiDecorator(
            director.construct_game_mode(FlexSquareBuilder()),
            AiAdapter(AI.init()))
        ai_mode.name = "Диагональные уголки с ИИ"

        modes.append(ai_mode)

        buttons = [
            CheckButton(screen, (100, 100 + 60 * i, 440, 45), modes[i].name)
            for i in range(len(modes))
        ]

        self.mod_pairs = list(zip(buttons, modes))

        self.back_button = Button(screen, (590, 590, 100, 60), 'Назад')
        self.go_button = Button(screen, (100, 590, 180, 60), 'Играть!',
                                colors.RED, colors.WHITE)

        self.chosen_mode = None
        self.checked_button = None
Exemplo n.º 2
0
def test_classic():
    director = Director()
    mode = director.construct_game_mode(ClassicModeBuilder())

    assert mode.size_map == 8

    positions = set()

    for unit, x, y in mode.arrangement:
        assert 0 <= x < 3 and 0 <= y < 3
        assert unit.type == Type.USUAL
        positions.add((x, y))

    print(len(positions))
    assert len(positions) == 9
Exemplo n.º 3
0
def test_triangle_builder():
    director = Director()
    mode = director.construct_game_mode(TriangleModeBuilder())

    assert mode.size_map == 8

    positions = set()

    for unit, x, y in mode.arrangement:
        assert 0 <= x <= 3 and 0 <= y <= 3
        assert unit.type == Type.FLEX
        positions.add((x, y))

    print(len(positions))
    assert len(positions) == 10
Exemplo n.º 4
0
def test_triangle():
    director = Director()
    mode = director.construct_game_mode(AllUnitsModeBuilder())
    board = Board(mode)
    for i in range(4):
        for j in range(3 - i):
            ni, nj = 8 - i, 8 - j
            assert board.map[i][j].type == board.map[ni][nj].type

    for i in range(4):
        for j in range(4 - i):
            ni, nj = 8 - i, 8 - j
            board.map[i][j], board.map[ni][nj] = board.map[ni][nj], board.map[
                i][j]

    board.map[0][0], board.map[4][4] = board.map[4][4], board.map[0][0]
    board.map[8][8], board.map[7][7] = board.map[7][7], board.map[8][8]

    assert board.is_game_finished() == board.player_A
Exemplo n.º 5
0
def test_classic():
    director = Director()
    mode = director.construct_game_mode(ClassicModeBuilder())
    board = Board(mode)
    assert board.is_game_finished() is None
    ex = (7, 0)
    for i, j in product(range(3), range(3)):
        board.do_move(i, j, ex[0], ex[1])
        ni, nj = 7 - i, 7 - j
        board.do_move(ni, nj, i, j)
        board.do_move(ex[0], ex[1], ni, nj)
    assert len(board.is_game_finished()) == 2
    board.do_move(7, 7, ex[0], ex[1])
    assert board.is_game_finished() is board.player_B
    board.do_move(ex[0], ex[1], 7, 7)
    board.do_move(0, 0, ex[0], ex[1])
    assert board.is_game_finished() is board.player_A
    assert board.is_game_finished() is board.player_A
    assert board.do_move(7, 7, 0, 0) is True
    assert board.is_game_finished() is None