The Museum of HP Calculators

Hangman Game for the HP-41CX

This program is Copyright © 1999 by Michael Harwood and may be freely used by permission.

This program is supplied without representation or warranty of any kind. Michael Harwood and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.

Overview

The object of thisgame is to guess a secret word that has been entered by someone else.
This game is played by two players, one inputs a word and the other tries to guess it letter by letter.  The word can be from 1 to 8 charactes long. Non-alphabetic characters should be avoided as it makes it too hard to guess.

Operation

NOTE: This program uses the extended functions ATOX and XTOA and thus requires an HP-41CX.

Example

Someone types in the word "EXCITING" for you to guess.
Keys              Display         Comments 
[XEQ] "HANGMAN"
                  ENTER WORD:
EXCITING          EXCITING
[R/S]             ________  @     At this point the person gives you the 41C
I [R/S]           ___I_I__  @     Guess an I
A [R/S]           ___I_I__  @~    Guess an A (I can't draw the hangman in HTML)
T [R/S]           ___ITI__  @~
R [R/S]           ___ITI__  @^    Another wrong guess
...
...
Two possible outcomes: (a) you guess the word in time or (b) you don't.
Outcome (a)
G [R/S]           EXCITING  @^    [Beep] - you win!
[R/S]             ENTER WORD:     Now you can play again.

Outcome (b)
Z [R/S]           EXCITIN_  @&    Final guess is wrong.
                  YOU DIE #       You lose.
[R/S]             EXCITIN_  @#    You can keep trying to guess the word.
F [R/S]           EXCITIN_  @#    Another wrong guess.

The Program

LINE CODE               COMMENTS
01 <>LBL "HANGMAN"
02 <>LBL 01             label for restarting game
03  "ENTER WORD:"
04  0
05  STO 10              set number of wrong guesses to zero
06  X<>F                clear all flags needed
07  32.09664512         code to draw men in correct sequence
08  STO 11
09  AVIEW
10  AON
11  CLA                 clear display (incase no word is entered)
12  STOP                prompt for new word
13  ALENG               * insert single player code in here -- see below
14  STO 08
15  9
16  X>Y?                check length of word
17  GTO 02
18  TONE 0
19  "WORD TOO LONG"
20  AVIEW
21  PSE
22  GTO 01
23 <>LBL 02             word is good (8 or less letters)
24  .007                loop counter
25  STO 09
26 <>LBL 03              store each letter and set flags for words < 8 chars
27  ATOX
28  STO IND 09
29  X=0?
30  SF IND 09
31  ISG 09
32  GTO 03
33  1                   change string length to ISG format (0.00n)
34  ST- 08
35  1000
36  ST/08
37 <>LBL 04              display word so far
38  RCL 08
39  STO 09
40  CLA
41 LBL 05              label for loop to create display
42  95
43  FS? IND 09
44  RCL IND 09
45  XTOA
46  ISG 09
47  GTO 05
48  "  @"              append 2 spaces and @ symbol (synthetic programming?)
49  AON
50  255                 check if all letters have been guessed
51  0
52  X<>F
53  X=Y?
54  GTO 07
55  X<>F
56  RCL 11              recall and append man to display.
57  INT
58  XTOA
59  STOP                wait for guess (one letter)
60  RCL 08
61  CF 09
62  ATOX
63 <>LBL 06              check if the letter is correct
64  X=NN?
65  SF IND Y
66  X=NN?
67  SF09
68  ISG Y
69  GTO 06
70  FS? 09
71  GTO 04
72  1                   wrong guess
73  ST+10
74  6
75  RCL 10
76  X>Y?
77  GTO 08              more than 6 wrong guesses: you're dead!
78  RCL 11              make the next man character
79  FRC
80  10
81  *
82  STO 11
83  9
84  X>Y?
85  GTO 04
86  10
87  ST* 11
88  GTO 04
89 <>LBL 07              word is right! You win!
90  BEEP
91  RTN
92  GTO 01              restart game
93 <>LBL 08             all of your lives have been used up. You lose!
94  TONE 1
95  TONE 0
96  "YOU DIE  "
97  64
98  XTOA
99  2
100 XTOA
101 RTN
102 0                   set up to continue game 
103 STO 10
104 2.222222
105 STO 11
106 GTO 04
107 END
EXTRA
If you want to be able to play hangman as a one person game, do the following:
1.  Create a text file of size 22 ("CRFLAS") and enter words in it, one word per line.  I called my file "WORDS". (Perhaps it is better if you have someone else enter the words.)
2.  Add the following code after line 13 (which says ALENG).  This will get a random word from the file "WORDS" in extended memory.
3.  Run the program HANGMAN. When it says "ENTER WORD:", just press [R/S] without entering a word. The code below will then be executed.
NOTE: "RAND" is a short program that I have written to return a 4 digit random number between 0.0000 and 1.0000. Perhaps I'll upload it later.
14  X=0?                non-zero word length?
15  GTO 09              continue with game
16  XEQ "RAND"          call random number generator
17  21
18  *                   random number between 0 and 20
19  INT
20  "WORDS"             name of ASCII text file
21  SEEKPTA
22  GETREC
23  ALENG
24 <>LBL 09             continue with the game.

Flag and Register Use

Flags:
All flags are initially cleared.
00-07 used to indicated when each letter of the word has been guessed
09    used to indicated that a correct guess has been made.

Registers:
00-07 used for each letter in the word.
      Letters are stored as their decimal equivalent
08    length of word
09    loop counter
10    number of wrong guesses
11    code for displaying men
 

Go back to the HP-41 software library
Go back to the general software library
Go back to the main exhibit hall