Hangman (New Owners Column)

Type
Game
Category
Word game / beginner's tutorial
Author
David Plotkin
Published in
Antic, May 1986 (Vol. 5, No. 1), New Owners Column, Lesson 3
Year
1986
Language
Atari BASIC
Requirements
Any Atari 8-bit computer, Atari BASIC
Hangman in GRAPHICS 7: a brown gallows on a green base with the victim's head drawn, the word shown as _ T _ R _ in the text window, the prompt WHAT LETTER DO YOU GUESS? and the guesses TQR

About the program

In 1986 Antic began a "New Owners Column" for people who had just bought an Atari. Lesson 3, in the May issue, covered variables, IF/THEN decisions and FOR/NEXT/STEP loops, and ended with a complete program that used them all: the pencil-and-paper game Hangman. The author, David Plotkin, was a regular Antic contributor in both BASIC and ACTION!, and he kept the column going for many issues.

The computer picks a word and shows a blank for each letter. Guess a letter, and if it's in the word it appears in every place it belongs. If it isn't, another piece of the poor fellow is drawn on the gallows. The words are all Atari terms (ATARI, ANTIC, CARTRIDGE, JOYSTICK, MODEM and so on), so it's a vocabulary test too.

Typing it in

The lesson was meant for beginners, so the program is plain and full of explanatory REMs. The only special characters are the inverse words in lines 120, 420 and 430: {inv} … {/inv} means press the Atari (inverse) key before and after. Line 119 is just a REM. The prompt in line 430 really does say "CONINUE", a typo in the original. Antic printed TYPO II checksums beside each line of the magazine listing. They are not part of the program.

How to play

RUN it and type a letter (capitals), then RETURN, at the WHAT LETTER DO YOU GUESS prompt. Your guesses are listed along the bottom. Eight wrong guesses and you're HUNG. When every word has been used, the program shows your percentage of words solved and offers another round.

To add words, put new DATA lines before the final DATA END. The word END must always come last, because that's how the program knows it has run out.

How it works

This is a good listing to read alongside the lesson:

  • FOR/NEXT draws the row of blanks (lines 90–110) and checks every letter of the word against your guess (lines 170–200).
  • IF/THEN decides what each guess means. The array HOLD() remembers which positions are already found, so guessing the same correct letter twice doesn't count double (line 175).
  • ON … GOSUB (line 230) picks which body part to draw from the number of wrong guesses, and each part is a short subroutine of PLOT/DRAWTO loops (lines 700–990).
  • Text in a graphics screen. POKEing 656 (row) and 657 (column) places the cursor in the GRAPHICS 7 text window before each PRINT.

Listing

10 REM THE NEW OWNERS COLUMN
20 REM THE HANGMAN GAME
30 REM BY DAVID PLOTKIN
40 REM (c) 1985, ANTIC PUBLISHING
50 DIM ANSWER$(40),LTR$(1),HOLD(40)
55 NUMCORRECT=0:TOTAL=0
60 GRAPHICS 7:CTR=0:YES=0:CORRECT=0:INCORRECT=0:SETCOLOR 0,2,4:SETCOLOR 1,12,10:GOSUB 610:REM DRAW GALLOWS
65 FOR LP=1 TO 40:HOLD(LP)=0:NEXT LP
70 READ ANSWER$:REM GET THE WORD TO PLAY WITH FROM THE DATA STATEMENTS
80 IF ANSWER$="END" THEN GOTO 660:REM TEST FOR ALL DATA USED...GO TO END OF THE GAME IF IT IS.
85 TOTAL=TOTAL+1
90 FOR LP=1 TO LEN(ANSWER$):REM LOOP TO THE LENGTH OF THE WORD
100 POKE 656,0:POKE 657,LP*2:PRINT "_";:REM PRINT THE UNDERLINE BLANKS FOR THE WORD
110 NEXT LP:POKE 656,2:POKE 657,24:PRINT " ";
115 POKE 656,2:POKE 657,25:PRINT " ";
119 REM {ESC}=
120 LTR$="":POKE 656,2:POKE 657,0:PRINT "{inv}WHAT LETTER DO YOU GUESS{/inv}";:INPUT LTR$
130 IF LTR$="" THEN GOTO 115
140 CTR=CTR+1:REM UPDATE THE COUNTER  FOR A SUCCESSFUL LETTER CHOICE.
150 POKE 656,3:POKE 657,CTR:PRINT LTR$;
160 FOR ZIP=200 TO 100 STEP -10:SOUND 0,ZIP,10,4:NEXT ZIP:SOUND 0,0,0,0:REM SOME SOUND
170 FOR LP=1 TO LEN(ANSWER$):REM LOOP...
175 IF ANSWER$(LP,LP)=LTR$ AND HOLD(LP)=0 THEN HOLD(LP)=1:YES=1:CORRECT=CORRECT+1
180 IF ANSWER$(LP,LP)=LTR$ THEN POKE 656,0:POKE 657,LP*2:PRINT LTR$
190 IF ANSWER$(LP,LP)=LTR$ THEN FOR ZIP=50 TO 150 STEP 10:SOUND 0,ZIP,12,4:NEXT ZIP:SOUND 0,0,0,0
200 NEXT LP:IF YES=1 THEN YES=0:GOTO 250
210 INCORRECT=INCORRECT+1
220 FOR ZIP=10 TO 50:SOUND 0,ZIP,8,4:NEXT ZIP:SOUND 0,0,0,0
230 ON INCORRECT GOSUB 710,750,790,830,870,910,950,990
240 IF INCORRECT=8 THEN GOTO 410
250 IF CORRECT=LEN(ANSWER$) THEN GOTO 510
260 GOTO 115
400 REM OH,OH...YOU ARE HUNG!
410 COLOR 3:PLOT 123,13:DRAWTO 123,19:PLOT 120,30:DRAWTO 126,30:PRINT CHR$(125):POKE 656,1:POKE 657,16
420 PRINT "***{inv}HUNG{/inv}***":FOR PP=100 TO 200 STEP 2:SOUND 0,PP,10,4:SOUND 1,250-PP,10,4:NEXT PP
430 SOUND 0,0,0,0:SOUND 1,0,0,0:POKE 656,3:POKE 657,3:PRINT "PRESS {inv}RETURN{/inv} TO CONINUE...";:INPUT LTR$
440 GOTO 60
500 REM GOT THE CORRECT ANSWER
510 FOR PP=50 TO 150:SOUND 0,PP,10,4:SOUND 1,PP+10,10,4:POKE 712,PP:NEXT PP:SOUND 0,0,0,0:SOUND 1,0,0,0
520 POKE 712,0:NUMCORRECT=NUMCORRECT+1
530 GOTO 60
600 REM DRAW THE GALLOWS
610 COLOR 2:FOR PP=70 TO 78:PLOT 100,PP:DRAWTO 140,PP:NEXT PP
620 COLOR 1:FOR PP=10 TO 69:PLOT 102,PP:DRAWTO 106,PP:NEXT PP
630 FOR PP=6 TO 9:PLOT 102,PP:DRAWTO 125,PP:NEXT PP:FOR PP=10 TO 12:PLOT 121,PP:DRAWTO 125,PP:NEXT PP
640 RETURN
650 REM ALL DATA USED...
660 PRINT CHR$(125):POKE 656,1:POKE 657,3:PRINT "ALL THE DATA USED":POKE 656,2:POKE 657,3
670 PRINT "PERCENT CORRECT:";NUMCORRECT/TOTAL*100;"%";:POKE 656,3:POKE 657,3:LTR$=""
680 PRINT "PLAY AGAIN (Y/N)";:INPUT LTR$:IF LTR$="Y" THEN RESTORE :GOTO 55
690 GRAPHICS 0:PRINT "GOOD BYE TILL NEXT TIME":END
700 REM DRAW THE HEAD
710 COLOR 1:FOR PP=20 TO 28:PLOT 120,PP:DRAWTO 128,PP:NEXT PP:COLOR 2:PLOT 122,23:PLOT 126,23:PLOT 124,25
720 PLOT 123,27:DRAWTO 125,27:COLOR 0:PLOT 120,20:PLOT 128,20:PLOT 120,28:PLOT 128,28
730 RETURN
740 REM DRAW THE NECK
750 COLOR 1:FOR PP=29 TO 31:PLOT 123,PP:DRAWTO 125,PP:NEXT PP
770 RETURN
780 REM DRAW THE BODY
790 FOR PP=32 TO 50 STEP 2:COLOR 2:PLOT 118,PP:DRAWTO 130,PP:COLOR 3:PLOT 118,PP+1:DRAWTO 130,PP+1:NEXT PP
810 RETURN
820 REM DRAW THE LEFT ARM
830 FOR PP=32 TO 36 STEP 2:COLOR 2:PLOT 115,PP:DRAWTO 117,PP:COLOR 3:PLOT 115,PP+1:DRAWTO 117,PP+1:NEXT PP
840 FOR PP=32 TO 42 STEP 2:COLOR 2:PLOT 110,PP:DRAWTO 114,PP:COLOR 3:PLOT 110,PP+1:DRAWTO 114,PP+1:NEXT PP
850 RETURN
860 REM DRAW THE RIGHT ARM
870 FOR PP=32 TO 36 STEP 2:COLOR 2:PLOT 131,PP:DRAWTO 133,PP:COLOR 3:PLOT 131,PP+1:DRAWTO 133,PP+1:NEXT PP
880 FOR PP=32 TO 42 STEP 2:COLOR 2:PLOT 134,PP:DRAWTO 138,PP:COLOR 3:PLOT 134,PP+1:DRAWTO 138,PP+1:NEXT PP
890 RETURN
900 REM DRAW LEFT LEG
910 FOR PP=52 TO 60 STEP 2:COLOR 2:PLOT 118,PP:DRAWTO 122,PP:COLOR 3:PLOT 118,PP+1:DRAWTO 122,PP+1:NEXT PP
920 COLOR 1:FOR PP=61 TO 64:PLOT 116,PP:DRAWTO 122,PP:NEXT PP
930 RETURN
940 REM DRAW THE RIGHT LEG
950 FOR PP=52 TO 60 STEP 2:COLOR 2:PLOT 126,PP:DRAWTO 130,PP:COLOR 3:PLOT 126,PP+1:DRAWTO 130,PP+1:NEXT PP
960 COLOR 1:FOR PP=61 TO 64:PLOT 126,PP:DRAWTO 132,PP:NEXT PP
970 RETURN
980 REM HUNG!
990 RETURN
1000 REM DATA FOR THE GAME
1010 DATA ATARI,COMPUTER,DISK
1020 DATA ANTIC,PROGRAM,CARTRIDGE
1030 DATA SCREEN,MEMORY,COUNTER
1040 DATA MODEM,BASIC,PRINTER
1050 DATA DEBUG,KEYBOARD,MANUAL
1060 DATA JOYSTICK,PADDLE,GRAPHICS
1070 DATA SOUND,COLOR
1080 DATA END

Download

The original program from the Antic disk, to LOAD or ENTER instead of typing it: NEWOWN3.BAS.

Credits