==========
Snake Game
==========
v0.01 (??) by "//hIDRA_5" with modifications by PEW

(this document by Peter E. Williams [PEW])

The original snake game for Delphi was by //hIDRA_5, and can be downloaded from http://www.delphi-source-code.com (until he updates it with this new version).

I am one of many people who have visited the above site and downloaded the source to the original game. The attached files form the new version of the snake game, as modified, enhanced and debugged by myself. I am sending this new version (0.01) including this file, to //hIDRA_5, in the hope that it will become the "official" next version, replacing the original.

Firstly, I would like to thank "//hIDRA_5" for sharing his source code and cool little game with the rest of the world. I hope that the new version will be accepted as an improvement to it. :-)))

The following 2 Windows Fonts are required by my version (possibly already exist on some systems):

ALGER.TTF   - Algerian true type font
OLDENGL.TTF - Old English true type font

(See 8 & 15 for references to bugs (2) which have been fixed. :-)))

The following is a list of changes (in no particular order):

1. The following are new units (& frm's):

* untHiscores.pas (& .frm) (used for high score table)
* untCongrats.pas (& .frm) (used to input player name when he/she reaches the high score table)
* untMyInifiles.pas (for .ini file ... based on IniFiles.pas but with added procs: MyReadBool & MyWriteBool
* "BTBeeper" (freeware component used for pc speaker sound, not written by me. I got it from the Delphi Super Page and did a few mods with the author's permission via a Delphi yahoogroups email list [ http://www.yahoogroups.com/delphi-programming/ ]) [all files are included in additional zip file for the Beeper source code, "beeper_src.zip"].

2. untSettings (.pas & .frm) have been removed. The has been replaced by 6 submenus to the "Options / Level" menu (renamed from "Options / Settings" in original). The submenus of the "Level" menu are 6 levels (same as before) and have shortcuts of ctrl-1 to ctrl-6 (set in FormCreate [6])

3. snake.res file modified. There are now 5 snake icons, these are also included as .ico files.

4. High scores saved in file: snake.his (txt).

5. (untGame.pas) read_inifile & save_inifile procedures added. The game now automatically saves a number of settings to an .ini file (program name.ini), when the program is exited. The file is read (if it exists) when the program is first run.

6. (untGame.pas) FormCreate has changed quite a lot.

7. (untGame.pas) New global const's:

  TimeToWaitBase = 20; // time to wait values in menu
  // start at TimeToWaitBase + 20 (interval between values)
  DefaultTimeToWaitBeforeMovingTarget = 120;

  added. Used in TfrmGame.TmrSnakeTimer (proc) [8] and SetAnyTimeToWait (proc) [9],

  and private var's
    CountToWaitBeforeMovingTarget,
    TimeToWaitBeforeMovingTarget : Integer;
  added.

  these control how often the target is moved (in timer intervals).
  
8. (untGame.pas) TfrmGame.TmrSnakeTimer (proc) has also changed quite bit. Note the changes to the case statement; now only 1 statement per case, instead of before approx 17 statements (requiring 2 new vars). Code is added AFTER the case. 

   Note that the "if PntInTarget(NewLeft, NewTop) then ..." statement (refer to code) now does NOT have anything added (+) to either NewLeft or NewTop ... this corrects a bug.

   Note the addition of:

    if want_sounds then
      BTBeeper1.BeepFor( 500,10 );

    which adds code for sound effects (e.g. a pc speaker beep) when the target has been eaten.

   Note also at the beginning of the proc, the following new code:

  if TimeToWaitBeforeMovingTarget > 0 then
  begin
    CountToWaitBeforeMovingTarget :=
      CountToWaitBeforeMovingTarget + 1 mod TimeToWaitBeforeMovingTarget;
    show_panel1;
    if CountToWaitBeforeMovingTarget >= TimeToWaitBeforeMovingTarget then
    // move the target
      DrawTarget;
  end;

    which moves the target at specified intervals (selectable from the menu).

9. (untGame.pas) SetAnyTimeToWait (proc) added to handle menu clicks for setting TimeToWaitBeforeMovingTarget (see 7).

10. (untGame.pas) Sound1Click (proc) added to handle "Options / Sound" menu click. Global var Want_sound added.

11. (untGame.pas) FormClose proc added.

12. (untGame.pas) NewPointIsValid (proc) has a few changes.

13. (untGame.pas) all statements which were:
  "PutStatus('Score: 0',0);" 
      have been replaced with:
  show_panel1;

   Show_panel1 is a new proc, which also displays additional info on panel1 of the status bar.

14. (untGame.pas) mnuNewClick has some changes.

15. (untGame.pas) DrawTarget (proc) has the following change to it's until statement:

  until ValidPoint(X*W,Y*H) and ((OldX <> X) or (OldY <> Y));

     Note the (X*W,Y*H) ... this fixes a bug !!!

16. (untGame.pas) mnuAboutClick (proc) amended.

17. (untGame.pas) mnuAlwaysClick (proc) amended. Now uses var always_on_top.

18. (untGame.pas) the tmainmenu has quite a few changes. Also the target is now clLime not clBlack (as originally).

19. (untGame.pas) 2 new vars added: 
    game_over, game_paused, want_borders : Boolean;
   used in various places.

20. (untGame.pas) ViewHighScores1Click (proc) added to handle click for "Game / View High Scores" menu.

21. (untGame.pas) HowtoPlay1Click (proc) added.

22. (untGame.pas) in tmainmenu, new menu "Options / Borders" added. Selecting this menu toggles borders on/off. When borders are "on" game plays as original. When borders are "off", the snake move through the border(s) e.g. the game board is circular. New global var (boolean) added for this, want_borders (see 19).

NB - there are probably a few more changes that I've missed. :-)))

   To "//hIDRA_5": I hope that you like and approve of these changes. Would you please upload the new version of this code to the web site (listed above) as the next version, for others to download? BTW, I make no claims at being a great Delphi coder. This was just something that I enjoyed doing on my Christmas holidays. Merry Christmas & A Happy New Year!!!

--- Peter E. Williams
26 Apr 2002
Canberra, Australia

mailto:pew@pcug.org.au (or)
mailto:pwill@ausi.com

