Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Okay so I am really close now, I got # of wins to go +1 now. But the only problem left is that I can only get +1 for # of wins if the random word(@words) is the same word 2 times in a row, otherwise its +1 to # of losses... I had the same problem in an earlier game I made, and I did the same thing to fix it(since the word that is printed is random, i store the random value in a new param($correctryhm)) but for some reason its not working...any advice? thanks guys for all the help, i'm kind of new to perl here's my newly edited code..

#!/usr/bin/perl use strict; use warnings; use Template; print "Content-type: text/html\n\n"; use CGI qw(:standard); my @words=("sparrow","wax","field","tear"); my $theword=$words[rand @words]; my $startwin=0; my $startlose=0; my $game=param('submit'); my $win=param('win'); my $lose=param('lose'); my $response=param('response'); my $picselect=param('picselect'); my $arrow=param('arrow'); my $axe=param('axe'); my $shield=param('shield'); my $spear=param('spear'); my $correctryhm=param('correctryhm'); #another way of setting up a hash #needs to know where the templates are my $config={ INCLUDE_PATH =>'../../projectTemplate', #or list ref INTERPOLATE => 1, #expand '$var' in plain text POST_CHOMP => 1, #cleans up whitespace EVAL_PERL =>1, #evaluate Perl code blocks }; #<body background="../../projectTemplate/indianbackground"> my $output=<<_html_; <html> <body> </body> </html> _html_ print $output; #create a template object #-> means 'send to' my $template=Template->new($config); if($game eq "Fight") { if($response eq "arrow" && $correctryhm eq "sparrow") { $correctryhm=$correctryhm; $response=param('response'); $win=param('win'); $win=$win+1; } elsif($response ne "arrow" && $correctryhm eq "sparrow") { $correctryhm=$correctryhm; $response=param('response'); $lose=param('lose'); $lose=$lose+1; } if($response eq "axe" && $correctryhm eq "wax") { $correctryhm=$correctryhm; $response=param('response'); $win=param('win'); $win=$win+1; } elsif($response ne "axe" && $correctryhm eq "wax") { $correctryhm=$correctryhm; $response=param('response'); $lose=param('lose'); $lose=$lose+1; } if($response eq "shield" && $correctryhm eq "field") { $correctryhm=$correctryhm; $response=param('response'); $win=param('win'); $win=$win+1; } elsif($response ne "shield" && $correctryhm eq "field") { $correctryhm=$correctryhm; $response=param('response'); $lose=param('lose'); $lose=$lose+1; } if($response eq "spear" && $correctryhm eq "tear") { $correctryhm=$correctryhm; $response=param('response'); $win=param('win'); $win=$win+1; } elsif($response ne "spear" && $correctryhm eq "tear") { $correctryhm=$correctryhm; $response=param('response'); $lose=param('lose'); $lose=$lose+1; } if ($win <= 9 && $lose <= 10) { print "<h3>Ryhm the words to win the battle!</h3>"; print "<form method=\"post\" action=\"ryhm2.cgi\">"; print "<input type=\"hidden\" name=\"win\" value=\"$win\">"; print "<input type=\"hidden\" name=\"lose\" value=\"$lose\">"; print "<input type=\"hidden\" name=\"arrow\" value=\"$arrow\">"; print "<input type=\"hidden\" name=\"axe\" value=\"$axe\">"; print "<input type=\"hidden\" name=\"shield\" value=\"$shield\">"; print "<input type=\"hidden\" name=\"spear\" value=\"$spear\">"; print "<input type=\"hidden\" name=\"response\" value=\"$picselect +\">"; print "<input type=\"hidden\" name=\"correctryhm\" value=\"$thewor +d\">"; print "<input name=\"submit\" type=\"submit\" value=\"Fight\" /> < +br>"; print "Wins: $win <br>"; print "Losses: $lose <br>"; #goes into var1 from projectTemplate and creates image map my $var1=<<_html_; <html> <body> <IMG src="../../projectTemplate/arrow.jpg\" align="left" /><input name +="picselect" type="radio" value="arrow" /> <input type="hidden" name="arrow" value="$arrow"> <input type="hidden" name="response" value="$picselect"> </body> </html> _html_ #goes into var2 from projectTemplate and creates image map my $var2=<<_html_; <html> <body> <IMG src="../../projectTemplate/axe.jpg\" /><input name="picselect" ty +pe="radio" value="axe" /> <input type="hidden" name="axe" value="$axe"> <input type="hidden" name="response" value="$picselect"> </body> </html> _html_ #goes into var3 and writes the random word in the box my $var3="<h3>$theword</h3>"; print "<input type=\"hidden\" name=\"correctryhm\" value=\"$theword\"> +"; #goes into var4 from projectTemplate and creates image map my $var4="<IMG src=\"../../projectTemplate/shield.jpg\" align=\"left\" +> <input name=\"picselect\" type=\"radio\" value=\"shield\" />"; #goes i +nto var5 from projectTemplate print "<input type=\"hidden\" name=\"shield\" value=\"$shield\"> <input type=\"hidden\" name=\"response\" value=\"$picselect\">"; #my $var4="<IMG src=\"../../projectTemplate/shield.jpg\">"; #$var4=<<_html_; #<html> #<body> #<IMG src="../../projectTemplate/shield.jpg\" align="left" /><input na +me="response" type="radio" value="shield" /> #<input type="hidden" name="shield" value="$shield"> #</body> #</html> #_html_ #goes into var5 from projectTemplate my $var5="<IMG src=\"../../projectTemplate/spear.jpg\"> <input name=\"picselect\" type=\"radio\" value=\"spear\" />"; print "<input type=\"hidden\" name=\"spear\" value=\"$spear\"> <input type=\"hidden\" name=\"response\" value=\"$picselect\">"; #my $var5=<<_html_; #<html> #<body> #<IMG src="../../projectTemplate/spear.jpg\" /><input name="response" +type="radio" value="spear" /> #<input type="hidden" name="spear" value="$spear"> #</body> #</html> #_html_ #set up another hash with var1, var2, var3, var4, var5 my $vars={ var1=>$var1, var2=>$var2, var3=>$var3, var4=>$var4, var5=>$var5, }; #gets from template file my $inputfile='ryhmgame.tpl'; $template->process($inputfile,$vars) || die print "not done"; print "</form>"; } if ($win == 10) { print "<h2>You won the battle!</h2>"; print "Congradualations you held off the enemy!"; } if ($lose > 10) { print "<h2>You failed to kill enough people</h2>"; print "Your family is dead <br>"; print "Game Over <br>"; $output=<<_html_; <a href="">Re +-start game</a> _html_ print $output; } } else{ print "<h1>You are about to enter a battle!</h1>"; print "<form action=\"ryhm2.cgi\" method=\"post\">"; print "<input name=\"submit\" type=\"submit\" value=\"Fight\" />"; print "<input type=\"hidden\" name=\"win\" value=\"$startwin\">"; print "<input type=\"hidden\" name=\"lose\" value=\"$startlose\">" +; print"</form>"; }

In reply to Re^4: logic problem with perl game by mynameisG
in thread logic problem with perl game by mynameisG

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (9)
    As of 2018-03-17 17:31 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (225 votes). Check out past polls.