Click here to Skip to main content
Click here to Skip to main content

Tagged as

A Picture Puzzle that Lets You Pick y'er Own'pic

, 17 Nov 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
A picture puzzle that allows the user to select any picture as a puzzle, along with options for tile sizes for those long car-rides.

Why the World Needs a New Picture Puzzle

The art of solving picture puzzles is a sadly missed part of our modern culture, and the current penury of pass-times which sharpen the mind is the focal point which incites well-meaning members of the World's Independent Masters of Picture Puzzles (WIMPPs International) to charter new grounds in their far-reaching quest to create better picture puzzles with which to delight us all.

Picture Puzzles Can't Cure Cancer

... but they can keep you from thinking too hard about getting cancer, and isn't that what really matters?

It's Just a Game

I think everybody has seen a sliding picture puzzle at some point in their lives. The only difference between this one and the ones your folks gave you on long road-trips is that this one is on your computer or whatever portable console you happen to be using. To move tiles around, just click the tile you want to move, and if it is next to the 'hole' tile, then it'll move to the hole-spot.

An added fun bit here is that you get to hear a soothing harp-like tinkle to the ear whenever a piece is placed in the right spot, better than hearing your kid-sister's constant kibitzing about which tile goes where, right! You can toggle-view the 'solution', or completed puzzle image, but I think the part of this puzzle you'll like most is that you can finally make a sliding-picture puzzle out of old Linda Carter 'Wonder Woman' images you can download off the internet. Come on, admit it, this is what you've been waiting for!

How Does It Work

The most important parts of this program, what makes it all tick, are these two arrays:

udtCartesian[,] udrImageIndices;
// 2d array of cartesian, initialized at newPuzzle() and used to draw image

Bitmap[,] bmp;
// 2d array of images drawn according to their position 
//                     tracked by udrImageIndices

Let's see if I can sum this up simply:

  1. There's a two-dimensional array of bitmaps which holds the images of all the tiles.
  2. Then there's a two-dimensional array of Cartesian (x,y) which is of the same size, and this array tells the program which tile is located where. Each element in this array is initialized when a new puzzle is created, and the puzzle is solved when udrImageIndices (udrII for short):
udrII[i,j].x = i

and:

udrII[i,j].j = j
for all i,j.

And when a tile is moved, the values of this array are swapped between the moving-tile's initial position and the moving-tile's final position. It is not that complicated, it might just seem so right now, because it's 3am and I didn't take my Flintstones vitamins today, but if you look at the code and think about it, it's really not much.

And that's the gist of it.

The puzzle is displayed on a single picture box by collaging all the bmp[,] images in the order that they are pointed to in the udrII[,] array. This picturebox has two event handlers: mousemove(), which sets a global Cartesian to the tile index of the tile under the mouse cursor, and a mouseclick() event handler which first tests if the tile clicked can be moved and then makes the move if it can. When tiles are moved, another global variable keeps track of where the 'hole' tile is, for quicker tests and future reference, and the puzzle is tested to see if it has been solved.

You might have noticed the class MessageBox (A Versatile MessageBox); it's a handy class, and though it's such a simple few lines of code, it really does the job where other message boxes are too formal with their 'Yes', 'No', and 'OK' buttons when the buttons you really need are 'medium' or 'large'.

Point of Concern

It is a puzzling circumstance, but due to current squabbling among the upper-echelon of the WIMPPS International, the world's leading riddle-league is not currently accepting membership applications.

History

  • 8th November, 2009: Initial post
  • 15th November, 2009: Updated source code

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Christ Kennedy
CEO unemployable
Canada Canada
Christ Kennedy, published his fourth novel "Cleats of the Counter Revolution" in the summer of 2010. He grew up in the suburbs of Montreal and is a bilingual Quebecois with a bachelor’s degree in computer engineering from McGill University and is currently walking across ontario plotting a new novel, far away from any computer.

Comments and Discussions

 
Suggestionpicture with curves PinmemberMember 1017486226-Jul-13 9:24 
GeneralI did one of those a while back PinmvpSacha Barber9-Nov-09 4:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.141022.1 | Last Updated 17 Nov 2009
Article Copyright 2009 by Christ Kennedy
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid