Exemplo n.º 1
0
"""""""""""""""""""""
SIMULATION CODE BELOW
"""""""""""""""""""""

agent = HumanAgent()
agent.set_paddle_x(PADDLE_ON_RIGHT)
curr_state = get_initial_state(PADDLE_ON_RIGHT)
score = 0

while True:
    draw(window, curr_state, score)
    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_UP:
                agent.up_pressed()
            if event.key == K_DOWN:
                agent.down_pressed()
        else:
            agent.nothing_pressed()
    if curr_state.game_over:
        print('GG')
        print('You Scored: ' + str(score))
        pygame.quit()
        sys.exit()
    if curr_state.hit:
        score += 1
    curr_state = get_next_state(curr_state, agent)
    pygame.display.update()
    fps.tick(50)
Exemplo n.º 2
0
SIMULATION CODE BELOW
""" """""" """""" """"""

left_agent = HumanAgent()
right_agent = HumanAgent()
curr_state = get_initial_state()
total_hits = 0

while True:
    draw(window, curr_state, total_hits)
    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_w:
                left_agent.up_pressed()
            if event.key == K_s:
                left_agent.down_pressed()
            if event.key == K_UP:
                right_agent.up_pressed()
            if event.key == K_DOWN:
                right_agent.down_pressed()
        else:
            left_agent.nothing_pressed()
            right_agent.nothing_pressed()
    if curr_state.game_over0 or curr_state.game_over1:
        if curr_state.game_over0:
            print('Right Player Wins!')
        else:
            print('Left Player Wins!')
        print('Rally Score: ' + str(total_hits))
        pygame.quit()
        sys.exit()