niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » Perl » modules
Hangman
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
weberw@adelphia.net
*nix forums beginner


Joined: 09 Jul 2006
Posts: 22

PostPosted: Sun Jul 09, 2006 11:12 pm    Post subject: Hangman Reply with quote

Can someone help with my code? When the user enters "c" in the text
box it fills in c_ _, which is great. But when they enter the next
letter, like "a". It erases the c_ _ and produces _ a _. I need to
keep it to be ca_. Also how do you get the number of wrong guesses in
a string? Example, j,l,u,v etc.so the user knows the letters they have
entered?
#!C://Perl/bin/perl


use CGI ':standard';

use CGI::Carp 'fatalsToBrowser';

use constant MAX_MISSES => 8;


&display();

my $word;
$word = "cat";
my $misses_left = MAX_MISSES;
my %letters = map {$_ => 1} split //, $word;;
my %guesses = ();

if (param()) {

my $guess = param('guess');
&processguess($guess);



sub processguess{


if (exists $guesses{$guess}) {
print qq(You\'ve already guessed "$guess".\n);

}

$guesses{$guess}++;

if (exists $letters{$guess}) {
delete $letters{$guess};
keys %letters or last GUESSES;

} else {
--$misses_left;
print "another";

}
if ($misses_left > 0)
{
print "Your guess is: ", join(' ', sort keys %guesses), "\n";
print "You have $misses_left misses left.\n\n";
print join(' ', map {exists $guesses{$_} ? $_ : '_'} split //,
$word), "\n";
my $guess;

}

}
}
}
sub display {


my $the_cookie = cookie (
-name=>'gameid',
-value=>$id,
-expires=>'+1h');

print header(-cookie=>$the_cookie),
start_html(
-title=>"Hangman!",
-onLoad=>"document.forms[0].guess.select()"),

h1("Hangman!"),


"Tries Remaining: ",
"The word: ",
br,
"Letters guessed so far: ",
br,

start_form,
"Next Guess: ",
textfield (
-name=>"guess",
-size=>5,
-maxlength=>1,
-default=>''),
br,
br,


br,
submit (-name=>"submit", -label=>"Guess"),
submit (-name=>"new_game", -label=>"New Game"),

end_form,
end_html;

}
end_html;
Back to top
Jürgen Exner
*nix forums Guru


Joined: 09 Apr 2005
Posts: 514

PostPosted: Mon Jul 10, 2006 3:57 am    Post subject: Re: Hangman Reply with quote

weberw@adelphia.net wrote:
Quote:
Can someone help with my code? When the user enters "c" in the text
box it fills in c_ _, which is great.
[...]


Didn't you like the responses that you got in CLPMisc?
Anyway, as you are asking in CLPModules the answer is
http://search.cpan.org/search?query=hangman&mode=all, of course.

jue
Back to top
DJ Stunks
*nix forums Guru Wannabe


Joined: 20 Dec 2005
Posts: 192

PostPosted: Mon Jul 10, 2006 3:35 pm    Post subject: Re: Hangman Reply with quote

Jürgen Exner wrote:
Quote:
weberw@adelphia.net wrote:
Can someone help with my code? When the user enters "c" in the text
box it fills in c_ _, which is great.
[...]

Didn't you like the responses that you got in CLPMisc?

or perl.beginners... this guy was really hedging his bets...

-jp
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
The time now is Sat Nov 22, 2008 5:45 am | All times are GMT
navigation Forum index » Programming » Perl » modules
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Hangman weberw@adelphia.net Perl 4 Sun Jul 09, 2006 11:11 pm
No new posts Hangman Game tigrfire C 5 Tue Nov 22, 2005 1:25 am

Homeowner Loans | Loans | Buy Shares | Personal Injury Lawyer Los Angeles | Loans
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2110s ][ Queries: 13 (0.1272s) ][ GZIP on - Debug on ]