1

I use the latest version of PyQt4, and python3.

The game I want to make its most common name is "sliding puzzle".

I know the easy part (start, reset, close, and the stopwatch time), but I have some issues with slides motion.

I created 15 QPushButtons inside a QGridLayout (shown in the attached image, here: Game Design:
Game Design), and I want to know how to move the clicked button based on these thoughts:

for each mouse click

  1. determine where the empty cell is, inside the GridLayout
  2. determine the surrounding non-empty cells
  3. if the click is on one of the surroundings
  4. switch the empty cell with the clicked one
  5. if not
  6. do nothing

I have these problems:

  1. I don't know how to determine the clicked object (widget) inside a specific GridLayout cell

  2. If I'm able to solve the 1st problem, I don't know how to switch the empty cell with a non-empty one

  3. I don't know how to randomise the arrangement of the buttons

  4. I also don't know how to check if the puzzle is solved (how to check the arrangement based on index of the buttons and their text values)

Any ideas?

If you have a better concept, I'll be happy to implement it inside the app.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
shahwan42
  • 75
  • 9
  • You can use a matrix to do that and create a matrix of button so that you can save index in the matrix to do randomise action and slid checking stuff .. – Ankur Jyoti Phukan Mar 18 '17 at 01:47
  • 2
    There is no need to move any buttons. Just hide the button that the space moves to, and then re-show the previously hidden button and change its text accordingly. – ekhumoro Mar 18 '17 at 03:31

0 Answers0