commit d27d348449c96e4d2c426b0f82f77aa9dc5a25ba
parent 0f160c8cf1a217710d024f54d7a39cb73f871ac7
Author: Samir Parikh <noreply@samirparikh.com>
Date: Thu, 17 Feb 2022 20:09:00 +0000
add generate_html subroutine
Diffstat:
1 file changed, 28 insertions(+), 0 deletions(-)
diff --git a/guess_number.cgi b/guess_number.cgi
@@ -69,6 +69,25 @@ sub process_guess {
}
+sub print_status {
+ my ( $message, $state ) = @_;
+
+ # draw table
+ print
+ $game->table( { -border=>"1", -width=>"100%" },
+ $game->tr(
+ $game->td( "Game #: ", $state->{GAMENO} ),
+ $game->td( "Wins: ", $state->{WON} )
+ ),
+ $game->tr(
+ $game->td( "Guesses Left: ", $state->{GUESSES_LEFT} ),
+ $game->td( "Numbers Guessed: ", $state->{GUESSED} )
+ )
+ );
+ print $game->h2( font( {-color => 'red'}, $message )) if $message;
+}
+
+# begin main program
# retrieve current state
my $state = get_state();
@@ -84,3 +103,12 @@ my ( $message, $status ) =
process_guess( $game->param( 'guess' ) || '', $state );
# generate the HTML page
+print $game->header(
+ -type => "text/html",
+ -charset => 'utf-8',
+);
+print $game->start_html(
+ -title => "Guess a Secret Number!",
+ -onLoad => 'if (document.gf) document.gf.guess.focus()',
+);
+print $game->h1( 'Guess a Secret Number Interactive Game' );