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: break else: print("Invalid Key Pressed") # print the matrix after each # move. print(mat)
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) else: pass
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!': screen.blit(num.win, (0, 0))
def test_move_right_2(self): mas = [[2, 4, 4, 2], [4, 0, 0, 2], [0, 0, 0, 0], [8, 8, 4, 4]] rezult = [[0, 2, 8, 2], [0, 0, 4, 2], [0, 0, 0, 0], [0, 0, 16, 8]] self.assertEqual(move_right(mas), (rezult, 32))
def test_move_right_1(self): mas = [[2, 2, 0, 0], [0, 4, 4, 0], [0, 0, 0, 0], [0, 0, 0, 0]] rezult = [[0, 0, 0, 4], [0, 0, 0, 8], [0, 0, 0, 0], [0, 0, 0, 0]] self.assertEqual(move_right(mas), (rezult, 12))
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) if (status == '' and changed): logic.add_new_2(mat) elif (status != ''): break elif event.key == keyboard.KeyCode.from_char('x'): exit() #종료 커맨드 else: print("Invalid Key Pressed") # 이외의 키를 입력했을때 표시