Microsoft HomeProductsSearchSupportShopWrite Usspacer.gif Microsoft Home
AFC Samples
 In this topic

*Description

*Sources

 

AFC Samples   PreviousAFC SamplesNext
    Previous AFC
Samples
Next

 


Puzzle15 Sample Applet

The Puzzle15 sample is a fun and challenging demonstration of property sheets, marquees, and other controls.

Description

When the applet first loads, a Property dialog box is displayed showing the game options. The Scrambling Spinner edit control is used to enter 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 the effect on the puzzle when the arrow keys are pressed.

  1. The first option will cause a button to occupy the area where the blank space currently is, if possible (that is, pressing the LEFT ARROW key will have no effect when the blank is on the right side of the puzzle).
  2. The second option will cause 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).
  3. The third option causes the arrow keys to move the focus between buttons (the blank piece cannot accept focus).

When a button is adjacent to (or in the same row or column) the blank space, pressing the SPACEBAR or the ENTER key will cause the button with the focus to move in the direction of the blank (as if the button had been pressed by the mouse).

The Marquee provides status on the solver thread, as well as the user's status relative to the solver thread.

The Statistics panel informs the user on the number of moves he or she has made so far, and the minimum number of moves from the current position that will be required to reach the goal. 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.

The Puzzle15 application and applet demonstrate the use of property sheets (UIPropertyDialog, UIPropertyPage), message boxes (UIMessageBox), menus (UIBandBox, UIBand, UIMenuButton, UIMenuList, UIMenuItem, UILine), buttons (UICheckButton, UIRadioButton, UIPushButton), and various other UI controls and classes (AWTUIApplet, UIApplet, UIFrame, UIPanel, UIGroup, UIViewer, UIGraphic, UIText, UIButtonBar, UISpinnerEdit, UIGridLayout, UIBorderLayout, UIVerticalFlowLayout, UISplitLayout).

Menu Options:
F2 Starts a new puzzle. A new puzzle is created by scrambling the goal puzzle the specified number of moves.
F4 Restarts current puzzle. The puzzle currently displayed is restored to its original state.
F3 If the solver has found an optimum solution, a dialog box will come up and display the solution as a list of arrow key moves (U = up, L = left, D = down, R = right).
F7 Game options. Displays property pages that allows the user to change the game parameters.
Ctrl-Z Undo move. Undo last move: disabled when no moves are on the move stack.
Ctrl-X Terminate Application: Disabled when the game is run as an applet.

Sources

This sample applet consists of the following sources:
Puzzle15.java
Pz15AccGrfxBtn.java
Pz15Callbacks.java
Pz15Consts.java
Pz15ControlPanel.java
Pz15Data.java
Pz15GamePanel.java
Pz15Images.java
Pz15InfoPanel.java
Pz15Marquee.java
Pz15Menu.java
Pz15Options.java
Pz15PropGame.java
Pz15PropNav.java
Pz15Solver.java
SDKInsetPanel.java

Top