Skip to main content

Shift Puzzle

2d shift puzzle. About 130 lines. Simple example of a 2d game with mouse control using pygame.


Lars P
(larsp90)
2d shift puzzle. Left mouse click on a tile next to the empty tile moves that tile there. Right mouse button shows the solved puzzle image temporarily. The initial display shows the solved puzzle. The first mouse click shuffles the tiles. The whole game is about 132 lines. It is meant to be a simple example of a 2d game with mouse control using pygame. It is also fun to play (for a while).

Links

Home Page
https://github.com/larsp90/pygame-shift-puzzle

Releases

Shift Puzzle 1.0 — 17 Sep, 2016

Pygame.org account Comments

  • Coderess 2016-12-15 21:30:18

    Hey this is an awesome game! Just out of intrest how long did this take for you to code?

    Lars P 2017-03-12 10:55:24.633773

    It took me about 2 days. The idea was to create a simple example of a mouse controlled game. Hopefully I will have time to do some more, like a card game which requires mouse dragging.
  • Andréoti Castillo 2017-01-13 22:19:43

    i can not move the tiles

    paveway3 2017-01-23 14:26:57

    I had this problem too. Determined that it was a problem converting the mouse position to a tile position. I changed lines 118 and 119 from:
    c = mouse_pos[0] / TILE_WIDTH
    r = mouse_pos[1] / TILE_HEIGHT
    to:
    c = mouse_pos[0] // TILE_WIDTH
    r = mouse_pos[1] // TILE_HEIGHT
    The division operator was returning a float, so c and r would not evaluate correctly in the following if statement. I assume it was working correctly for the author, so it may be a difference in implementation. I notice that the screenshot is from Ubuntu, (no way of knowing what version of Python). I am running Python 3.4 on Windows.

    paveway3 2017-01-23 14:55:28

    I probably should have done some research before my initial post... The division operator ( / ) does floor division with integers in Python 2 and does 'true division' in Python 3. The floor division operator ( // ) was added in Python 3 and Python 2.2+. Therefore, I presume that the author wrote this with 2.x where c = mouse_pos[0] / TILE_WIDTH would have returned an int and worked correctly.

    Lars P 2017-03-12 10:56:22.679495

    All true. I used Ubuntu and Python 2. Thanks for pointing this out.