![]() |
Multimedia »
General Graphics »
Graphics
Beginner
License: The Code Project Open License (CPOL)
A Picture Puzzle that Lets You Pick y'er Own'picBy Christ KennedyA picture puzzle that allows the user to select any picture as a puzzle, along with options for tile sizes for those long car-rides. |
C#, Windows
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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.
... but they can keep you from thinking too hard about getting cancer, and isn't that what really matters?
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!
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:
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'.
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.
| You must Sign In to use this message board. | ||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
General
News
Question
Answer
Joke
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 17 Nov 2009 Editor: Deeksha Shenoy |
Copyright 2009 by Christ Kennedy Everything else Copyright © CodeProject, 1999-2010 Web17 | Advertise on the Code Project |