<html>
<head>
<!--
Author: Travus Gonzalez
Date: 1/5/09
-->
<title>
BioCreator's Battleship!
</title>
<script>
// Enter a players name
var player = prompt('Enter Your Name!','Captain BioPlayer');
// Enemy chooses his location
var e11 = Math.round(Math.random()*24)+1;
var e12 = Math.round(Math.random()*24)+1;
while(e12 == e11)
{
e12 = Math.round(Math.random()*24)+1;
}
var e13 = Math.round(Math.random()*24)+1;
while(e13 == e12)
{
e13 = Math.round(Math.random()*24)+1;
}
var e14 = Math.round(Math.random()*24)+1;
while(e14 == e13)
{
e14 = Math.round(Math.random()*24)+1;
}
var e15 = Math.round(Math.random()*24)+1;
while(e15 == e14)
{
Math.round(Math.random()*24)+1;
}
// Allow player to set his ships in ocean
function setPlayerOcean()
{
alert("please place your 5 ships in your ocean by clicking on the appropriate location");
}
var isOkToSet = "yes";
// Player can place nore more then 5 ships into his ocean by clicking in cells
function PlaceShip(pl_num, target)
{
if(isOkToSet == "yes")
{
if(playerlocation[pl_num]=="empty")
{
document[target].src=plyrship.src;
playerlocation[pl_num]=battleship;
document.num_player.ships.value=eval(document.num_player.ships.value)+1;
if(eval(document.num_player.ships.value)>=5)
{
isOkToSet="no";
document.gameplay.status.value="Fire A Torpedo!!!";
}
}
else
{
alert("That area of your ocean is already occupied by one of your ships! \n Try another!");
}
}
else
{
alert(player + ", you have all ready placed your ships!");
}
}
</script>
<script>
// Defines the function of the player firing torpedoes
function Fire(el_num,target)
{
if(document.gameplay.status.value=="Game Over!")
{
alert("Click your browswer's reload button to play again")
}
else if(IsOkToSet=="no")
{
if(torpedobutton[el_num]=="empty")
{
torpedobutton[el_num]="used";
}
if(enemylocation[el_num]=="battleship")
{
document[target].src = enmyship.src;
document.num_enemy.ships.value=eval(document.num_enemy.ships.value)-1;
GameMaster('playerhit');
}
else
{
document[target].src = miss.src;
GameMaster('playerhit');
}
}
else
{
alert('You must first place your ships before firing torpedos!');
}
}
// Function of the enemy firing torpedos
function EnemyFire()
{
var randomshot = Math.round(Math.random()*24)+1;
while(enemytorpedo[randomshot]=="used")
{
randomshot = Math.round(Math.random()*24)+1;
}
enemytorpedo[randomshot]="used";
var playercell = 'P_' + randomshot;
if(playerlocation[randomshot]=="battleship")
{
document[playercell].src = enmyship.src;
document.num_player.ships.value=eval(document.num_player.ships.value)-1;
GameMaster('enemyhit');
}
else
{
document[playercell].src = miss.src;
GameMaster('enemymiss');
}
}
//Function that defines the array object
function MakeArray(n)
{
this.length = n;
for(var i = 0; i <= n; i++)
{
this[i] = "empty";
}
}
//setting all ocean cells to empty
enemylocation = new Array(25); var el = "empty";
playerlocation = new Array(25); var pl = "empty";
torpedobutton = new Array(25);
enemytorpedo = new Array(25);
playerlocation
var battleship = "battleship";
var pcellsrc = "nobattleship";
enemylocation[el1] = "battleship";
enemylocation[el2] = "battleship";
enemylocation[el3] = "battleship";
enemylocation[el4] = "battleship";
enemylocation[el5] = "battleship";
</script>
</head>
<body background="oceanbb.jpg">
<script>
var Plyrship = new Image(50, 50);
Plyrship.src = "plyrship.jpg";
var Enmyhidn = new Image(50, 50);
Enmyhidn.src = "enmyhidn.jpg";
var Ocnwater = new Image(50, 50);
Ocnwater.src = "ocnwater.jpg";
var Enmyship = new Image(50, 50);
Enmyship.src = "enmyship.jpg";
var Miss = new Image(50, 50);
Miss.src = "miss.jpg";
</script>
<p align="center"><img src="biobattleship_title.gif" height="110" width="300" /></p>
<h1 align="center">Enemy Territory</h1>
<!--Main Table1-->
<table cellpadding="0" cellspacing="0" width="750" bgcolor="#D9ECEC" border="0"
align="center">
<tr>
<td>
<!--Enemies Field-->
<table cellpadding="0" cellspacing="0" bgcolor="#0080FF" border="1">
<caption align="bottom"><b>Enemys Ocean</b></caption>
<tbody>
<tr>
<td>
<img src="enmyhidn.jpg" name="E_A1" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_A2" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_A3" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_A4" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_A5" width="50" height="50" />
</td>
</tr>
<tr>
<td>
<img src="enmyhidn.jpg" name="E_B1" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_B2" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_B3" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_B4" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_B5" width="50" height="50" />
</td>
</tr>
<tr>
<td>
<img src="enmyhidn.jpg" name="E_C1" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_C2" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_C3" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_C4" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_C5" width="50" height="50" />
</td>
</tr>
<tr>
<td>
<img src="enmyhidn.jpg" name="E_D1" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_D2" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_D3" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_D4" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_D5" width="50" height="50" />
</td>
</tr>
<tr>
<td>
<img src="enmyhidn.jpg" name="E_E1" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_E2" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_E3" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_E4" width="50" height="50" />
</td>
<td>
<img src="enmyhidn.jpg" name="E_E5" width="50" height="50" />
</td>
</tr>
</tbody>
</table>
</td>
<!--Control table-->
<td>
<table cellpadding="2" cellspacing="0" bgcolor="975EB3" border="1">
<caption align="bottom"><b>Control Panel</b></caption>
<tbody>
<tr>
<td width="40">
<form action=post>
<input onClick="Fire(1, E_A1)" type="button" value="A1" name="A1" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(2, E_A2)" type="button" value="A2" name="A2" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(3, E_A3)" type="button" value="A3" name="A3" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(4, E_A4)" type="button" value="A4" name="A4" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(5, E_A5)" type="button" value="A5" name="A5" />
</form>
</td>
</tr>
<tr>
<td width="40">
<form action=post>
<input onClick="Fire(6, E_B1)" type="button" value="B1" name="B1" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(7, E_B2)" type="button" value="B2" name="B2" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(8, E_B3)" type="button" value="B3" name="B3" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(9, E_B4)" type="button" value="B4" name="B4" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(10, E_B5)" type="button" value="B5" name="B5" />
</form>
</td>
</tr>
<tr>
<td width="40">
<form action=post>
<input onClick="Fire(11, E_C1)" type="button" value="C1" name="C1" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(12, E_C2)" type="button" value="C2" name="C2" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(13, E_C3)" type="button" value="C3" name="C3" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(14, E_C4)" type="button" value="C4" name="C4" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(15, E_C5)" type="button" value="C5" name="C5" />
</form>
</td>
</tr>
<tr>
<td width="40">
<form action=post>
<input onClick="Fire(16, E_D1)" type="button" value="D1" name="D1" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(17, E_D2)" type="button" value="D2" name="D2" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(18, E_D3)" type="button" value="D3" name="D3" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(19, E_D4)" type="button" value="D4" name="D4" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(20, E_D5)" type="button" value="D5" name="D5" />
</form>
</td>
</tr>
<tr>
<td width="40">
<form action=post>
<input onClick="Fire(21, E_E1)" type="button" value="E1" name="E1" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(22, E_E2)" type="button" value="E2" name="E2" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(23, E_E3)" type="button" value="E3" name="E3" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(24, E_E4)" type="button" value="E4" name="E4" />
</form>
</td>
<td width="40">
<form action=post>
<input onClick="Fire(25, E_E5)" type="button" value="E5" name="E5" />
</form>
</td>
</tr>
</tbody>
</table>
<h1 style="text-align:center;"></h1>
</td>
</tr>
</table>
<br />
<!--Main Table2-->
<table cellpadding="0" cellspacing="0" width="750" bgcolor="#D9ECEC" border="0"
align="center">
<tr>
<td>
<!--Ocean Table-->
<table cellpadding="0" width="150" border="0" bgcolor="#D9ECEC" align="right">
<caption align="bottom"><b>Your Ocean</b></caption>
<tbody>
<tr>
<td>
<a onClick="PlaceShip(1, 'P_1');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_1" /></a>
</td>
<td>
<a onClick="PlaceShip(2, 'P_2');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_2" /></a>
</td>
<td>
<a onClick="PlaceShip(3, 'P_3');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_3" /></a>
</td>
<td>
<a onClick="PlaceShip(4, 'P_4');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_4" /></a>
</td>
<td>
<a onClick="PlaceShip(5, 'P_5');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_5" /></a>
</td>
</tr>
<tr>
<td>
<a onClick="PlaceShip(6, 'P_6');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_6" /></a>
</td>
<td>
<a onClick="PlaceShip(7, 'P_7');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_7" /></a>
</td>
<td>
<a onClick="PlaceShip(8, 'P_8');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_8" /></a>
</td>
<td>
<a onClick="PlaceShip(9, 'P_9');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_9" /></a>
</td>
<td>
<a onClick="PlaceShip(10, 'P_10');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_10" /></a>
</td>
</tr>
<tr>
<td>
<a onClick="PlaceShip(11, 'P_11');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_11" /></a>
</td>
<td>
<a onClick="PlaceShip(12, 'P_12');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_12" /></a>
</td>
<td>
<a onClick="PlaceShip(13, 'P_13');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_13" /></a>
</td>
<td>
<a onClick="PlaceShip(14, 'P_14');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_14" /></a>
</td>
<td>
<a onClick="PlaceShip(15, 'P_15');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_15" /></a>
</td>
</tr>
<tr>
<td>
<a onClick="PlaceShip(16, 'P_16');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_16" /></a>
</td>
<td>
<a onClick="PlaceShip(17, 'P_17');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_17" /></a>
</td>
<td>
<a onClick="PlaceShip(18, 'P_18');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_18" /></a>
</td>
<td>
<a onClick="PlaceShip(19, 'P_19');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_19" /></a>
</td>
<td>
<a onClick="PlaceShip(20, 'P_20');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_20" /></a>
</td>
</tr>
<tr>
<td>
<a onClick="PlaceShip(21, 'P_21');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_21" /></a>
</td>
<td>
<a onClick="PlaceShip(22, 'P_22');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_22" /></a>
</td>
<td>
<a onClick="PlaceShip(23, 'P_23');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_23" /></a>
</td>
<td>
<a onClick="PlaceShip(24, 'P_24');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_24" /></a>
</td>
<td>
<a onClick="PlaceShip(25, 'P_25');" href="#boit"><img height="50" width="50"
src="ocnwater.jpg" name="P_25" /></a>
</td>
</tr>
</tbody>
</table>
<!--Status Table-->
<table cellpadding="0" width="750" bgColor-"#d9ECEC" border="0" align="center">
<tr>
<td>
<table cellpadding="0" bgColor="#975EB3" border="0">
<tr>
<td>
<h3>Who's Turn?</h3>
</td>
<td>
<form name="whos" action="post">
<input onfocus="blur();" value="Your turn" name="turn" size="20" />
</form>
</td>
</tr>
<tr>
<td>
<h3>Status</h3>
</td>
<td>
<form name="gamePlay" action="post">
<input onfocus="blur();" value="Place Your Ships" name="status" size="20" />
</form>
</td>
</tr>
<tr>
<td>
<h3># of your ships</h3>
</td>
<td>
<form name="num" action="post">
<input onfocus="blur();" value="0" name="ships" size="20" />
</form>
</td>
</tr>
<tr>
<td>
<h3># of enemy ships</h3>
</td>
<td>
<form name="num_enemy" action="post">
<input onfocus="blur();" value="5" name="ships" size="20" />
</form>
</td>
</tr>
<tr>
<td>
<h3>Who is Winning?</h3>
</td>
<td>
<form name="whois" action="post">
<input onfocus="blur();" value="Its a Tie" name="winning" size="20" />
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>