Proudly hosted with Dreamhost

Save $20 when signing up for Dreamhost by using the promo code amnuts20
If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh to encourage me to continue? Every little helps!
|
Battleships By Email (BBE)
Play battleships against an opponent via email! No database required as all information is passed along a URL.
A database is used in the script, however, to allow for recording of wins and losses.
One problem with this script is that Outlook's maximum querystring length seems to be 255 characters (or there abouts), and the URL created by this script is almost always longer than that. However, it works great with other mail clients such as Mozilla, Eudora, Pine, Elm, Mutt, etc.
index.php
20.36kb in size last modified May 6, 2006 at 1:54pm 6400 views, 6561 downloads
makeboard.php
<?php
include "setup.php";
if ($board == "") return; $barray = unserialize(gzuncompress(base64_decode(urldecode($board)))); if ($hits != "") $harray = unserialize(gzuncompress(base64_decode(urldecode($hits))));
// create image // 10x10 grid - 1 block = 10 pixels. 9 dividing lines. // 10x10 border on top and left $h = $w = (PSIZE * BWIDTH) + PSIZE + (BWIDTH - 1); $b = ImageCreate($w,$h); // setup colours $black = ImageColorAllocate($b,0,0,0); $white = ImageColorAllocate($b,255,255,255); $miss = ImageColorAllocate($b,$misccolours[MISS][0],$misccolours[MISS][1],$misccolours[MISS][2]); $hit = ImageColorAllocate($b,$misccolours[HIT][0],$misccolours[HIT][1],$misccolours[HIT][2]); $sea = ImageColorAllocate($b,$misccolours[SEA][0],$misccolours[SEA][1],$misccolours[SEA][2]); // make sea ImageFilledRectangle($b,0,0,$w,$h,$white); ImageFilledRectangle($b,PSIZE,PSIZE,$w,$h,$sea);
// the colours - board for ($y=0; $y<BDEPTH; $y++) { for ($x=0; $x<BWIDTH; $x++) { $newh = ((PSIZE*$y) + ($y==1?0:$y)) + (PSIZE+1); $neww = ((PSIZE*$x) + ($x==1?0:$x)) + (PSIZE+1); switch($barray[$y][$x]) { case HIT: ImageFilledRectangle($b,$neww,$newh,$neww+(PSIZE-1),$newh+PSIZE,$hit); break; case MISS: ImageFilledRectangle($b,$neww,$newh,$neww+PSIZE,$newh+PSIZE,$miss); break; default: if (($id = get_ship_number($barray[$y][$x])) != -1) { if ($sc[$id]=="") $sc[$id] = ImageColorAllocate($b,$shipcolours[$id][0],$shipcolours[$id][1],$shipcolours[$id][2]); ImageFilledRectangle($b,$neww,$newh,$neww+PSIZE,$newh+PSIZE,$sc[$id]); break; } } } }
// the colours - hits if ($hits != "") { for ($y=0; $y<BDEPTH; $y++) { for ($x=0; $x<BWIDTH; $x++) { $newh = ((PSIZE*$y) + ($y==1?0:$y)) + (PSIZE+1); $neww = ((PSIZE*$x) + ($x==1?0:$x)) + (PSIZE+1); switch($harray[$y][$x]) { case HIT: ImageFilledRectangle($b,$neww,$newh,$neww+(PSIZE-1),$newh+PSIZE,$hit); break; case MISS: ImageFilledRectangle($b,$neww,$newh,$neww+PSIZE,$newh+PSIZE,$miss); break; } } } }
// overlay the grid for ($i=0; $i<=BWIDTH; $i++) { $new = ((PSIZE*$i) + (($i==1?0:$i-1))) + (PSIZE+1); $new = ($new>=$w ? $w-1 : $new); ImageLine($b,floor(PSIZE/2),$new,$w,$new,$black); // l - r } for ($i=0; $i<=BDEPTH; $i++) { $new = ((PSIZE*$i) + (($i==1?0:$i-1))) + (PSIZE+1); $new = ($new>=$w ? $w-1 : $new); ImageLine($b,$new,floor(PSIZE/2),$new,$h,$black); // t - b }
// overlay the numbers $newy = (PSIZE/2) - (ImageFontHeight(2)/2); for ($i=0; $i<BWIDTH; $i++) { $new = (((PSIZE*$i) + (($i==1?0:$i-1))) + (PSIZE+(PSIZE/2))) - (((ImageFontWidth(FONT)*strlen($i))/2) - 1); $new = ($new>=$w ? $w-1 : $new); ImageString($b,FONT,$new,$newy,$i,$black); } $newy = (PSIZE/2) - (ImageFontHeight(FONT)/2) + 2; for ($i=0; $i<BWIDTH; $i++) { $new = (((PSIZE*$i) + (($i==1?0:$i-1))) + (PSIZE+(PSIZE/2))) - (((ImageFontWidth(FONT)*strlen($i))/2) + 2); $new = ($new>=$w ? $w-1 : $new); ImageString($b,FONT,$newy,$new,$i,$black); }
// now output the image header("Content-type: image/png"); ImagePNG($b);
// clean up //ImageDestroy($b);
function get_ship_number($id) { global $ships; for ($i=0; $i<SHIPTYPES; $i++) { if ($id == $ships[$i][symbol]) return $i; } return -1; }
?>
3.29kb in size last modified May 6, 2006 at 1:54pm 4929 views, 5735 downloads
makelegend.php
3.29kb in size last modified May 6, 2006 at 1:54pm 4981 views, 5661 downloads
makemap.php
437b in size last modified May 6, 2006 at 1:54pm 4645 views, 5682 downloads
setup.php
2.27kb in size last modified May 6, 2006 at 1:54pm 4745 views, 5740 downloads
|