Well this game is fairly easy you have to chose what you think the card is going to be either higher or lower or in the middle of the two images but im having a little bit of a glitch. Here is my code and sometimes it works but when the cards are like say 5 and 6 and i chose it to be higher and the image that comes up is a 8 but it says i lose thats what im having problems with and heres the site: http://ctech.smccme.ed u/~rhodge/cw/hilow/hilow.pl
Code:
#!/usr/bin/perl use CGI ':standard'; use CGI::Carp "fatalsToBrowser"; print header; #####variables####### $card1=param('card1'); $card2=param('card2'); $card3=param('card3'); $pick=param('pick'); $wcount=param('wcount'); $lcount=param('lcount'); $results=param('param'); ######main script###### print start_html('Hi Low Game'); &hash; &cards; if($pick eq ' ' ){ &form; }else{ &results; } #####initializing a hash array w/a key value ###### sub hash{ %value=( "1",1, "2",1, "3",1, "4",1, "5",13, "6",13, "7",13, "8",13, "9",12, "10",12, "11",12, "12",12, "13",11, "14",11, "15",11, "16",11, "17",10, "18",10, "19",10, "20",10, "21",9, "22",9, "23",9, "24",9, "25",8, "26",8, "27",8, "28",8, "29",7, "30",7, "31",7, "32",7, "33",6, "34",6, "35",6, "36",6, "37",5, "38",5, "39",5, "40",5, "41",4, "42",4, "43",4, "44",4, "45",3, "46",3, "47",3, "48",3, "49",2, "50",2, "51",2, "52",2, ); } ####The for loop -- initializer; test; increment/decrement#### #for($x=1; $x<53; $x++){ # print" the Key is $x <br> # <img src=images/$x.png> <br> # the value is $value{$x} # <hr> # "; #} ####first two cards chosen#### sub cards{ $card1=int(rand(52)+1); $card2=int(rand(52)+1); while($card2 == $card1){ $card2=int(rand(52)+1);} print" <img src=images/$card1.png> <img src=images/$card2.png"; $c1v=$value{$card1}; $c2v=$value{$card2}; } #######form to choose card####### sub form{ print" <form method=post action=hilow.pl> <input type=hidden value='$c1v'> <input type=hidden value='$c2v'> <input type=radio name=pick value=Higher>Higher<br> <input type=radio name=pick value=Middle>Middle<br> <input type=radio name=pick value=Lower>Lower<br> <input type=hidden value='$wcount'> <input type=hidden value='$lcount'> <input type=submit value='Ba Bam'> </form> "; } #####win or loss computed##### sub results{ $card3=int(rand(52)+1); while($card3 == $card1 || $card3 == $card2){ $card3=int(rand(52)+1);} $c3v=$value{$card3}; if($pick eq "Higher" && $card3 > $card1 && $card3 > $card2){ $results='You Win!'; }elsif($pick eq "Middle" && $card3 > $card1 && $card3 < $card2 || $pick eq "Middle" && $card3 < $card1 && $card3 > $card2){ $results='You Win!'; }else{$results='You Lose!';} print"<img src=images/$card3.png> <br /> $results"; }
Comment