Location: PHPKode > projects > Blackbeard's Revenge > shipyard.php
<?php
session_start(); 
//header("Cache-control: private");

require_once "headers.php";
require_once "common.php";

echo"<BODY><div align=left>";
echo "<form action=\"shipyard.php\" method=\"POST\">";
echo "<br><br>";
echo "<table class=\"menu\">";
echo "	<tr>";
echo "		<td class=\"menu\" style=\"height:25px;width:450px;text-align:center\" colspan=3><img src=\"../images/shipyard.png\"></td>";
echo "	</tr>";
echo "	<tr>";
echo "		<td style=\"text-align:center\"><img src=\"../images/shipSale.png\"></td>";
echo "		<td style=\"text-align:center\"><img src=\"../images/cannon.png\"></td>";
echo "		<td style=\"text-align:center\"><img src=\"../images/rechristen.png\"></td>";
echo "	</tr>";
echo "	<tr>";
echo "		<td class=\"body\" style=\"text-align:Center;width:150px\"><a href=\"shipyard.php?module=1\">Buy / Sell Ship</td>";
echo "		<td class=\"body\" style=\"text-align:Center;width:150px\"><a href=\"shipyard.php?module=2\">Purchase Upgrades</td>";
echo "		<td class=\"body\" style=\"text-align:Center;width:150px\"><a href=\"shipyard.php?module=3\">Rename your vessel</td>";
echo "	</tr>";

$cannonbought = 0;
$platingbought = 0;


switch($_GET["module"])
{
	case 0:				
			if($_POST['action'] == "trade")
			{
				$query = "SELECT * FROM shiptype WHERE id = ".$_POST['buyship']." ";
				$result = db_query($query);	
				$row = db_fetch_assoc($result);

				if(($_SESSION['playergold'] + $_SESSION['myshipvalue']) >  $row["basevalue"])
				{
					$_SESSION['playershipnum'] = $row["id"];
					$_SESSION['myshipclass']   = $row["class"];
					$_SESSION['myshiptype']    = $row["id"];
					$_SESSION['myshiphull']    = $row["basehull"];
					$_SESSION['myshipmaxhull'] = $row["basehull"];
					$_SESSION['myshipmanuver'] = $row["basemanuver"];
					$_SESSION['mycannons']     = $row["basecannon"];
					$_SESSION['myarmor']       = $row["basearmour"];
					$_SESSION['myshipvalue']   = $row["basevalue"];
					$_SESSION['playergold']    = $_SESSION['playergold'] + $_SESSION['myshipvalue'] - $row["basevalue"];
					echo "<tr><td colspan=\"3\" class=\"message\">". $_SESSION['myshipclass']. " purchased</td></tr>";
					SavePlayerShip();
					SaveNewPlayerShip();
				}
				else
					echo "<tr><td colspan=\"3\" class=\"message\">You do not have enough gold to make this purchase</td></tr>";
			}
			else if($_POST['action'] == "Buy")
			{

				$query = "SELECT * FROM shiptype WHERE id = ".$_SESSION['myshiptype']." ";
				$result = db_query($query);	
				$row = db_fetch_assoc($result);

				$_SESSION['ShipMaxCannon'] = $row["maxcannon"];
				$_SESSION['ShipMaxArmour'] = $row["maxarmour"];

				if($_SESSION['mycannons'] == $_SESSION['ShipMaxCannon'] && $_POST['buycannon'] > 0)
				{
					echo "<tr><td colspan=\"3\" class=\"message\">You already have the maximum number of cannons</td></tr>";
				}
				else if($_SESSION['playergold'] < (CANNONCOST * $_POST['buycannon']) && $_POST['buycannon'] > 0)
				{
					echo "<tr><td colspan=\"3\" class=\"message\">You don't have enough gold to buy that many cannon.</td></tr>";
				}
				else if(($_POST['buycannon']+$_SESSION['mycannons']) > $_SESSION['ShipMaxCannon'] && $_POST['buycannon'] > 0)
				{
					$cannonbought = ($_SESSION['ShipMaxCannon'] - $_SESSION['mycannons']);
					$_SESSION['mycannons'] = $_SESSION['ShipMaxCannon'];

					$_SESSION['playergold'] = $_SESSION['playergold'] - CANNONCOST * $cannonbought;
					echo "<tr><td colspan=\"3\" class=\"message\">You were only able to purchase ". $cannonbought ."  cannon</td></tr>";
				}
				else if($_POST['buycannon'] > 0)
				{
					$cannonbought = ($_SESSION['ShipMaxCannon'] - $_SESSION['mycannons']);
					$_SESSION['mycannons'] = $_SESSION['ShipMaxCannon'];

					$_SESSION['playergold'] = $_SESSION['playergold'] - CANNONCOST * $cannonbought;
					echo "<tr><td colspan=\"3\" class=\"message\">You purchased ". $cannonbought ."  cannon</td></tr>";
				}

				if($_SESSION['myarmor'] == $_SESSION['ShipMaxArmour'] && $_POST['buyarmor'] > 0)
				{
					echo "<tr><td colspan=\"3\" class=\"message\">You already have the maximum hull plating.</td></tr>";
				}
				else if($_SESSION['playergold'] < (ARMORCOST * $_POST['buyarmor']) && $_POST['buyarmor'] > 0)
				{
					echo "<tr><td colspan=\"3\" class=\"message\">You don't have enough gold to buy that much hull plating.</td></tr>";
				}
				else if(($_POST['buyplating'] + $_SESSION['ShipMaxArmour']) > $_SESSION['ShipMaxArmour'] &&  $_POST['buyplating'] > 0)
				{
					$platingbought = ($_SESSION['ShipMaxArmour'] - $_SESSION['myarmor']);
					$_SESSION['myarmor']  = $_SESSION['ShipMaxArmour'];

					$_SESSION['playergold'] = $_SESSION['playergold'] - ARMORCOST * $platingbought;
					echo "<tr><td colspan=\"3\" class=\"message\">You were only able to purchase ". $platingbought ." maximum hull plating.</td></tr>";
				}
				else if($_POST['buyplating'] > 0)
				{					
					$platingbought = $buyplating;
					$_SESSION['myarmor']  = $_SESSION['ShipMaxArmour'];

					$_SESSION['playergold'] = $_SESSION['playergold'] - ARMORCOST * $platingbought;
					echo "<tr><td colspan=\"3\" class=\"message\">You purchased ".$platingbought ."  maximum hull plating.</td></tr>";
				}

				SavePlayerShip();
			}
			else if($_POST['action'] == "Sell")
			{
				
			}
			else if($_POST['action'] == "Change")
			{
				$_SESSION['myshipname'] = $_POST['newshipname'];
				SavePlayerShip();
			}
			else
			{
				echo "<tr><td colspan=\"3\">Welcome to Fred's Shipyard</td></tr>";
			}

			break;
	case 1:
			echo "	<tr>";
			echo "		<td colspan=3 style=\"width:450px\">";
			echo "			<div align=center><table class=\"data\" style=\"width:400px\">";
			echo "				<tr>";
			echo "					<td class=\"header\" style=\"text-align:Left\" colspan=1>Your ship</td>";
			echo "					<td class=\"header\" style=\"text-align:Left\">Trade in</td>";
			echo "					<td class=\"header\" style=\"text-align:Left\"></td>";
			echo "				</tr>";

			echo "				<tr>";
			echo "					<td class=\"body\" style=\"text-align:Left\" colspan=1>". $_SESSION['myshipclass'] ."</td>";
			echo "					<td class=\"body\" style=\"text-align:Right\">". $_SESSION['myshipvalue'] ."</td>";
			echo "					<td class=\"body\" style=\"text-align:Center\"></td>";
			echo "				</tr>";				

			echo "				<tr>";
			echo "					<td class=\"header\" style=\"text-align:Left\" colspan=1>Ships available</td>";
			echo "					<td class=\"header\" style=\"text-align:Left\">Cost</td>";
			echo "					<td class=\"header\" style=\"text-align:Left\">Select</td>";
			echo "				</tr>";			
			$query = "SELECT id, class, basevalue FROM shiptype ORDER BY basevalue";
			$result = db_query($query);

			while ($row = db_fetch_assoc($result))
			{
				echo "				<tr>";
				echo "					<td class=\"body\" style=\"text-align:Left\" colspan=1>". $row["class"] ."</td>";
				echo "					<td class=\"body\" style=\"text-align:Right\">". $row["basevalue"] ."</td>";
				echo "					<td class=\"body\" style=\"text-align:Center\"><input class=\"value\" type=\"radio\" name=\"buyship\" value=\"". $row["id"] ."\"></td>";
				echo "				</tr>";
			}
			echo "			</table></div>";
			echo "			</td>";
			echo "		</tr>";
			echo "		<tr>";
			echo "			<td colspan=2></td>";
			echo "			<td style=\"text-align:Center;width:150px\"><input class=\"button\" type=\"Submit\" name=\"action\" value=\"trade\"></td>";
			echo "		</tr>";
			break;
	case 2:		
			echo "<tr>";
			echo "		<td colspan=3 style=\"width:450px\">";
			echo "			<div align=center><table class=\"data\" style=\"width:400px\">";
			echo "				<tr><td class=\"header\" style=\"text-align:Left\" colspan=2>Your ship currently has the following:</td>";
			echo "				<td class=\"header\" style=\"text-align:Left\">Cost per</tr>";
			echo "				<td class=\"header\" style=\"text-align:Center\">#</tr>";
			echo "				<tr><td class=\"body\" style=\"text-align:Left\">Cannon</td><td class=\"body\" style=\"text-align:Center\">". $_SESSION['mycannons'] ."</td>";
			echo "				<td class=\"body\" style=\"text-align:Right\">".CANNONCOST."</td>";
			echo "				<td class=\"body\" style=\"text-align:Center\"><input class=\"value\" type=\"text\" name=\"buycannon\" value=\"0\"></td></tr>";
			echo "				<tr><td class=\"body\" style=\"text-align:Left\">Hull plating</td><td class=\"body\" style=\"text-align:Center\">". $_SESSION['myarmor'] ."</td>";
			echo "				<td class=\"body\" style=\"text-align:Right\">".ARMORCOST."</td>";
			echo "				<td class=\"body\" style=\"text-align:Center\"><input class=\"value\" type=\"text\" name=\"buyplating\" value=\"0\"></td></tr>";
			echo "			</table></div>";
			echo "		</td>";
			echo "	</tr>";
			echo "	<tr>";
			echo "		<td></td>";
			echo "		<td style=\"text-align:Center;width:150px\"><input class=\"button\" type=\"Submit\" name=\"action\" value=\"Buy\"></td>";
			echo "		<td style=\"text-align:Center;width:150px\"><input class=\"button\" type=\"Submit\" name=\"action\" value=\"Sell\"></td>";
			echo "	</tr>";
			break;
	case 3:	
			echo "<tr>";
			echo "			<td colspan=3 style=\"width:450px\">";
			echo "			<div align=center>";
			echo "				<table class=\"data\" style=\"width:400px\">";
			echo "				<tr>";
			echo "					<td class=\"header\" style=\"text-align:Left\" colspan=3>Your vessel's name:</td>";
			echo "					<td class=\"header\" style=\"text-align:Left\"></td>";
			echo "				</tr>";
			echo "				<tr>";
			echo "					<td class=\"body\" style=\"width:100px\"></td>";
			echo "					<td class=\"body\" style=\"text-align:Left\">". $_SESSION['myshipname'] ."</td>";	
			echo "					<td class=\"body\" style=\"width:100px\"></td>";
			echo "				</tr>";	
			echo "				<tr>";
			echo "					<td class=\"header\" style=\"text-align:Left\" colspan=3>Change name to:</td>";
			echo "					<td class=\"header\"></td>";
			echo "				</tr>";
			echo "				<tr>";
			echo "					<td class=\"body\" style=\"width:100px\"></td>";
			echo "					<td class=\"body\" style=\"text-align:Cente\"><input class=\"login\" style=\"width:150px\" type=\"text\" name=\"newshipname\" value=\"". $_SESSION['myshipname'] ."\"></td>	";	
			echo "					<td class=\"body\"></td>";
			echo "				</tr>";
			echo "			</table>";
			echo "			</td>";
			echo "		</tr>";
			echo "		<tr>";
			echo "			<td colspan=2></td>";
			echo "			<td style=\"text-align:Center;width:150px\"><input class=\"button\" type=\"Submit\" name=\"action\" value=\"Change\"></td>";
			echo "		</tr>";
			break;	
	default:			
			echo "<tr><td colspan=\"3\" class=\"message\">Welcome to Federated Ship Yards</td></tr>";
			break;
}

echo "</table>";	
echo "</form>";
echo "</div>";
echo "</BODY>";
include("footer.php");
?>
Return current item: Blackbeard's Revenge