Simon Memory Game

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 

     

We receive a few cents from each purchase.  Thanks

 


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa 365 Puzzlers  Calendar 2017

Mensa 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

Problem Description

Here is a Delphi implementation of the classic electronic memory game,  Simon.  The program produces increasingly long sequences of light and tones which the player must then repeat.  The first user error ends the game.
  

Background & Techniques

This program was written and sent to me by Shane Holmes.   I made a couple of cosmetic changes, adding a track bar to replace numeric input to set the speed at which the light/sound sequences are displayed and inverting Shane's "High Scores" list so that the highest scores appear at the top of the list.

Non-programmers are welcome to read on, but may want to skip to the bottom of this page to download an executable version of the program.

The code is pretty straightforward.  TShape components are used for the lights.   A TObjectslist, Lights,  is used to hold the current sequence of lights by filling it with TIntObj integer objects.   The TIntObj object is defined in the U_Common unit.

After the initial random entry is placed in Lights by the start button click procedure, successive entries are generated each time the user has correctly clicked the number of lights in the list.   When the user finally clicks an incorrect light, a loser message is delivered and if the count is among the top 5 found so far, a user name and score are added to the list  of top scores.

The U_Common unit defines the TScores object which maintains top scorers information.  It is similar to my TScores unit except that Shane uses  file streaming to save the high scores, while mine uses an "Ini" text file.   This makes the data in the list less prone to user editing, which may or may not be an advantage.    But is is a good example of what is required to save an arbitrary set of integer and string data to a file stream. 

U_Common also contains a function, WinOpSys,  which returns the currently running version of Windows.  I ended up not using the function in this program  but retained  the code because it might come in  handy someday. 

Addendum February 17, 2004:  I discovered that the Windows version of the Beep procedure used to generate sounds for Simon didn't work at all well for Windows 95, 98, and ME.  The procedure reverts to a message beep for these systems which operates asynchronously, meaning it does not wait for the beep to finish before continuing to execute code.  The for faster play speeds the result is that beeps are lost making it very confusing to play.    Today's version uses a routine that generates tones of the proper length using the PC speaker for Windows ME and lower.     A big improvement.

Running/Exploring the Program 

bulletDownload source
bulletDownload  executable

Suggestions for Further Explorations

Two player version
User control of number of lights.

 

Original Date: February 15, 2004

Modified: July 29, 2017

 
  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2017, Gary Darby    All rights reserved.