Hangman #1

[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

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 15, 2018

 

 

 

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