Hangman
 

program hangfile(input, output);

{This program is like hangman, but uses a file of words to retrieve }
{if only one person is playing. }

const
blank = ' ';
spot = #254;
blankline =
' ';
numwords = 432; {NOTE: Update to match number of words }
{ in HANGWDS.TXT file }

type
guess = array[1..80] of char;
bodyparts = array[1..6] of string[4];
matrix = array[0..9, 1..15] of char;
guess_char = array[1..27] of char;
bodyfig = array[1..6] of string[4];

var
word, wdisp,
wordguess : guess;
ch_guess : guess_char;

ch, response : char;

i, k, n, p,
selection,
numberplayers : integer;

gameover,
done,
finished,
wordmatch,
foundone : boolean;
ch_used : boolean;

piece : bodyparts;
getit : matrix;
stickpiece : bodyfig;
dummy : string[80];
infile : text;

{ EOLN is used, and is a built-in boolean variable }

procedure clrarrays;
begin
for i := 1 to 80 do
begin
word[i] := blank;
wdisp[i] := spot;
end;
for i := 1 to 27 do ch_guess[i] := blank;
end;

procedure initbodyparts;
begin
piece[1] := 'Head';
piece[2] := 'Body';
piece[3] := 'Arm1';
piece[4] := 'Arm2';
piece[5] := 'Leg1';
piece[6] := 'Leg2';
stickpiece[1] := '( )';
stickpiece[2] := ' |';
stickpiece[3] := '-- ';
stickpiece[4] := '--';
stickpiece[5] := '/';
stickpiece[6] := '\';
end;

procedure showparts(var parts : integer);
begin
parts := parts + 1;
if parts > 5 then
begin
GotoXY(52,13);
Write(stickpiece[6]);
GotoXY(1, 19);
write(blankline);
GotoXY(1,19);
write('You Lost; you are a hung hombre!!');
gameover := true;
end
else
begin
GotoXY(10, 21);
write('You now have a ');
for i := 1 to parts do
write(piece[i],', ');
for i := 1 to parts do
case i of
1 : begin GotoXY(50,10); write(stickpiece[i]); end;
2 : begin GotoXY(50,11); write(stickpiece[i]); end;
3 : begin GotoXY(49,12); write(stickpiece[i]); end;
4 : begin GotoXY(52,12); write(stickpiece[i]); end;
5 : begin GotoXY(50,13); write(stickpiece[i]); end;
end; { of case }
end;
end;

procedure enterword;
begin
i := 0; { must start at 0 to "throw away" hanging ENTER char }
GotoXY(1, 23);
WRITE(blankline);
GotoXY(1, 22);
write('Enter word or phrase to guess: ');
GotoXY(1, 23);
read(input, ch);
while not EOLN do
begin
word[i] := UPCASE(ch);
i := i + 1;
read(input, ch);
end;
word[i] := UPCASE(ch);
word[i+1] := '.';
GotoXY(1, 22);
WRITE(blankline);
GotoXY(1,23);
WRITE(blankline);
end;

procedure displayword;
begin
i := 1;
ch := word[i];
GotoXY(2, 18);
while ch <> '.' do
begin
if ch <> ' ' then
write(output, wdisp[i])
else
begin
wdisp[i] := ' ';
write(' ');
end;
i := i + 1;
ch := word[i];
end;
end;

procedure makeguess;
begin
i := 1;
foundone := false;
ch_used := false;
GotoXY(10,23);
write('Enter a character: ');
GotoXY(32, 23);
readln(ch);
GotoXY(1, 22);
WRITE(blankline);
WHILE ch_guess[i] <> blank DO
BEGIN
IF ch = ch_guess[i] THEN
BEGIN
ch_used := TRUE;
GotoXY(10,22);
WRITE('You''ve already tried ', ch, '. Try again!');
GotoXY(32, 23);
READLN(ch);
GotoXY(10,22);
Write(blankline);
i := 1;
END
ELSE
BEGIN
i := i + 1;
IF ch_guess[i] = blank THEN ch_used := false;
END;
END;
IF ((ch <> '#') AND (NOT ch_used)) THEN ch_guess[i] := ch;
i := 1;
repeat
if UPCASE(ch) = word[i] then
begin
wdisp[i] := word[i];
i := i + 1;
foundone := true;
end
else
i := i + 1;
until word[i] = '.';
if not (foundone) and (ch <> '#') then
showparts(n);
end;

procedure wordtest;
begin
wordmatch := true;
i := 1;
repeat
if word[i] = wdisp[i] then
i := i + 1
else
wordmatch := false;
until (word[i] = '.') or (not wordmatch);
if wordmatch then
begin
GotoXY(1,22);
WRITE(blankline);
GotoXY(10, 22);
write('.....Congratulations; You win!! ');
end;
end;

procedure enterguess;
begin
i := 1;
GotoXY(1,22);
WRITE(blankline);
GotoXY(1, 23);
WRITE(blankline);
GotoXY(1, 22);
write('Enter your guess: ');
GotoXY(1, 23);
read(ch);
while not EOLN do
begin
wordguess[i] := UPCASE(ch);
i := i + 1;
read(input, ch);
end;
wordguess[i] := UPCASE(ch);
wordguess[i+1] := '.';
end;

procedure guesswordtest;
begin
wordmatch := true;
i := 1;
repeat
if wordguess[i] = word[i] then
i := i + 1
else
wordmatch := false;
until (word[i] = '.') or (not wordmatch);
if wordmatch then
begin
GotoXY(1,22);
WRITE(blankline);
GotoXY(10, 22);
write('.....Congratulations; You win!! ');
end
else
begin
GotoXY(1,22);
WRITE(blankline);
GotoXY(1,23);
WRITE(blankline);
GotoXY(10, 22);
write('Nope..that is not it. ');
showparts(n);
end;
end;

procedure showanswer;
begin
i := 1;
GotoXY(10, 21);
write('The correct answer was: ');
GotoXY(10, 22);
while word[i] <> '.' do
begin
write(word[i]);
i := i + 1;
end;
end;

procedure selectphrase;
var
select, count, i : integer;
begin
for i := 1 to 80 do
word[i] := ' ';
assign(infile, 'hangwds.txt');
reset(infile);
i := 2;
randomize;
select := random(numwords);

WRITE(SELECT);

for count := 1 to select do
readln(infile, dummy);
read(infile, ch);
word[1] := ch;
while ch <> '.' do
begin
read(infile, ch);
word[i] := ch;
i := i + 1;
end;
close(infile);
end;

BEGIN { main program }
REPEAT
finished := false;
clrarrays;
initbodyparts;
gameover := false;
n := 0;
ch := 's';
clrscr;
GotoXY(10, 23);
write('How many players? ');
readln(numberplayers);
GotoXY(10, 23);
write(' ');
GotoXY(22,3);
write('To guess the whole word, enter a "#".');
{PUT THE DISPLAY ON THE SCREEN FOR THE GAME TO BEGIN}
if numberplayers = 1 then
selectphrase
else
enterword;
displayword;
repeat
makeguess;
if (ch <> '#') and (n <= 5) then
begin
displayword;
wordtest;
end
else if ch = '#' then
begin
enterguess;
guesswordtest;
end;
until (wordmatch) or (gameover);
if n > 5 then
showanswer;
GotoXY(1, 23);
WRITE(blankline);
GotoXY(10, 23);
write(' Another game (Y/N)? ');
readln(response);
GotoXY(10, 23);
write(' ');
if UPCASE(response) = 'N' then
finished := true;
UNTIL finished;
GotoXY(10, 23);
write('**** Game Over ****');
END.

========================================================================
Here is a sample HANGWDS.TXT file to use with the program:

ANTIQUE.
APPEALING.
ARMOIRES.
ARTISTS.
ATTRACTIVE.
BASE.
BUDS.
CABINETS.
CABINETMAKERS.
CARE.
CHAIRS.
CHARMING.
CHEST.
COLORS.
CRAFTS.
CUPBOARDS.
DESIGN.
FLORAL.
FLOWERS.
FOLKART.
GLAZE.
HEADBOARDS.
HUTCHES.
KNOWLTON.
PAINT.
PAST.
PERIOD.
RANK.
SALE.
SCENES.
SIDEBOARD.
SIGNS.
STAINING.
STYLE.
TINT.
TONES.
TRIM.
WARM.
ARCH.
BAND.
BORDER.
BUSES.
CABLE.
CAFE.
CENTRAL.
CHAIN.
COAST.
CODE.
COFFEE.
COMEON.
CREDIT.
DANCE.
DIVIDE.
DOUBLE.
DRAW.
ENTER.
FERRY.
FREE.
FUEL.
GAPS.
HIRE.
HURRY.
LANE.
LEAD.
MAIL.
PARADE.
PARK.
PATIENCE.
PENCIL.
PEOPLE.
PERPENDICULAR.
PIER.
POETIC.
PRIVATE.
RESTAURANT.
ROUTE.
SHOW.
SIDE.
SILO.
SINGLE.
SPACE.
SPEED.
SPIRAL.
STRAIGHT.
START.
STRANDS.
STRING.
TAIL.
THIN.
TRAIN.
TURNS.
VALUE.
WIRE.
WORD.
HUMIDITY.
FILAMENTS.
ASTHMA.
BEDS.
BITE.
BLAH.
BLOW.
BOUT.
BREAK.
BURN.
CAST.
DOSE.
EYES.
FEARS.
GUMS.
HEAL.
HEART.
HELP.
HIVES.
HUMOR.
HURT.
HYPOTHERMIA.
IDLE.
INDIGESTION.
LATE.
LIMBS.
LUNGS.
MEDICINE.
MISS.
MOUTH.
NAUSEA.
NECK.
NOSE.
NUMB.
NURSE.
OTITIS.
PAIN.
PETTY.
RANT.
REMEDY.
RESTING.
RUNNY.
SINUS.
SLACK.
SLEEP.
SNEEZE.
SNIFF.
STAID.
STEAM.
STREP.
SWELL.
THERMOMETER.
THROAT.
TIRE.
TURBULENT.
VILE.
VIRUS.
WEAK.
WIND.
WORRY.
AIMS.
BILL.
BONUS.
BORED.
BOSS.
CALLS.
CASH.
CELEBRATE.
CHAMPAGNE.
CHEF.
CLOSED.
COST.
DINE.
DINNER.
EFFORT.
EMPLOYEES.
FEAST.
FEED.
FEST.
FUSS.
GAMES.
GOING.
GREET.
HALL.
HOST.
HOTEL.
HUGS.
IDEAS.
INVITE.
LIBATION.
MEAL.
MEETING.
MENUS.
MUSIC.
NOISE.
OBLIGATION.
OFFICE.
ORCHESTRA.
PLATTER.
PLAY.
POTABLES.
PUBLIC.
PUBS.
RESTAURANT.
ROOM.
SEAT.
SETS.
SING.
TALL.
TEAM.
TIDINGS.
TIMED.
TRAVEL.
TRAYS.
TREE.
ADDITIVE.
ANGLE.
AROMA.
BEAT.
BRAN.
BREAD.
BUNS.
CAKE.
CARAMEL.
CHEMICAL.
COATS.
CREAM.
CRUMPET.
DOUGH.
ECLAIR.
EGGS.
FADS.
FOLD.
FOOD.
FROSTING.
GRAIN.
GRATE.
GREASE.
GUMS.
HEAP.
HERB.
ICING.
JAM.
JELLY.
LARD.
LAYER.
LEAVEN.
NAPOLEON.
OATS.
OVEN.
PANS.
PITA.
PRESERVATIVES.
PUFF.
RACK.
RISE.
ROAST.
ROLL.
SALT.
SAVE.
SEEDS.
SESAME.
SIFT.
SLICE.
SOUFFLE.
SPICE.
STRUDEL.
SUGAR.
TART.
TWIST.
WHEAT.
WRAP.
YEAST.
ANGEL.
ASSIST.
BIRTH.
BORN.
BOWS.
BOXES.
BUSY.
CANDLE.
CARD.
CASH.
CELEBRATE.
CHEER.
CHIMNEY.
CHURCH.
CRANBERRIES.
DATE.
DEAR.
DECEMBER.
DECORATION.
EMBRACE.
ESSENCE.
GAME.
GANG.
GIFTS.
GOODIES.
GOODWILL.
GUEST.
HEAP.
HOPE.
JESUS.
MEAL.
MUGS.
OPEN.
PEACE.
PHONE.
PRAISE.
PRAY.
PRESENT.
RIBBON.
SALE.
SANTA.
SEASON.
SHARE.
SLEIGH.
SNOW.
SURPRISE.
TABLE.
TINSEL.
TOYS.
TREE.
TURKEY.
YEAR.
ACCEPT.
APPOINTED.
CARE.
CHARITY.
CRUSADE.
CUES.
DEVOTED.
EAST.
ENVOY.
FAITH.
FOREIGN.
FRIEND.
GUEST.
HEAL.
HOLY.
HOPE.
HOSPITAL.
HOST.
HURT.
INFORMED.
JOIN.
JOYS.
LIFT.
MEDICAL.
MIDDLE.
MISSION.
MONK.
OVERSEAS.
PAID.
PIONEER.
POOR.
PRIEST.
PROMOTE.
RELIGION.
RIGHTS.
ROLES.
SENT.
SERVE.
SICK.
SISTER.
SPARE.
SPONSOR.
STAGE.
STAKE.
STAY.
TEAMS.
TERM.
THANKS.
TIPS.
TRIP.
USEFUL.
VALUE.
VISION.
YEAR.
ASHTRAY.
BARS.
BOAST.
BODY.
CABLE.
CAPS.
CHIP.
CHROME.
CONSOLE.
CRASH.
DASH.
DEAL.
DOOR.
DRIVE.
ENGINE.
FILTER.
FLAT.
FORM.
GAUGE.
GUARANTEE.
INSPECT.
LAMP.
LEAK.
LIGHT.
MILEAGE.
MINT.
MIRROR.
MODEL.
MOLD.
MUFFLER.
NAME.
OWNER.
PAINT.
PANEL.
PEEL.
PERMIT.
PLUG.
RADIATOR.
RATING.
REPAIR.
RETAIL.
RISK.
RUST.
SCRATCH.
SEATS.
SHOCK.
SPARK.
STARTER.
STEER.
TAILPIPE.
TANK.
TIRE.
TITLE.
TRIM.
TRIAL.
TRUNK.
VISIBLE.
WASH.
WELD.
WOOD.

(c) Shilpa Sayura Foundation 2006-2017