Hangman #1

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

Search

 

Search DelphiForFun.org only

Support DFF

 

If you shop at Amazon anyway,  consider using this link. We receive a few cents from each purchase.   Thanks.

In Association with Amazon.com

 

Support DFF

 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.

 

 

Contact

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

 

Search DelphiForFun.org only

 

 

 

 

Problem Description

Hangman #1 is the traditional game of Hangman.  One player, the hangman chooses a word kept secret from the other player, the convict.  The convict  guesses letters in the unknown word - he gets to see each correct guess placed wherever it occurs in the secret word.  Each incorrect  guess adds another piece to the gallows and an effigy of the hanging convict.  If he completes the word before the picture is complete, he goes free.  Otherwise, the convict is the big loser.  

Background & Techniques

This game provides the framework for a  future version with computer play.   Here we'll define the basic drawing strategy,  an array of 9  TPiece objects defining the  gallows and hanging man.   A TList component is an ideal place to keep a list of objects - HangManList is a TList containing the  parts of the drawing in the order that they should be drawn.  

Initially we get a "secret" word from the hangman - The passwordchar property is optionally used to hide the word   from prying eyes as it is being entered - the same technique used in password dialogs.  Then the "convict" makes letter guesses until he wins (completes the secret word) or loses (completes the drawing).

 The CheckALetter procedure  takes the convict's guess and either fills in the correct letter or draws one more piece and then checks if the letter was a winning or losing move.    A simple ShowMessage  call displays winning or losing messages.  

Running/Exploring the Program 

bulletBrowse source extract 
bulletDownload source 
bulletDownload  executable

Suggestions for Further Explorations

A future computer play version will use a dictionary to let the computer take the role of convict or hangman.  
I'm not sure if there is an "official" number of wrong guesses before the drawing is complete - ours has 9, but a harder version could end at 7  by , for example, drawing both arms or both legs as a result of a wrong guess.

 

Modified: May 18, 2009

 

 

 

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