in reply to Re^3: hangman question
in thread hangman question
#!/usr/bin/perl -w @words = qw( hi no ); @guesses=(); $wrong=0; $choice=$words[rand @words]; $hangman="0-|--<"; @letters=split(//, $choice); print "\@letters is @letters\n"; @hangman=split(//, $hangman); @blankword=(0) x scalar(@letters); print "\@blankword is @blankword\n"; OUTER: while ($wrong<@hangman) { print "whielloop\n"; foreach $i (0..$#letters) { if ($blankword[$i]) { print $blankword[$i]; } else { print "-"; } } print "\n"; if ($wrong) { print @hangman[0..$wrong-1] } print "\n\n\n\n Your Guess: "; $guess=<STDIN>; chomp $guess; # foreach(@guesses) { # print "foreach loop\n"; # print "\$guess is $guess\n"; # print "\$\_ is $_\n"; # next OUTER if ($_ eq $guess); # } # print "\@guesses is @guesses\n"; # $guess_scalar = "@guesses"; # print "\$guess_scalar is $guess_scalar\n"; #$guesses[@guesses]=$guess; # push @guesses, $guess; $right=0; for ($i=0; $i<@letters; $i++) { print "\$i is $i\n"; print "in the forloop\n"; if ($letters[$i] eq $guess) { $blankword[$i]=$guess; print "\$blankword\[\$i\] is $blankword[$i] +\n"; $right=1; } } $wrong++ if (not $right); print "\$wrong is $wrong\n"; if (join('', @blankword) eq $choice) { print "IF loop\n"; print "You got it right!\n"; exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: hangman question
by ysth (Canon) on Jul 16, 2007 at 02:46 UTC | |
by convenientstore (Pilgrim) on Jul 16, 2007 at 03:48 UTC |