Background:
I wrote this game after seeing something similar on another site
written in Shockwave, and I wondered if it would be possible to
create the same functionality using Flash. There are other Flash
versions of this classic card game around, but none with the score-keeping
functionality I wanted. This is my second publicly released FLA
file, and is vastly more complicated than my first. Whilst I have
radically improved my ActionScript coding skills for it's creation,
I am in no way suggesting that the design is flawless, so please
do let me know if you have any suggestions, or if you make improvements
to the code, or spot any bugs in it.
Thanks:
The stopwatch function code used in this game were developed by
Mike Gieson. They came from an FLA file he published at flashkit.com,
and he has kindly granted me permission to reuse his code for this
game. The stopwatch functionality he developed is very reliable,
and has a very low drain on system resources. I have also borrowed
a couple of graphics from his original file which I have edited
to fit the style of the game. Thanks Mike ;-)
The
Game Concept and Rules:
The game contains 24 cards (increasing or decreasing this number
is not a simple task) which are dynamically shuffled every time
a new game is started using the Math.random function. Cards are
animated when they are flipped, and a user may only flip two cards
at a time. After two cards are flipped, they remain visible for
a short period to give the user a chance to remember their positions,
before returning to a face down position. If the user clicks a new
card while two are face up, the previous two flip back over straight
away. Games are timed with a stopwatch which can be paused at any
time during the game. While the game is paused cards may not be
flipped. The number of flips attempted is also recorded as the user
plays, and both the user's time and total flips are presented to
them on completion of the game. If
the user makes more than 999 flips, a game over message is displayed
- likewise if the clock runs over 59 minutes and 59 seconds. Without
these checks the variables might overflow and cause runtime errors
on the user's PC. After completion, the game will check a scoreboard
to see if the user has beaten any of the top 5 times or lowest 5
total flips. If they have, they will be presented with an opportunity
to enter their name and win a place on the scoreboard which will
be displayed after they enter a name. If a high score is not achieved,
the high score chart is displayed after a short delay upon completion.
A local record is also kept of each user's best time and lowest
flips. This is updated silently whenever the records are beaten,
and is displayed continuously on screen.
The
Scoreboard:
The scoreboard works on a synthesis of a PHP scoreboard script.
PHP is only needed at all because Flash has no built in functionality
to write to ASCII text files. Included within this scoreboard system
is a server time-out check - if the server takes too long to respond
or to read the scoreboard, the Flash file will fail gracefully and
display a server time-out message. The scores are saved to an ASCII
text file in a format which can be split into an array when read
by Flash. This feature can be switched on or off by the developer.
The
Personal High Score System:
The final section I developed is for recording the personal best
scores of each individual user. This is done with Javascript which
is run silently from within Flash. No Javascript is needed for the
page containing the flash file. Two cookies are used, one for the
best time, and another for the lowest flips. These are read using
Javascript whenever that user opens the game, and updated whenever
the user beats their scores. This is done without any user input,
and is simply displayed on screen. This feature can be switched
on or off by the developer.
IMPORTANT! -
To make the Javascript for this system work, you must set both the
name and ID properties of the Flash movie on you html page to "CardGame"
and set the MovieTitle variable accordingly. If you forget this,
the Javascript won't work.
Customisation:
There are 7 variables which can be changed by the developer. They
are in the first frame of the "Actions" layer in the card
game movie. These are as follows:
UseScoreboard |
Set to
either true or false.
This determines whether the scoreboard functionality is used.
If set to false, the PHP file is not needed, nor is the scoreboard
text file and neither are their defining variables below. |
UsePersonalBest |
Set to
either true or false.
This determines whether the personal high score functionality
is used. If set to false, the area where personal high scores
are displayed is set to invisible, and the Javascript functions
are not called. |
MovieTitle |
This is
what you have used as the name
and ID properties of your movie
in the html file containing it. If you are using the personal
high score system, you MUST specify this, and you must also
add the name and ID tags to your html, because without it the
Javascript won't work. |
ScoreboardScriptFile |
The name
and location of your PHP scoreboard file. This is can be either
a relative path or an absolute path just as any link on an html
page would be to an image etc. Only needed if UseScoreboard
is set to true. |
ScoreboardScoresFile |
The name
and location of your text file where your scores are kept. This
is can be either a relative path or an absolute path just as
any link on an html page would be to an image etc. Only needed
if UsePersonalBest is set to true. |
TimeCookieName |
The name
for the cookie to save the user's personal best time. You only
need change this if you happen to be using another cookie with
the same name (highly unlikely) |
FlipsCookieName |
The name
for the cookie to save the user's personal lowest flips. You
only need change this if you happen to be using another cookie
with the same name (highly unlikely) |
The PHP file
included requires one variable to be modified. The variable is on
the second line of the file and is called "$filename".
This needs to point to your "scoreboard.txt" file which
can be a relative or an absolute path - if you use a relative path,
it must be relative to the PHP file, not to the flash movie.
You only need to change this variable if the "scoreboard.txt"
and "scoreboard.php" files are not being kept in the same
folder.
If for
example your "highscores.php" file is in a folder
called "php-bin" and your "scoreboard.txt"
file is in a folder called "results" on the same level,
for the PHP script to read the scores file, it needs to drill
up one directory and then drill down to the "results"
folder to find it, so in this example your path would be "../results/scoreboard.txt"
("../" means up one level). An absolute path will
also work such as "/results/scoreboard.txt" - Absolute
paths start with a "/" which is the root of your site,
and are relevant only to the root of your site regardless of
where they are being used. |
 |
These are the
things which you can safely change in the code. The most obvious
thing you will want to change is the photos. By far the best way
to do this is just to update the existing photo symbols with new
photos, rather than importing new photos and trying to manually
reposition them on the screen. This is done as follows:
 |
First
make 12 jpeg images to use on your cards. They must all measure
EXACTLY 58 x 44 pixels. If they don't measure those exact
dimensions, the photos will look very bad on the screen because
Flash does not do a good job of stretching photos from their
original dimensions at such a small size. Anyway, select properties
on the Card you want to change. You will see a new dialogue
box - click Import to select a different photo with which
to replace the original. Do this for each Card.
|
You might want
to change the cards manually, or change the back of card graphic.
There is a symbol called Card Graphics
which contains 13 frames - one for each photo and a back of card
graphic. It is safe to edit this symbol. You may make the cards
larger or smaller by editing this symbol and it will have no adverse
effect on the game code. You can change the clipart I have used
for the background and the control panel (obviously), but I strongly
recommend leaving the code well alone unless you are very familiar
with the language. There is a lot of interconnected code throughout
the game, and in changing something you may be breaking a link somewhere
else in the game which is not immediately apparent.
Servers
and Installation:
For the scoreboard to work properly, your server must support PHP.
Also, you must be able to change the permissions of your files using
the UNIX command CHMOD. For servers which do not support PHP (this
includes almost all free hosts like Geocities and Angelfire), you
cannot use the scoreboard and will have to disable it. If you do
have PHP enabled, you must CHMOD your scoreboard.php file to 755,
and your scoreboard.txt file to 777. If these permissions are not
set, it won't work. You will need up upload bother of these files
to your server, making sure that the paths you upload them to are
reflected in the Flash variables which are looking for them (see
above). If you don't understand what I am talking about here, I
suggest disabling the scoreboard.
That should
be all you need to know to get the game working (and quite a lot
you don't need to know). If you have any questions, you can email
me at wwarby@hotmail.com,
but please do try to work through these notes first because I do
work full-time. I don't mind helping people out, as long as I haven't
already answered the question in this file. And please do let me
know if you use this game online. It's great to see my own work
implemented elsewhere on the Internet, and inspires me to publish
other files I create.
-William

|