andy's php projects
Script and site usage:
All of the scripts on this site are provided free for non-commercial, personal or non-profit use. If you wish to use any of these in a commercial system, please refer to the payment plan.

Support:
Support for each of the scripts is given, free of charge, on the message board. Each script has its own message board which can be accessed by clicking on the 'project forum' link (beneath the description of each project).


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!

Zend Certified Engineer logo


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 9:54pm
4790 views, 5579 downloads

makeboard.php

3.29kb in size
last modified May 6, 2006 at 9:54pm
3910 views, 4835 downloads

makelegend.php

3.29kb in size
last modified May 6, 2006 at 9:54pm
3923 views, 4743 downloads

makemap.php

437b in size
last modified May 6, 2006 at 9:54pm
3702 views, 4786 downloads

setup.php

<?php

    
//
    // Battleships By Email
    // version 1.0.0
    // 
    // Andrew Collington, 2002
    // php@amnuts.com, http://php.amnuts.com/
    //
    
    
    // these two should be all you need to change
    
define("BBEURL","http://php.amnuts.com/devarticles_bbe/index.php");
    
$dbVars = array(
        
"user" => "username",
        
"pass" => "password",
        
"host" => "localhost",
        
"name" => "battleships",
        
"tbl_results" => "results"
    
);
    
    
    
// players
    
define("PLAYER1",0);
    
define("PLAYER2",1);
    
    
// directions
    
define("E",  0);
    
define("SE"1);
    
define("S",  2);
    
define("SW"3);
    
define("W",  4);
    
define("NW"5);
    
define("N",  6);
    
define("NE"7);
    
    
// boards
    
define("SPACER",2);
    
define("FONT",2);
    
define("BWIDTH",10);
    
define("BDEPTH",10);
    
define("PSIZE",14);  // pixel size per square
    
define("HIT",1);
    
define("MISS",2);
    
define("SEA",3);
    
    
// directions
    
$xincr = array(110, -1, -1, -1,  0,  1);
    
$yincr = array(011,  1,  0, -1, -1, -1);
    
    
// ships
    
define("SHIPTYPES"5);
    
define("CARRIER",0);
    
define("BATTLE",1);
    
define("DESTROYER",2);
    
define("SUBMARINE",3);
    
define("PTBOAT",4);
    
    
$ships = array(
        
CARRIER => array(
            
"name"   => "Aircraft Carrier",
            
"hits"   => 0,
            
"symbol" => "A",
            
"length" => 5,
            
"x"      => 0,
            
"y"      => 0,
            
"dir"    => 0,
            
"placed" => 0
            
),
        
BATTLE => array(
            
"name"   => "Battleship",
            
"hits"   => 0,
            
"symbol" => "B",
            
"length" => 4,
            
"x"      => 0,
            
"y"      => 0,
            
"dir"    => 0,
            
"placed" => 0
            
),
        
DESTROYER => array(
            
"name"   => "Destroyer",
            
"hits"   => 0,
            
"symbol" => "D",
            
"length" => 3,
            
"x"      => 0,
            
"y"      => 0,
            
"dir"    => 0,
            
"placed" => 0
            
),
        
SUBMARINE => array(
            
"name"   => "Submarine",
            
"hits"   => 0,
            
"symbol" => "S",
            
"length" => 3,
            
"x"      => 0,
            
"y"      => 0,
            
"dir"    => 0,
            
"placed" => 0
            
),
        
PTBOAT => array(
            
"name"   => "PT Boat",
            
"hits"   => 0,
            
"symbol" => "P",
            
"length" => 2,
            
"x"      => 0,
            
"y"      => 0,
            
"dir"    => 0,
            
"placed" => 0
            
)
        );
    
    
$shipcolours = array(
        
CARRIER => array(72,72,72),
        
BATTLE => array(120,120,120),
        
DESTROYER => array(148,148,148),
        
SUBMARINE => array(169,169,169),
        
PTBOAT => array(213,213,213)
        );
    
    
$misccolours = array(
        
SEA => array(0,0,255),
        
HIT => array(255,0,0),
        
MISS => array(255,255,0)
        );

?>
2.27kb in size
last modified May 6, 2006 at 9:54pm
3750 views, 4834 downloads
list all projects :: this project's forum :: script in action
added Sep 19, 2002 at 2:51pm :: updated Apr 27, 2003 at 5:13pm :: 5 files :: 18796 views

© Andrew Collington, 2002-2007.