Contents
Peg Solitaire (2) Sample Help

Sample Description: Peg Solitaire (2)

Points of Interest

Playing Peg Solitaire (2)

Program Overview

Control

Image

For Help on Help, Press F1


Program Overview

Initializing the Program

The program is initialized with the ResetApplication method.  This command is executed when the File/Reset menu entry is clicked.  Initialization is accomplished by the executing Controls.PegInit.  Each of the peg images on the form are derived from a specialized Image control named PegImage.  This object has a method called PegInit which basically displays a bitmap of a peg in the hole.  In addition, a GameStarted property is set to 0 (or False) and an instruction caption is set to "Click to remove first peg..."

The First Click

When the mouse is clicked over one of the pegs at the beginning of the game, since the GameStarted property if False, the action is simply to change the bitmap in the PegImage control under the mouse to remove the first peg.  In addition, the GameStarted property is set to -1 (or True) and an instruction caption is set to "Game is in progress..."  Once this property is set to -1, no other MouseDown actions are processed.

Starting the Move with DragStart

All jumps must start with the DragStart method.  When the Right Mouse Button is clicked and dragged over a PegImage control, if it has a peg, its Picture property is changed to reference a bitmap containing a hole (i.e., no peg).

Each PegImage on the board has a PegID property which indicates its location.  This PegID is used to set the source of the drag, or the peg that is jumping another peg.

When the move is completed, the MoveOver method is called.  This method examines the state of the board using the MoreMoves method to determine if any legal moves remain.  If no remaining moves remain on the board, the game is ended.

Finishing the Move with DragAndDrop

When a DragAndDrop event is triggered on one of the PegImage controls, it first checks to make sure it has a hole.  If it does not have a hole, it is considered an illegal move and the drop is canceled.

If a hole exits on the image receiving the DragAndDrop event, the PegID is passed to the forms ValidMove method which determines if the move is legal or not.  If the move is illegal, the drop is canceled, otherwise the image is changed from a hole to a peg and the move is completed.


About Peg Solitaire 1
Peg Solitaire (2)

The game Peg Solitaire is an Envelop version of a board game played in the eighteenth-century.  You will learn how to play the game as well as some programming techniques used to develop the game.

Peg Solitaire is usually played with a board containing several holes, each containing some type of peg.  The objective of the game is to remove pegs by jumping one peg over another, until only a single peg remains on the board.

The game begins with all the holes on the board filled except for one.  The player may choose which hole should be empty.  The player then jumps one peg over another into an empty hole on the other side of the peg.  The Envelop version of the game will not permit any illegal moves.  The player then attempts to remove all pegs from the board until only a single peg is left,


Playing Peg Solitaire 1
Playing Peg Solitaire (2)

At the beginning of the game, all holes on the electronic board are filled with peg images.  The File/Reset menu command will reset the board to this initial state.

To begin play, click the Left Mouse Button on any peg to remove it from the board.  Once the first peg is removed, continue play by jumping one peg over another into an empty hole.  To perform a jump, position the mouse cursor over the desired peg to move, click and hold the Right Mouse Button, then drag it over the peg to be jumped and releasing the Right Mouse Button over the empty hole.  If the move is illegal, the peg will automatically be returned to its starting point.

When no more moves are possible, Envelop ends the game, displays the number of pegs remains as well as your rank.  Below is a list of rankings:

Pegs Left	Rank

1	General

2	Captain

3	Sergeant

4	Private