Exemple #1
0
        # if game not ove then continue
        # and add a new two
        if (status == 'GAME NOT OVER'):
            logic.add_new_2(mat)

        # else break the loop
        else:
            break

    # the above process will be followed
    # 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:
Exemple #2
0
    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)
        else:
            pass
    else:
        sleep(2)
        if status == 'Game over':
            screen.blit(num.lose, (0, 0))
Exemple #3
0
 def test_move_down(self):
     mas = [[2, 4, 0, 2], [2, 0, 2, 0], [4, 0, 2, 4], [4, 4, 0, 0]]
     rezult = [[0, 0, 0, 0], [0, 0, 0, 0], [4, 0, 0, 2], [8, 8, 4, 4]]
     self.assertEqual(move_down(mas), (rezult, 24))
Exemple #4
0
    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!':
                screen.blit(num.win, (0, 0))

            else:
                screen.blit(num.lose, (0, 0))
            display.flip()
            sleep(1)
            changed = logic.move_up(mat)
            mat, flag = logic.move_up(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(
                '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)