Thread: Need help with script
Results 1 to 1 of 1
Related
-
is there a difference between <script language="javascript> and <script type="text/javascript"> Forum: Javascript Forum
Replies: 8 -
Help with Random Content script (need hotlink in script) Forum: Javascript Forum
Replies: 0
-
03-08-2006, 12:41 AM #1
Need help with script
I'd like to change the following script so that I can install the script in my cgi-bin directory and install images associated with the script in a different directory (outside the cgi-bin directory). Can anyone help me modify this script to do this?
Code:#!/usr/local/bin/perl # # Name: WebConcentration # Author: James Dean Palmer # License: GPL v2 (See http://www.fsf.org/) # Release: 0.2 (7-21-98) # # This is a *VERY* simple concentration game written in perl. # Just modify these first few variables for your system: # The skin file changes what the html part of the game looks like $skin = "/home/james/public_html/concentration/skin.html"; # This file must be writeable by the user your web server runs under. $scorefile = "/home/james/public_html/concentration/.scores"; # The images that the player will have to remember: @imagelist = ("a.jpg", "b.jpg", "c.jpg", "d.jpg", "e.jpg", "f.jpg", "g.jpg", "h.jpg" ); # The prize picture revealed at the end of a game. @picturelist = ("ga.jpg", "gb.jpg", "gc.jpg", "gd.jpg", "ge.jpg", "gf.jpg", "gg.jpg", "gh.jpg", "gi.jpg", "gj.jpg", "gk.jpg", "gl.jpg", "gm.jpg", "gn.jpg", "go.jpg", "gp.jpg"); # The number of columns for the image board. $columns = 4; $facecard = "card.jpg"; # Okay, you probably don't need to modify anything beyond # this point. open (INFILE, "< $skin"); while (<INFILE>) { $skinoutput = $skinoutput . $_; } close(INFILE); use CGI qw(:standard); print header; $puzzleoutput .= start_form; $puzzleoutput .= "<center>"; # Create a puzzle if one doesn't exist.. if (!param("sq")) { @imagelist = (@imagelist, @imagelist); srand(time ^ $$); foreach $x (@imagelist) { $p = rand; $p = int($p*100000); push @numberlist, "$p\:$x"; } @numberlist = sort @numberlist; foreach $x (@numberlist) { ($a, $b) = split(/\:/, $x); push @randomlist, $a; push @randomlist, $b; } } else { @randomlist = param("sq"); } # print the cards according to their state: # 0 >= facedown # -1 == faceup # -2 == solved if (param("pick")) { $pick = param("pick") - 10; } else { $pick = -1; } if (param("selection")) { $selection = param("selection"); } else { $selection = 0; } $i=0; $scount=0; $a=-1; $b=-1; while ($i<@randomlist) { if ($i==$pick) { $randomlist[$i] = -1; } if (($randomlist[$i] == -1) && ($a>-1)) { $b = $i; } if (($randomlist[$i] == -1) && ($a==-1)) { $a = $i; } if ($randomlist[$i] == -2) { $scount = $scount + 2; } if (param("win")) { $randomlist[$i] = -2; } $i = $i + 2; } @nextrandomlist = @randomlist; if (( (!param("win")) && ($a > -1) && ($b > -1) )) { if (@randomlist[$a+1] eq @randomlist[$b+1]) { @nextrandomlist[$a]=-2; @nextrandomlist[$b]=-2; $scount = $scount + 4; if ($scount == @randomlist) { $puzzleoutput .= p . "Your Name: " . textfield("username") . " \ \;"; $puzzleoutput .= hidden("pick", $i+10); $puzzleoutput .= hidden("sq", "dummy", @nextrandomlist); $puzzleoutput .= hidden("win", "1"); $puzzleoutput .= hidden("selection", "$selection"); $puzzleoutput .= submit("See Puzzle / Scores"); } else { $puzzleoutput .= h3("A very good match!"); $puzzleoutput .= h4("Select another card."); } } else { $puzzleoutput .= h3("Sorry, that's not a match."); $puzzleoutput .= h4("Select another card."); @nextrandomlist[$a]=10; @nextrandomlist[$b]=10; } } else { if (!param("win")) { $puzzleoutput .= "<b>Select a card.</b>"; } else { $puzzleoutput .= "<font size=+1>Good Game, " . param("username") . "! "; $puzzleoutput .= "You won in " . $selection . " moves.</font><p>"; $scoreout = "<tr><td>Name</td><td>Score</td></tr>"; $i=0; $name = param("username"); open (INFILE, "< $scorefile"); while (<INFILE>) { if (($_ ne "") && ($_ ne "\n")) { s/\n//gi; push @scoretable, $_; } } close(INFILE); open (INFILE, "> $scorefile"); foreach $x (@scoretable) { # dont add the same score/name AGAIN. if ($x eq "$selection\:$name") { $i=1; } } if ($i==0) { push @scoretable, "$selection\:$name"; } $i=0; @scoretable = sort { $b <=> $a; } @scoretable; while ((@scoretable) && $i<10) { $i++; $_ = pop @scoretable; ($score, $name) = split /\:/, $_; print INFILE "$score\:$name\n"; $scoreout .= "<tr><td>$name</td><td>$score</td></tr>"; } close(INFILE); } } $i=0; if (param("win")) {$puzzleoutput .= "<table cellspacing=0 cellpadding=0 border=0>\n<tr>"; } else { $puzzleoutput .= "<table>\n<tr>"; } while ($i<@randomlist) { $link = "\<a href \=\"concentration.cgi?pick\=" . ($i + 10); $link .= "\&sq\=" . join("\&sq\=",@nextrandomlist); $link .= "\&selection\=" . ($selection + 1) . "\"\>"; $image = "\<img src\=\"" . $randomlist[$i+1] . "\"\>"; if (!($i % ($columns*2))) { $puzzleoutput .= "\n</tr>\n<tr>\n"; } $puzzleoutput .= "<td>"; if ($randomlist[$i] == -1) { $puzzleoutput .= $image; } if ($randomlist[$i] == -2) { $puzzleoutput .= "\<img src\=\"" . $picturelist[($i/2)] . "\"\>"; } if ($randomlist[$i] >= 0 ) { $puzzleoutput .= $link . "\<img src\=\"" . $facecard . "\"\>\<\/a\>"; } $puzzleoutput .= "</td>"; $i=$i+2; } $puzzleoutput .= "</table>\n</center>"; $skinoutput =~ s/\<\!\-\- concentration puzzle \-\-\>/$puzzleoutput/sig; $skinoutput =~ s/\<\!\-\- concentration score \-\-\>/$scoreout/sig; print $skinoutput;
Cloudjiffy- PaaS for Developers
10-05-2020, 12:30 AM in Web Hosting Forum