コード例 #1
0
 def test_square_from_pos(self):
     # init constants with 2 person game
     Blockies.Game(2)
     test_values = {
         (0, 0): (0, 0),
         (0, 0): (-57, -57),
         (0, 0): (-57, 57),
         (0, 0): (3, 57),
         (0, 0): (57, 57),
         (0, 0): (57, 3),
         (1, 0): (83, 57),
         (2, 3): (163, 240),
     }
     for square, point in test_values.items():
         self.assertEqual(
             square, Blockies.square_from_pos(point),
             'point in wrong square: {} on a {} square size grid'.format(
                 point, const.SQ_SIZE))
コード例 #2
0
ファイル: main.py プロジェクト: bfaloona/blockies
    pygame.draw.polygon(screen, const.LT_YELLOW,
                        [[650, 300], [650, 525], [725, 525], [725, 450],
                         [800, 450], [800, 375], [725, 375], [725, 300]])

    pygame.display.flip()  # Update display
    clock.tick(60)  # Limit to 30 frames per second

while not game.done:
    for event in pygame.event.get():  # User did something
        if event.type == pygame.QUIT:  # User clicked close
            quit(0)
        elif event.type == pygame.KEYDOWN:
            if pygame.key.get_pressed()[pygame.K_UP]:
                game.active_piece = game.next_available_piece()
                game.active_piece.move_to(
                    Blockies.square_from_pos(pygame.mouse.get_pos()))
            elif pygame.key.get_pressed()[pygame.K_DOWN]:
                game.active_piece = game.previous_available_piece()
                game.active_piece.move_to(
                    Blockies.square_from_pos(pygame.mouse.get_pos()))
            elif pygame.key.get_pressed()[pygame.K_RIGHT]:
                game.active_piece.rotate_clockwise()
            elif pygame.key.get_pressed()[pygame.K_LEFT]:
                game.active_piece.rotate_counter_clockwise()
            elif pygame.key.get_pressed()[pygame.K_q]:
                quit(0)
            game.active_piece.set_color(
                game.players_lt_colors[game.player_index])

        elif event.type == pygame.MOUSEBUTTONDOWN:
            game.update_active_piece(event.pos)