Programming Example: Cryptogram
A cryptogram is a coded message where each letter in the cryptogram puzzle stands for a different letter of the alphabet. The coded message is often a famous quotation, proverb, or maxim. The objective of the game is to decode the message.
This sample program was originally given as a student exercise, with the directive to write a VB application that will present a cryptogram puzzle to the user and provide a way for them to enter the solution.
Below is a screenshot showing my implementation:
Following is information from the help file written for the application, which will be displayed when the user clicks the "Instructions" button. It can also provide a guideline for how you might go about designing this application. Bear in mind that this applies to my implementation; you may have an entirely different vision of how this might be done. Feel free to use all, any, or none of the ideas presented here for your own implementation.
When you start the game, a new puzzle is displayed on the interface as black letters on gray tiles, with space separating each word in the puzzle. Above each gray tile is a black box in which you type the letter that the coded letter below it represents. The letters you type in the black boxes will be displayed in green.
Whatever letter you type for a coded letter will automatically be propagated throughout the puzzle. For example, if you type an "A" above an "X" tile, then the letter "A" will appear over ALL "X" tiles.
Whenever you type a letter in a black box, the cursor will automatically move forward to the next unused black box. To move forward to any black box, use the <right arrow> key, the <Tab> key, or click it with the mouse. To move backward to any black box, use the <left arrow> key, the <Shift-Tab> key combination or click it with the mouse. To move up or down a line, use the <up arrow> and <down arrow> keys. To go directly to the beginning of a line, use the <Home> key; to go directly to the end of a line, use the <End> key.
To delete a character in a black box, press the <Delete> key if the insertion point appears to the left of the letter, or press <Backspace> if the insertion point appears to the right of the letter.
Only letters may be entered into a black box; input of any other character is inhibited. Also, input of any letter you have already used will be inhibited. If you wish to change a coded letter to a letter you have already used, you must first delete the original occurrence of the letter.
Displays the help screen.
This option checks your solution and temporarily changes the color of any incorrect letters to red (if you have not completed the puzzle, only the letters you have entered so far will be checked). Once you type a new letter or click another command button, all letters will turn back to green.
If you have completed the puzzle and your solution is correct, you will be asked if you want to play another game. If so, a new puzzle will be presented; otherwise, the program will end.
If your solution is incomplete or incorrect as this point, you will first be asked if you are sure you want to see the answer. If you choose Yes, the game board will temporarily freeze as the answer is revealed. At that point, you can either start a new game or exit.
If your solution is correct, you will be asked if you want to play another game. If so, a new puzzle will be presented; otherwise, the program will end.
This option starts a new puzzle. If you already have a game in progress, your solution will be checked to see if it is incomplete or incorrect, and if so, you will be asked if you want to abandon the game before moving on.
If you abandon the game, the solution for the abandoned game will be shown to you, then the new game will start.
Download the solution for this project here.