#!/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 }; # my $output=<<_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 "

Ryhm the words to win the battle!

"; print "
"; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print "
"; print "Wins: $win
"; print "Losses: $lose
"; #goes into var1 from projectTemplate and creates image map my $var1=<<_html_; _html_ #goes into var2 from projectTemplate and creates image map my $var2=<<_html_; _html_ #goes into var3 and writes the random word in the box my $var3="

$theword

"; print ""; #goes into var4 from projectTemplate and creates image map my $var4=" "; #goes into var5 from projectTemplate print " "; #my $var4=""; #$var4=<<_html_; # # # # # # #_html_ #goes into var5 from projectTemplate my $var5=" "; print " "; #my $var5=<<_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 "
"; } if ($win == 10) { print "

You won the battle!

"; print "Congradualations you held off the enemy!"; } if ($lose > 10) { print "

You failed to kill enough people

"; print "Your family is dead
"; print "Game Over
"; $output=<<_html_; Re-start game _html_ print $output; } } else{ print "

You are about to enter a battle!

"; print "
"; print ""; print ""; print ""; print"
"; }