GNVQ Advanced IT - Solitaire Game in JavaScript
Play Game
Programme details
Game rules
Form design
Programme design
Solitaire
Cards
Cards left
in the pack
Cards Taken
Choice 1
Choice 2
Controls
Game rules.
Top of page
The pack of cards is shuffled
Four cards are dealt face-up in a row
If two cards on the top of any of the four piles form a pair (
ie same number irrelevant of the suit
)they are discarded
When all pairs have been taken, step two is repeated, dealing on top of the previous cards. If all cards have been dealt then the game is over.
If all cards have been dealt, and in the process all cards have been discarded in pairs then the game has been won.
Programme Details
Top of page
The game uses the following JavaScript:
Constructs;
Sequence
Iteration (
For/ do, while/do, repeat until loop
)
Selection (
If, then, Else or case
)
Features;
Setting variables
Using arrays
Usingevent handlers
Using the eval () statement
Using the string object
Creating custom objects
Dynamically updating form fields
The game interface provides the following detail:
Displays the current top card on each of the four piles of cards
Radio buttons to select the two matching cards to be removed
Control buttons to
Remove the selected pair
Deal four new cards
Start a new game
Quit
Counters to display
Cards left in the pack
Pairs of cards removed
Form design
Top of page
The four cards are displayed as text labels in the text input fields called card1, card2, card3 and card4.
Two cards (
choice1 and choice2
) are selected using two sets of radio buttons.
Two additional text fields called "hands" and "Taken" are used to display the cards left in the pack and cards taken.
Four buttons are provided:
take is used to discard a selected pair. (
an onClick event handler calls the takeCards() function
)
deal is used to deal four new cards (
an onClick event handler calls the dealCards() function
)
start is used to start a new game. (
an onClick event handler calls the startGame() function
)
exit is used to quit playing. (
an HTML document with a goodbye message by assigning anew URL to self.location
)
In addition to the form , the HTML <body> tag has an event handler that calls the startGame() function.
Top of Page
Home Page
Query for Tutor?