Hangman

This file is part of Long Island Sinclair Timex (LIST) User Group Library Tape #3.5. Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 2068
Tags: Game

A hangman game that reads its word lists from tape. A companion program, HANGDATA, asks for a category name and a list of words, converts them to upper case and saves them as a string array under the category name. HANGMAN then loads a data file, picks words at random without repeats, and shows a dash for each letter. Each wrong guess adds one more piece of the gallows and figure, drawn with PLOT, DRAW and CIRCLE, and eleven misses lose the round. A short INSTRUCT program explains the order in which to use the parts.

This program is on side B of the Long Island Sinclair Timex (LIST) user group library tape #3.5 as four files: INSTRUCT, HANGDATA, HANGMAN, and a sample data file, fruit, whose words are APPLE, ORANGE, PLANTAN, POMEGRANITE and TOMATOE.

Program Analysis

Program Structure

  • HANGDATA: stores the word count in w$(1) and each word in the following rows, prefixed with a length byte (CHR$ l+t$), then does SAVE c$ DATA w$().
  • HANGMAN lines 5-60: load the data with LOAD "data" DATA w$(), choose an unused word, and print the dashes.
  • Lines 100-190: read a key, convert it to upper case, reveal matching letters, and blank them in t$ so they cannot be matched twice.
  • Lines 500-610: failure and success messages.
  • Lines 1000-2020: the drawing data, read one piece per miss; the sixth piece is a CIRCLE for the head.

Notable Techniques

  • The length byte stored at the start of each word lets the fixed-width array hold words of different lengths without trailing spaces.
  • Used words are recorded in w() so each word is played only once per session.

Potential Issues

  • HANGMAN loads a file named data, but HANGDATA saves under the category name typed in, so the file has to be named “data” for the load to find it.

Source Code

    1 PRINT "If this is your first time....  LOAD Instruct first"
    3 PRINT AT 10,0;"       PLAY HANGDATA"
    5 LOAD "data" DATA w$()
   10 BORDER 4: PAPER 4: INK 9
   15 LET n=VAL w$(1)
   20 DIM w(n): LET u=1
   25 CLS : RESTORE 
   30 IF INKEY$="p" OR INKEY$="P" THEN GO TO 30
   35 LET w=INT (RND*n)+2
   40 FOR j=1 TO u: IF w(j)=w THEN GO TO 35
   45 NEXT j: LET w(u)=w: LET u=u+1
   50 LET t$=w$(w,2 TO CODE w$(w,1)+1): LET l=LEN t$
   55 FOR j=1 TO l: PRINT AT 0,j;CHR$ 45: NEXT j: LET j=0
   60 LET r=0
  100 LET i$=INKEY$: IF i$<CHR$ 32 THEN GO TO 100
  110 IF i$>="a" AND i$<="z" THEN LET i$=CHR$ (CODE i$-32)
  120 LET x=1: FOR k=1 TO l
  130 IF t$(k)=i$ THEN PRINT AT 0,k;i$: LET x=0: LET t$(k)=CHR$ 0: LET r=r+1
  140 NEXT k
  150 IF x THEN LET j=j+1: GO SUB 2000
  160 IF j=11 THEN GO TO 500
  170 IF r=l THEN GO TO 600
  180 IF INKEY$=i $ OR INKEY$=CHR$ (CODE i$+32) THEN GO TO 180
  190 GO TO 100
  500 PRINT AT 15,15; FLASH 1; INK 2; PAPER 7;"FAILURE"
  510 FOR k=1 TO l
  520 IF t$(k)<>CHR$ 0 THEN PRINT AT 0,k; FLASH 1; INK 2; PAPER 7;t$(k)
  530 NEXT k
  540 IF u=n+1 THEN PRINT AT 21,2;"ALL WORDS HAVE BEEN USED": GO TO 9999
  550 PRINT AT 21,0;"PRESS P TO PLAY AGAIN: X TO STOP"
  560 IF INKEY$="p" OR INKEY$="P" THEN GO TO 25
  570 IF INKEY$="x" OR INKEY$="X" THEN GO TO 9999
  580 GO TO 560
  600 PRINT AT 15,15; FLASH 1; INK 2; PAPER 7;"SUCCESS"
  610 GO TO 540
 1000 DATA 16,40,48,0,40,40,0,72,40,112,24,0,64,112,0,-10,40,100,12,12
 1010 DATA 64,96,6,64,90,0,-24,64,66,-8,-12,64,66,8,-12,64,84,-12,2,64,82,12,2
 2000 READ a,b: IF j=6 THEN READ c: CIRCLE a,b,c: GO TO 2020
 2010 PLOT a,b: READ c,d: DRAW c,d
 2020 RETURN 
 9000 CLEAR : SAVE "HANGMAN" LINE 1
 9999 STOP

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.