remake of 80’s computer toy word game

80's computer word game
80’s computer word game

Way back on Christmas of ’87, my sister got a computer toy similar to this one.  I couldn’t put it down.  It had a word game with 8, 14-segment LEDs where you had to enter letters one at a time and guess the word before your tries ran out, sort of like wheel of fortune.  I got bored on Sunday night, and wrote a command line version.

perl command line word game
perl command line word game

It requires an external file, words.txt, from which it randomly chooses a word for each round.  Above is the game play.

Here is the source:

#!/usr/bin/perl -w
use Tie::File;
use strict;

#array of all letters
my @letters = 'a' .. 'z';
my $szletters = @letters;
my @used_letters;
my $n_tries = 0;
my $wf = 0;
my $iword = '';
my $letter = '';
my @wrd;

my @words;
tie @words, 'Tie::File', "words.txt" or die $!;

my $nw = @words;
#print "nwords: $nw \n";
my $num = int(rand($nw));

my $word = $words[$num];

#print "word: $word\n";

my $lngth = length($word);

for(my $l=0; $l < $lngth; $l++){
#print '-';
$iword = $iword."-";
}#end for
print "\n";

@wrd = split //, $word;
my $lef = 0;
do {
print $iword."\n";
print "enter a letter: ";
chomp($letter = );
#print "letter: $letter\n";

#clear out iword
$iword = '';

push @used_letters, $letter;
for(my $l=0;$l<$lngth;$l++){
foreach my $v (@used_letters){
if($wrd[$l] eq $v){
$iword = $iword.$v;
$lef = 1;#set flag true
}#end if
}#end foreach

unless($lef == 1){
$iword = $iword.'-';
}#end unless
$lef = 0;
}#end for

print "used letters: @used_letters \n";

if($iword eq $word){
print "$word\n";
print "YOU WIN!!!\n";
$wf = 1;
}#end if

} while($wf ==0);

Leave a Reply

Your email address will not be published. Required fields are marked *