Php Battleship

Web, Mobile & Software Dev Web Development Posted 2 years ago

Fixed Price

Delivery by July 17, 2013

$50.00

Budget

Details

Create a battleship game. Make sure to include all the standard rules of the game. Also must include storing of variables (session or hidden), functions, and arrays.Battleship Game:
Create a battleship game. Make sure to include all the standard rules of the game.
Also must include storing of variables (session or hidden), functions, and arrays.
Create a battleship game 10 by 10 check box in table .
when randomly checkbox is check and submit (Hit).
it should pop up HIT the ship or Miss the ship.
Hit or destroy ship must be check (check on checkbox) and save .
Again when u randomly check the checkbox . it must save all the Hit ship and show  the total Hit and miss .  
Total result show when u click total 10 clicks(Hit or miss).

Please use my code that I have already done so it is easy for me to understand.
<?php session_start() ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>assignment31.php</title>
</head>
<body>

<?php

//build the arrays
$column1 = array(
'a1','a2','a3','a4','a5','a6','a7','a8','a9','a10'
);
$column2 = array(
'b1','b2','b3','b4','b5','b6','b7','b8','b9','b10'
);
$column3 = array(
'c1','c2','c3','c4','c5','c6','c7','c8','c9','c10'
);
$column4 = array(
'd1','d2','d3','d4','d5','d6','d7','d8','d9','d10'
);
$column5 = array(
'e1','e2','e3','e4','e5','e6','e7','e8','e9','e10'
);
$column6 = array(
'f1','f2','f3','f4','f5','f6','f7','f8','f9','f10'
);
$column7 = array(
'g1','g2','g3','g4','g5','g6','g7','g8','g9','g10'
);
$column8 = array(
'h1','h2','h3','h4','h5','h6','h7','h8','h9','h10'
);
$column9 = array(
'i1','i2','i3','i4','i5','i6','i7','i8','i9','i10'
);
$column10 = array(
'j1','j2','j3','j4','j5','j6','j7','j8','j9','j10'
);
//build the master array
$row = array(
"a"=>$column1,
"b"=>$column2,
"c"=>$column3,
"d"=>$column4,
"e"=>$column5,
"f"=>$column6,
"g"=>$column7,
"h"=>$column8,
"i"=>$column9,
"j"=>$column10
);

//start start the game
createBoard();
placeShips();

//create function placeShips
function placeShips(){
//bring in the arrays
GLOBAL $column1,$column2,$column3,$column4,
$column5,$column6,$column7,$column8,$column9,
$column10,$row;


$carrier = 5;
$battleship = 4;
$destroyer = 3;
$submarine = 3;
$patrolBoat = 2;


//check if rand check box returns a value

if (isset($_SESSION["randBoard"]))
{
$randBoard = $_SESSION["randBoard"];
}
else
{
$r = array_rand($row);
$c = rand(1,10)-1;
$randBoard = $row[$r][$c];
$_SESSION["randBoard"] = $randBoard;
}
$chkRow = filter_input(INPUT_POST,"$randBoard");
print "$randBoard";
if
(isset($chkRow))
{
echo "hit on $randBoard!";
}
/*function patrolBoat(){
$axis = rand(1,2);
if (isset($_SESSION["randBoard"])){
$randBoard = $_SESSION["randBoard"];
}else{
$r = array_rand($row);
$c = rand(1,10)-1;
$randBoard = $row[$r][$c];
$_SESSION["randBoard"] = $randBoard;
}//end if else
if ($axis == 1){
for ($i=1;$i<=2;$i++){
$r++;
$patrolBoat1 = $row[$r][$c];
print "<p>$patrolBoat1</p>";
}//end for
}//end if
elseif ($axis == 2){
for ($i=1;$i<=2;$i++){
$c++;
$patrolBoat2 = $row[$r][$c];
print "<p>$patrolBoat2</p>";
}//end for
}//end elseif
$randPB = filter_input(INPUT_POST,"$patrolBoat2");
if (isset($randPB)){
echo "hit on $patrolBoat2!";
}

}*///end patrolBoat()

}//end placeShips()


//create function createBoard
function createBoard(){
//bring in the arrays
GLOBAL $column1,$column2,$column3,$column4,$column5,$column6,$column7,$column8,$column9,$column10,$row;

//creating the checkbox battleship board
print<<<HERE

<form method = "post"
action = "">
<table border = "1">

HERE;

for ($i="a";$i<="j";$i++){
print "<tr>";
foreach ($row["$i"] as $chkRow){
print "<td><input type = 'checkbox' name = '$chkRow' value = '$chkRow'/>$chkRow</td>\n";
}//end foreach
print"</tr>\n";
} //end for loop

print "</table>";

print "<button type = 'submit'>Fire!</button></form>";


} //end function



?>

</body>
</html>

Skills Required:

Client Activity on this Job

Last Viewed: 1 year ago

Applicants: 33

Hired: 1


About the Client

(0.00) 0 reviews

United States
Marietta 11:57 PM

2 Jobs Posted
50% Hire Rate, 1 Open Job

$125 Total Spent
1 Hire, 0 Active

Member Since Jul 16, 2013