friar tux has asked for the wisdom of the Perl Monks concerning the following question:

hi, I am trying to make a simple craps game. and would appreciate some help

#index.html#
<html> <center> <img src=./pix/submit.jpg> <hr> <form action=/cgi-bin/dice.cgi method=post> <input type=submit value ="roll the dice" > <a href= cgi-bin/dice.cgi> </center> </html>

this next piece I would like to add an animated .gif that simulates the dice rolling then show the numbers if you would like to see them the url is http://s1215.photobucket.com/albums/cc505/troylolson/ all the .gif's are renamed correctly for this script

dice.cgi

#! /usr/bin/perl use CGI ':standard'; print "Content-type:html\n\n"; $dice1= int (rand(6)+1); $dice2= int (rand(6)+1); $rolla = param('rolla'); $rollb = param('rollb'); print "<img src=http://localhost/pix/dice$dice1.gif>"; print "<img src=http://localhost/pix/dice$dice2.gif>"; $total= $dice1+$dice2; print "your first roll was" ; print "<img src=http://localhost/pix/dice$rolla.gif>"; #rollb won't show up# print "<img src=http://localhost/pix/dice$rollb.gif>"; if (($total ==7)or($total ==11)){ print "you win!!!"; exit() } elsif (($total ==2) or ($total ==12)){ print "loser"; exit() } #I believe the problem with rollb is on this line# print "<a href= dice.cgi?rolla=$dice1 & rollb=$dice2>roll again</a>"

I also need to add some kind of counter so it remembers the first roll only. the counter and a few tweaks for the rules I am not worried about as much as a way to swap the animated .gif with the correct die face after the .gif has played through. thank you for your time

Replies are listed 'Best First'.
Re: dice game
by ikegami (Patriarch) on Mar 15, 2011 at 21:01 UTC
    <a href= dice.cgi?rolla=$dice1 & rollb=$dice2>roll again</a> ^ ^ ^

    Not to mention the whole url should be in quotes (single and double are both allowed).

Re: dice game
by SuicideJunkie (Vicar) on Mar 15, 2011 at 21:04 UTC

    Why not simply have six different animations, each of which end up on a different face? Make them without looping so that they stop once done playing through.

    Decide what it will be up front and then show, for example the die5.gif which bounces along, spins on a corner and then settles on 5. (die4.gif would naturally land on 4, and so on)