The 15 Game


You may recall the popular game where 15 tiles are arranged in a four-by-four layout, and one space is open.  The player’s objective is to arrange the numbered tiles in numerical sequence from 1 to 15, by moving tiles into the open space.

Write a program that uses a 2D array to play the 15-game.  The game must include the following features:

  • The board is randomly arranged at the start.
  • Buttons allow the player to restart and quit the game.
  • Score is kept of the number of moves taken by the user to arrange the sequence correctly.  The player must use as few moves as possible to arrange the tiles.
  • Cheating must not be allowed.  Only tiles adjacent to the open space can be moved.

Some things to consider

  • In the game, the block to be moved is clicked.  
  • There is only one cell to move to: the empty one.  
  • You need to keep a variable to hold the values of X and Y for the empty cell.  
  • When a block is clicked, your program checks to see if the stored values are only one away from the given cells.  
  • If this is correct, it moves the cell, then updates the values of X and Y for the now empty cell.


Step 1:  Design the screen for the game.  Consider all the buttons a user needs to play.  Draw a rough sketch of the screen layout, labeling each object.

Step 2: Write algorithms to perform each of the actions the user performs.  One algorithm per button/event is required.

Step 3: Create an instruction sheet for the player.  Type up user instructions, the capabilities of the hardware required, etc.  About a page should do it.


Step 1: Write and test the program.  Write and test as you gol don’t write huge chunks of code, then try to debug it.

Step 2: Hand in the source code, and the manuals/instructions sheet for marks.

Credit Blundell@MonktonCombe

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.