Пример #1
0
    # in case of each type of move
    # below

    # to move down
    elif (x == 'S' or x == 's'):
        mat, flag = logic.move_down(mat)
        status = logic.get_current_state(mat)
        print(status)
        if (status == 'GAME NOT OVER'):
            logic.add_new_2(mat)
        else:
            break

    # to move left
    elif (x == 'A' or x == 'a'):
        mat, flag = logic.move_left(mat)
        status = logic.get_current_state(mat)
        print(status)
        if (status == 'GAME NOT OVER'):
            logic.add_new_2(mat)
        else:
            break

    # to move right
    elif (x == 'D' or x == 'd'):
        mat, flag = logic.move_right(mat)
        status = logic.get_current_state(mat)
        print(status)
        if (status == 'GAME NOT OVER'):
            logic.add_new_2(mat)
        else:
Пример #2
0
tiles = tiles_change(board)

running = True
while running:
    current_events = event.get()
    for e in current_events:
        if e.type == pygame.QUIT:
            running = False
        if e.type == pygame.KEYDOWN:
            if e.key == pygame.K_ESCAPE:
                running = False
    changed = False
    keys = pygame.key.get_pressed()
    if keys[pygame.K_LEFT]:
        board, changed = logic.move_left(board)
    elif keys[pygame.K_RIGHT]:
        board, changed = logic.move_right(board)
    elif keys[pygame.K_UP]:
        board, changed = logic.move_up(board)
    elif keys[pygame.K_DOWN]:
        board, changed = logic.move_down(board)

    tiles = tiles_change(board)

    status = logic.current_state(board)
    print(status)
    if status == 'Continue':
        if changed:
            board = logic.add_new_number(board)
            tiles = tiles_change(board)
Пример #3
0

tiles = tiles_change(board)

running = True
while running:
    moved = False
    current_events = event.get()
    for e in current_events:
        if e.type == pygame.QUIT:
            running = False
        if e.type == pygame.KEYDOWN:
            if e.key == pygame.K_ESCAPE:
                running = False
            if e.key == pygame.K_LEFT:
                board, moved = logic.move_left(board)
            if e.key == pygame.K_RIGHT:
                board, moved = logic.move_right(board)
            if e.key == pygame.K_UP:
                board, moved = logic.move_up(board)
            if e.key == pygame.K_DOWN:
                board, moved = logic.move_down(board)

    tiles = tiles_change(board)

    if moved == True:
        status = logic.current_state(board)
        if status == 'Continue':
            board = logic.add_new_number(board)
        else:
            if status == 'Congratulation!':
Пример #4
0
 def test_move_left_2(self):
     mas = [[2, 4, 4, 2], [4, 0, 0, 2], [0, 0, 0, 0], [8, 8, 4, 4]]
     rezult = [[2, 8, 2, 0], [4, 2, 0, 0], [0, 0, 0, 0], [16, 8, 0, 0]]
     self.assertEqual(move_left(mas), (rezult, 32))
Пример #5
0
 def test_move_left_1(self):
     mas = [[2, 2, 0, 0], [0, 4, 4, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
     rezult = [[4, 0, 0, 0], [8, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
     self.assertEqual(move_left(mas), (rezult, 12))
Пример #6
0
                's'):  # s 커맨드를 입력하면 로직이 작동한다.

            changed = logic.move_down(mat)
            mat, flag = logic.move_down(mat)
            status = logic.get_current_state(mat)
            print(status)
            if (status == '' and changed):
                logic.add_new_2(mat)

            elif (status != ''):
                break

        elif event.key == keyboard.KeyCode.from_char(
                'a'):  # a 커맨드를 입력하면 로직이 작동한다.

            changed = logic.move_left(mat)
            mat, flag = logic.move_left(mat)
            status = logic.get_current_state(mat)
            print(status)
            if (status == '' and changed):
                logic.add_new_2(mat)

            elif (status != ''):
                break

        elif event.key == keyboard.KeyCode.from_char(
                'd'):  # d 커맨드를 입력하면 로직이 작동한다.
            changed = logic.move_right(mat)
            mat, flag = logic.move_right(mat)
            status = logic.get_current_state(mat)
            print(status)