aboutsummaryrefslogtreecommitdiff
path: root/games/battleship
diff options
context:
space:
mode:
Diffstat (limited to 'games/battleship')
-rw-r--r--games/battleship/batt1.gifbin0 -> 871 bytes
-rw-r--r--games/battleship/batt10.gifbin0 -> 871 bytes
-rw-r--r--games/battleship/batt100.gifbin0 -> 824 bytes
-rw-r--r--games/battleship/batt101.gifbin0 -> 866 bytes
-rw-r--r--games/battleship/batt102.gifbin0 -> 881 bytes
-rw-r--r--games/battleship/batt103.gifbin0 -> 899 bytes
-rw-r--r--games/battleship/batt2.gifbin0 -> 865 bytes
-rw-r--r--games/battleship/batt201.gifbin0 -> 851 bytes
-rw-r--r--games/battleship/batt202.gifbin0 -> 834 bytes
-rw-r--r--games/battleship/batt203.gifbin0 -> 848 bytes
-rw-r--r--games/battleship/batt204.gifbin0 -> 849 bytes
-rw-r--r--games/battleship/batt205.gifbin0 -> 849 bytes
-rw-r--r--games/battleship/batt206.gifbin0 -> 855 bytes
-rw-r--r--games/battleship/batt3.gifbin0 -> 866 bytes
-rw-r--r--games/battleship/batt4.gifbin0 -> 864 bytes
-rw-r--r--games/battleship/batt5.gifbin0 -> 869 bytes
-rw-r--r--games/battleship/batt6.gifbin0 -> 873 bytes
-rw-r--r--games/battleship/batt7.gifbin0 -> 882 bytes
-rw-r--r--games/battleship/batt8.gifbin0 -> 882 bytes
-rw-r--r--games/battleship/batt9.gifbin0 -> 883 bytes
-rw-r--r--games/battleship/common.css171
-rw-r--r--games/battleship/index.html401
-rw-r--r--games/battleship/splashscreen.pngbin0 -> 5627 bytes
23 files changed, 572 insertions, 0 deletions
diff --git a/games/battleship/batt1.gif b/games/battleship/batt1.gif
new file mode 100644
index 0000000..eac0022
--- /dev/null
+++ b/games/battleship/batt1.gif
Binary files differ
diff --git a/games/battleship/batt10.gif b/games/battleship/batt10.gif
new file mode 100644
index 0000000..0629114
--- /dev/null
+++ b/games/battleship/batt10.gif
Binary files differ
diff --git a/games/battleship/batt100.gif b/games/battleship/batt100.gif
new file mode 100644
index 0000000..ccc7e60
--- /dev/null
+++ b/games/battleship/batt100.gif
Binary files differ
diff --git a/games/battleship/batt101.gif b/games/battleship/batt101.gif
new file mode 100644
index 0000000..9aed99e
--- /dev/null
+++ b/games/battleship/batt101.gif
Binary files differ
diff --git a/games/battleship/batt102.gif b/games/battleship/batt102.gif
new file mode 100644
index 0000000..791bda9
--- /dev/null
+++ b/games/battleship/batt102.gif
Binary files differ
diff --git a/games/battleship/batt103.gif b/games/battleship/batt103.gif
new file mode 100644
index 0000000..8dd900d
--- /dev/null
+++ b/games/battleship/batt103.gif
Binary files differ
diff --git a/games/battleship/batt2.gif b/games/battleship/batt2.gif
new file mode 100644
index 0000000..d825f39
--- /dev/null
+++ b/games/battleship/batt2.gif
Binary files differ
diff --git a/games/battleship/batt201.gif b/games/battleship/batt201.gif
new file mode 100644
index 0000000..65ae3a1
--- /dev/null
+++ b/games/battleship/batt201.gif
Binary files differ
diff --git a/games/battleship/batt202.gif b/games/battleship/batt202.gif
new file mode 100644
index 0000000..d44b498
--- /dev/null
+++ b/games/battleship/batt202.gif
Binary files differ
diff --git a/games/battleship/batt203.gif b/games/battleship/batt203.gif
new file mode 100644
index 0000000..9a61163
--- /dev/null
+++ b/games/battleship/batt203.gif
Binary files differ
diff --git a/games/battleship/batt204.gif b/games/battleship/batt204.gif
new file mode 100644
index 0000000..64e0fe7
--- /dev/null
+++ b/games/battleship/batt204.gif
Binary files differ
diff --git a/games/battleship/batt205.gif b/games/battleship/batt205.gif
new file mode 100644
index 0000000..c243903
--- /dev/null
+++ b/games/battleship/batt205.gif
Binary files differ
diff --git a/games/battleship/batt206.gif b/games/battleship/batt206.gif
new file mode 100644
index 0000000..bbbee53
--- /dev/null
+++ b/games/battleship/batt206.gif
Binary files differ
diff --git a/games/battleship/batt3.gif b/games/battleship/batt3.gif
new file mode 100644
index 0000000..28345e7
--- /dev/null
+++ b/games/battleship/batt3.gif
Binary files differ
diff --git a/games/battleship/batt4.gif b/games/battleship/batt4.gif
new file mode 100644
index 0000000..95aba94
--- /dev/null
+++ b/games/battleship/batt4.gif
Binary files differ
diff --git a/games/battleship/batt5.gif b/games/battleship/batt5.gif
new file mode 100644
index 0000000..1dc9b9f
--- /dev/null
+++ b/games/battleship/batt5.gif
Binary files differ
diff --git a/games/battleship/batt6.gif b/games/battleship/batt6.gif
new file mode 100644
index 0000000..21b951f
--- /dev/null
+++ b/games/battleship/batt6.gif
Binary files differ
diff --git a/games/battleship/batt7.gif b/games/battleship/batt7.gif
new file mode 100644
index 0000000..87d8d65
--- /dev/null
+++ b/games/battleship/batt7.gif
Binary files differ
diff --git a/games/battleship/batt8.gif b/games/battleship/batt8.gif
new file mode 100644
index 0000000..890c402
--- /dev/null
+++ b/games/battleship/batt8.gif
Binary files differ
diff --git a/games/battleship/batt9.gif b/games/battleship/batt9.gif
new file mode 100644
index 0000000..2060538
--- /dev/null
+++ b/games/battleship/batt9.gif
Binary files differ
diff --git a/games/battleship/common.css b/games/battleship/common.css
new file mode 100644
index 0000000..01fd8f5
--- /dev/null
+++ b/games/battleship/common.css
@@ -0,0 +1,171 @@
+body {
+ font-family:Segoe UI;
+ color:#FFFFFF;
+ margin:0px;
+ padding:0px;
+}
+img, a {
+ outline:none;
+ border:none;
+}
+#splashscreen {
+ margin:0;
+ position:fixed;
+ top:0;
+ width:100%;
+ height:100%;
+ color:#FFFFFF;
+ background-image:url('splashscreen.png');
+ background-position:center;
+ background-color:#336BCD;
+ background-repeat:no-repeat;
+ animation:splash 4s;
+ -ms-animation:splash 4s;
+ -webkit-animation:splash 4s;
+ -o-animation:splash 4s;
+ opacity:0;
+ z-index:-1;
+}
+@keyframes splash {
+ from {
+ z-index:999;
+ opacity: 1;
+ }
+ 66% {
+ opacity: 1;
+ }
+ to {
+ opacity:0;
+ z-index:1;
+ display:none;
+ }
+}
+@-webkit-keyframes splash {
+ from {
+ z-index:999;
+ opacity: 1;
+ }
+ 66% {
+ opacity: 1;
+ }
+ to {
+ opacity:0;
+ z-index:1;
+ display:none;
+ }
+}
+@-ms-keyframes splash {
+ from {
+ z-index:999;
+ opacity: 1;
+ }
+ 66% {
+ opacity: 1;
+ }
+ to {
+ opacity:0;
+ z-index:1;
+ display:none;
+ }
+}
+@-o-keyframes splash {
+ from {
+ z-index:999;
+ opacity: 1;
+ }
+ 66% {
+ opacity: 1;
+ }
+ to {
+ opacity:0;
+ z-index:1;
+ display:none;
+ }
+}
+#hoverarea {
+ position:fixed;
+ top:0px;
+ right:0px;
+ width:15px;
+ height:15px;
+}
+#bottomhoverarea {
+ position:fixed;
+ bottom:0px;
+ right:0px;
+ width:15px;
+ height:15px;
+}
+#starthoverarea {
+ position:fixed;
+ bottom:0px;
+ left:0px;
+ width:15px;
+ height:15px;
+}
+#charmsbar {
+ display:none;
+ background-color:#111111;
+ position:fixed;
+ padding:5% 0;
+ top:0px;
+ right:0px;
+ height:100%;
+ width: 86px;
+
+}
+#settingscharms {
+ padding : 40px;
+ display:none;
+ background-color:#3B66AD;
+ position:fixed;
+ top:0px;
+ right:0px;
+ height:100%;
+ width: 345px;
+
+}
+#startbutton {
+ display:none;
+ position:fixed;
+ left:0px;
+ bottom:0px;
+}
+#iconnetwork {
+ position:absolute;
+ top:35px;
+ left:25px;
+}
+#iconbattery {
+ position:absolute;
+ bottom:35px;
+ left:32px;
+}
+#datetime {
+ display:none;
+ position:fixed;
+ left:50px;
+ bottom:50px;
+ width:490px;
+ height:139px;
+ background-color: rgba(17,17,17,1);
+}
+#time {
+ position:absolute;
+ left:70px;
+ bottom:19px;
+ font-family: Segoe UI Light;
+ font-size: 64pt;
+}
+#date {
+ margin-top:20px;
+ margin-right:20px;
+ float:right;
+ font-size:24pt;
+ font-family: Segoe UI;
+ color:#FFFFFF;
+}
+iframe {
+ position:relative;
+ border:none;
+} \ No newline at end of file
diff --git a/games/battleship/index.html b/games/battleship/index.html
new file mode 100644
index 0000000..46d32a8
--- /dev/null
+++ b/games/battleship/index.html
@@ -0,0 +1,401 @@
+<!DOCTYPE html>
+<html>
+<meta http-equiv="x-ua-compatible" content="IE=edge">
+<title>Battleship</title>
+ <link rel="stylesheet" href="common.css"/>
+ <style>
+body {
+ background-color:#2854A0;
+ font-family:Segoe UI;
+ color:#FFFFFF;
+}
+#title {
+ font : normal 48pt Segoe UI Light;
+ padding:20px;
+ display:inline;
+}
+#back {
+ display:inline;
+ margin: 0 30px;
+}
+.intro {
+ font-size:10pt;
+ font-style:italic;
+}
+.heading {
+ font-size:20pt;
+ font-family:Segoe UI Light;
+}
+.title {
+ font-size:18pt;
+ background-color:navy;
+ color:white;
+ text-align:center;
+ font-family:Segoe UI Light;
+}
+table {
+margin-top:60px;
+}
+td {
+padding: 30px 50px 0px 0px;
+}
+</style>
+ <script>
+function charms(){
+ document.getElementById('charmsbar').style.display='block';
+ document.getElementById('datetime').style.display='block';
+}
+function destroycharms() {
+ document.getElementById('charmsbar').style.display='none';
+ document.getElementById('datetime').style.display='none';
+}
+function start(){
+ document.getElementById('startbutton').style.display='block';
+}
+function destroystart() {
+ document.getElementById('startbutton').style.display='none';
+}
+</script>
+
+<script>
+<!-- Begin
+/* Information used to draw the ships
+*/
+var ship = [[[1,5], [1,2,5], [1,2,3,5], [1,2,3,4,5]], [[6,10], [6,7,10], [6,7,8,10], [6,7,8,9,10]]];
+
+/* Information used to draw sunk ships
+*/
+var dead = [[[201,203], [201,202,203], [201,202,202,203], [201,202,202,202,203]], [[204,206], [204,205,206], [204,205,205,206], [204,205,205,205,206]]];
+
+/* Information used to describe ships
+*/
+var shiptypes = [["Minesweeper",2,4],["Frigate",3,4],[ "Cruiser",4,2],[ "Battleship",5,1]];
+
+var gridx = 16, gridy = 16;
+var player = [], computer = [], playersships = [], computersships = [];
+var playerlives = 0, computerlives = 0, playflag=true, statusmsg="";
+
+/* Function to preload all the images, to prevent delays during play
+*/
+var preloaded = [];
+function imagePreload() {
+var i,ids = [1,2,3,4,5,6,7,8,9,10,100,101,102,103,201,202,203,204,205,206];
+window.status = "Preloading images...please wait";
+for (i=0;i<ids.length;++i) {
+var img = new Image, name = "batt"+ids[i]+".gif";
+img.src = name;
+preloaded[i] = img;
+}
+window.status = "";
+}
+
+/* Function to place the ships in the grid
+*/
+function setupPlayer(ispc) {
+var y,x;
+grid = [];
+for (y=0;y<gridx;++y) {
+grid[y] = [];
+for (x=0;x<gridx;++x)
+grid[y][x] = [100,-1,0];
+}
+
+var shipno = 0;
+var s;
+for (s=shiptypes.length-1;s>=0;--s) {
+var i;
+for (i=0;i<shiptypes[s][2];++i) {
+var d = Math.floor(Math.random()*2);
+var len = shiptypes[s][1], lx=gridx, ly=gridy, dx=0, dy=0;
+if ( d==0) {
+lx = gridx-len;
+dx=1;
+}
+else {
+ly = gridy-len;
+dy=1;
+}
+var x,y,ok;
+do {
+y = Math.floor(Math.random()*ly);
+x = Math.floor(Math.random()*lx);
+var j,cx=x,cy=y;
+ok = true;
+for (j=0;j<len;++j) {
+if (grid[cy][cx][0] < 100) {
+ok=false;
+break;
+}
+cx+=dx;
+cy+=dy;
+}
+} while(!ok);
+var j,cx=x,cy=y;
+for (j=0;j<len;++j) {
+grid[cy][cx][0] = ship[d][s][j];
+grid[cy][cx][1] = shipno;
+grid[cy][cx][2] = dead[d][s][j];
+cx+=dx;
+cy+=dy;
+}
+if (ispc) {
+computersships[shipno] = [s,shiptypes[s][1]];
+computerlives++;
+}
+else {
+playersships[shipno] = [s,shiptypes[s][1]];
+playerlives++;
+}
+shipno++;
+}
+}
+return grid;
+}
+
+/* Function to change an image shown on a grid
+*/
+function setImage(y,x,id,ispc) {
+if ( ispc ) {
+computer[y][x][0] = id;
+document.images["pc"+y+"_"+x].src = "batt"+id+".gif";
+}
+else {
+player[y][x][0] = id;
+document.images["ply"+y+"_"+x].src = "batt"+id+".gif";
+}
+}
+
+/* Function to insert HTML source for a grid
+*/
+function showGrid(ispc) {
+var y,x;
+for (y=0;y<gridy;++y) {
+for (x=0;x<gridx;++x) {
+if ( ispc )
+document.write ('<a href="javascript:gridClick('+y+','+x+');"><img name="pc'+y+'_'+x+'" src="batt100.gif" width=16 height=16></a>');
+else
+document.write ('<a href="javascript:void(0);"><img name="ply'+y+'_'+x+'" src="batt'+player[y][x][0]+'.gif" width=16 height=16></a>');
+}
+document.write('<br>');
+}
+}
+
+/* Handler for clicking on the grid
+*/
+function gridClick(y,x) {
+if ( playflag ) {
+if (computer[y][x][0] < 100) {
+setImage(y,x,103,true);
+var shipno = computer[y][x][1];
+if ( --computersships[shipno][1] == 0 ) {
+sinkShip(computer,shipno,true);
+alert("You sank my "+shiptypes[computersships[shipno][0]][0]+"!");
+updateStatus();
+if ( --computerlives == 0 ) {
+alert("You win! Press the Refresh button on\n"+
+"your browser to play another game.");
+playflag = false;
+}
+}
+if ( playflag ) computerMove();
+}
+else if (computer[y][x][0] == 100) {
+setImage(y,x,102,true);
+computerMove();
+}
+}
+}
+
+/* Function to make the computers move. Note that the computer does not cheat, oh no!
+*/
+function computerMove() {
+var x,y,pass;
+var sx,sy;
+var selected = false;
+
+/* Make two passes during 'shoot to kill' mode
+*/
+for (pass=0;pass<2;++pass) {
+for (y=0;y<gridy && !selected;++y) {
+for (x=0;x<gridx && !selected;++x) {
+/* Explosion shown at this position
+*/
+if (player[y][x][0]==103) {
+sx=x; sy=y;
+var nup=(y>0 && player[y-1][x][0]<=100);
+var ndn=(y<gridy-1 && player[y+1][x][0]<=100);
+var nlt=(x>0 && player[y][x-1][0]<=100);
+var nrt=(x<gridx-1 && player[y][x+1][0]<=100);
+if ( pass == 0 ) {
+/* On first pass look for two explosions
+in a row - next shot will be inline
+*/
+var yup=(y>0 && player[y-1][x][0]==103);
+var ydn=(y<gridy-1 && player[y+1][x][0]==103);
+var ylt=(x>0 && player[y][x-1][0]==103);
+var yrt=(x<gridx-1 && player[y][x+1][0]==103);
+if ( nlt && yrt) { sx = x-1; selected=true; }
+else if ( nrt && ylt) { sx = x+1; selected=true; }
+else if ( nup && ydn) { sy = y-1; selected=true; }
+else if ( ndn && yup) { sy = y+1; selected=true; }
+}
+else {
+/* Second pass look for single explosion -
+fire shots all around it
+*/
+if ( nlt ) { sx=x-1; selected=true; }
+else if ( nrt ) { sx=x+1; selected=true; }
+else if ( nup ) { sy=y-1; selected=true; }
+else if ( ndn ) { sy=y+1; selected=true; }
+}
+}
+}
+}
+}
+if ( !selected ) {
+/* Nothing found in 'shoot to kill' mode, so we're just taking
+potshots. Random shots are in a chequerboard pattern for
+maximum efficiency, and never twice in the same place
+*/
+do{
+sy = Math.floor(Math.random() * gridy);
+sx = Math.floor(Math.random() * gridx/2)*2+sy%2;
+} while( player[sy][sx][0]>100 );
+}
+if (player[sy][sx][0] < 100) {
+/* Hit something
+*/
+setImage(sy,sx,103,false);
+var shipno = player[sy][sx][1];
+if ( --playersships[shipno][1] == 0 ) {
+sinkShip(player,shipno,false);
+alert("I sank your "+shiptypes[playersships[shipno][0]][0]+"!");
+if ( --playerlives == 0 ) {
+knowYourEnemy();
+alert("I win! Press the Refresh button on\n"+
+"your browser to play another game.");
+playflag = false;
+}
+}
+}
+else {
+/* Missed
+*/
+setImage(sy,sx,102,false);
+}
+}
+
+/* When whole ship is hit, show it using changed graphics
+*/
+function sinkShip(grid,shipno,ispc) {
+var y,x;
+for (y=0;y<gridx;++y) {
+for (x=0;x<gridx;++x) {
+if ( grid[y][x][1] == shipno )
+if (ispc) setImage(y,x,computer[y][x][2],true);
+else setImage(y,x,player[y][x][2],false);
+}
+}
+}
+
+/* Show location of all the computers ships - when player has lost
+*/
+function knowYourEnemy() {
+var y,x;
+for (y=0;y<gridx;++y) {
+for (x=0;x<gridx;++x) {
+if ( computer[y][x][0] == 103 )
+setImage(y,x,computer[y][x][2],true);
+else if ( computer[y][x][0] < 100 )
+setImage(y,x,computer[y][x][0],true);
+}
+}
+}
+
+/* Show how many ships computer has left
+*/
+function updateStatus() {
+var f=false,i,s = "Computer has ";
+for (i=0;i<computersships.length;++i) {
+if (computersships[i][1] > 0) {
+if (f) s=s+", "; else f=true;
+s = s + shiptypes[computersships[i][0]][0];
+}
+}
+if (!f) s = s + "nothing left, thanks to you!";
+statusmsg = s;
+window.status = statusmsg;
+}
+function setStatus() {
+window.status = statusmsg;
+}
+/* Start the game!
+*/
+imagePreload();
+player = setupPlayer(false);
+computer = setupPlayer(true);
+document.write("<div align='center'><table><tr><td align='center'><span class='heading'>COMPUTER'S FLEET</span></td>"+
+"<td align='center'><span class='heading'>PLAYER'S FLEET</span></td></tr><tr><td>");
+showGrid(true);
+document.write("</td><td>");
+showGrid(false);
+document.write("</td></tr></table></div>");
+updateStatus();
+setInterval("setStatus();", 500);
+// End -->
+</script>
+
+<div id="splashscreen"></div>
+<div id="hoverarea" onmouseover="charms()" class="hotcorner">
+</div>
+<div id="charmsbar" onmouseover="charms()" onmouseout="destroycharms()">
+<img src="../../common/img/charmsbar/search.png" onmouseover="this.src='../../common/img/charmsbar/search-hover.png'" onmouseout="this.src='../../common/img/charmsbar/search.png'"/><br/>
+<img src="../../common/img/charmsbar/share.png" onmouseover="this.src='../../common/img/charmsbar/share-hover.png'" onmouseout="this.src='../../common/img/charmsbar/share.png'"/><br/>
+<a href="../../start/index.html"><img src="../../common/img/charmsbar/start.png" onmouseover="this.src='../../common/img/charmsbar/start-hover.png'" onmouseout="this.src='../../common/img/charmsbar/start.png'"/></a><br/>
+<img src="../../common/img/charmsbar/devices.png" onmouseover="this.src='../../common/img/charmsbar/devices-hover.png'" onmouseout="this.src='../../common/img/charmsbar/devices.png'"/><br/>
+<img src="../../common/img/charmsbar/settings.png" onmouseover="this.src='../../common/img/charmsbar/settings-hover.png'" onmouseout="this.src='../../common/img/charmsbar/settings.png'" onclick="settingsc()"/><br/>
+</div>
+<div id="datetime">
+<img src="../../common/img/network.png" id="iconnetwork" height="24px" width="24px"/>
+<img src="../../common/img/battery.png" id="iconbattery"/>
+<span id="time"></span>
+<script language="javascript" type="text/javascript">
+<!-- Begin
+function clock() {
+var digital = new Date();
+var hours = digital.getHours();
+var minutes = digital.getMinutes();
+var seconds = digital.getSeconds();
+var amOrPm = "AM";
+if (hours > 11) amOrPm = "PM";
+if (hours > 12) hours = hours - 12;
+if (hours == 0) hours = 12;
+if (minutes <= 9) minutes = "0" + minutes;
+if (seconds <= 9) seconds = "0" + seconds;
+dispTime = hours + ":" + minutes ;
+document.getElementById('time').innerHTML = dispTime;
+setTimeout("clock()", 1000);
+}
+window.onload=clock;
+// End -->
+</script>
+<div id="date"><script language="Javascript">
+
+ var dayName = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
+
+ var monName = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
+
+ var now = new Date
+
+ document.write("" + dayName[now.getDay()] + "<br/>" +"<span id=month>" + monName[now.getMonth()] + " "+now.getDate() +"")
+ </script>
+</div>
+</div>
+<div id="bottomhoverarea" onmouseover="charms()" class="hotcorner">
+</div>
+<div id="starthoverarea" onmouseover="start()" class="hotcorner">
+</div>
+<div id="startbutton" onmouseout="destroystart()">
+<a href="../../start/index.html"><img src="../../common/img/start.png"/></a>
+</div>
+</html> \ No newline at end of file
diff --git a/games/battleship/splashscreen.png b/games/battleship/splashscreen.png
new file mode 100644
index 0000000..6cd3608
--- /dev/null
+++ b/games/battleship/splashscreen.png
Binary files differ