Puzzle15 Sample
This sample is located in \Samples\afc11\Puzzle15.
Description
Using the Sample
Key Project Files
Technologies Demonstrated
Description
The Puzzle15 sample is a game that displays a panel of scrambled numbers to be placed in their correct order. The sample shows how to use property sheets, marquees, and other UI controls. When the applet first loads, a property dialog box appears that contains tab pages for setting game and navigation options.
The Options property page contains two controls:
- The Scrambling spinner edit control sets the number of moves the puzzle will be scrambled.
- The Competition check box control determines whether a separate puzzle solver thread will be started.
The Navigation property page determines how pressing the arrow keys affects the puzzle.
The main game panel contains the following components:
- The Game menu contains a variety of options for running the game.
- The Marquee control provides status on the solver thread, as well as the user's status relative to the solver thread.
- The Statistics panel provides information on the number of moves made and the minimum number of moves required to reach the goal from the current position. This is the cumulative distance of each button to its goal position. For example, if the 1 button is in the bottom right corner, it will take at least six moves: up three rows, and then left three columns, to get it to its goal position, which is the top left corner. The Statistics panel also displays the number of moves in the optimum solution, as determined by the solver thread. The solver thread uses an iteratively deepening, depth-first search algorithm to determine the optimum solution. When the solver has found the optimum solution, the optimum solution text changes from At Least X Moves to Exactly X Moves.
Using the Sample
You can also run the sample as an application with the following command:
wjview Puzzle15
To use the sample
The object of the game is to unscramble the numbers (putting them in their correct order), using the minimum number of moves possible. To play the game, do the following:
- When the applet starts, a dialog box appears for selecting game setup options. On the Options tab, enter (or use the arrows to select) the amount of scrambling you want. If you don't want the computer to find an optimum solution, clear this option.
- Click the Navigation tab, select the navigation option you want to use with the arrow keys, and then click OK. The navigation options are as follows:
- The move buttons option causes a button adjacent to a blank space to move to the blank space, if possible (that is, pressing the LEFT ARROW key will have no effect when the blank is on the right side of the puzzle).
- The move the blank space option causes the blank space to move in the direction specified, if possible (that is, pressing the LEFT ARROW key will have no effect when the blank is on the left side of the puzzle).
- The select buttons option causes the arrow keys to move the focus between buttons; the blank piece cannot accept focus. With this option, when a button is adjacent to (or in the same row or column as) the blank space, pressing the SPACEBAR or the ENTER key causes the button with the focus to move in the direction of the blank, as if the button had been clicked by the mouse.
Note You can also use the mouse to select and move buttons.
- Rearrange the numbers by moving the buttons or blank space using the arrow keys or mouse clicks. Press CTRL+Z to undo a move, if necessary. The Statistics area reports your progress. The marquee displays a message if you exceed the optimal solution.
- The Game menu, displayed by clicking the Game button at the top of the main panel, contains the following options:
- New Game (F2) starts a new game by rescrambling the numbers by the specified number of moves.
- Restart Game (F4) restores the current game to its original state.
- Undo Move (CTRL+Z) undoes the last move. This option is disabled when no moves are on the move stack.
- Show Optimal Soln (F3) displays the optimal solution if the solver has found one. A dialog box appears showing the solution as a list of arrow key moves. In this list, U=up, L=left, D=down, and R=right.
- Game Options (F7) displays the property dialog box to select new options for running the game.
- An Exit (CTRL+X) option is also available when the game is run as an application. This option closes the application.
Key Project Files
Pz15Data.java
This class implements Pz15Consts. It scrambles the game pieces in accordance with the value set in the Options property page, and accepts and evaluates the user's move.
Pz15GamePanel.java
This class extends UIGroup and implements Pz15Consts. It updates the game board's internal representation as moves are made.
Pz15InfoPanel.java
This class extends UIPanel and implements Pz15Consts. It tracks and displays game statistics.
Pz15Solver.java
This class extends Pz15Data and implements Runnable and Pz15Consts. It calculates the optimal solution given the starting position.
Pz15PropGame.java
This class extends UIPropertyPage and implements Pz15Consts and IFxTextConstants. It defines the Game property sheet.
Pz15Options.java
This class extends UIPropertyDialog and implements Pz15Consts. It defines the Options property page.
Pz15PropNav.java
This class extends UIPropertyPage and implements Pz15Consts. It defines the Navigation property page.
Technologies Demonstrated
AFC
- This sample shows how to use AFC classes to create property sheets and various types of UI controls.
© 1999 Microsoft Corporation. All rights reserved. Terms of use.