<style>
.miner td {
width : 16px;
height : 16px;
text-align : center;
padding : 0;
border-collapse : collapse;
font-family : arial;
}
</style>
<center>
<a href="?">[ Restart ]</a>
<table class="miner" cellspacing="0">
<script language='javascript'>
mines_c=32, miner_w=16, miner_h=16, miner_gameOver=false, miner_u=Array(), miner_p=Array();
for(y=0, a=0; y<miner_h; y++) {
document.write("<tr>");
for(x=0; x<miner_w; x++, a++) {
document.write('<td oncontextmenu="miner_click('+x+','+y+',1);return false"'
+' onclick="miner_click('+x+','+y+',0)"><img id="c'+a+'" src="-2.png"/></td>');
miner_u[a] = 0;
miner_p[a] = -2;
}
document.write("</tr>");
}
for(i=0; i<mines_c; i++)
miner_p[Math.floor(Math.random()*miner_w*miner_h)] = -1;
function miner_e(x,y) {
return x>=0 && y>=0 && x<miner_w && y<miner_h && miner_p[x+y*miner_w]==-1 ? 1 : 0;
}
function miner_8(f,x,y) {
return f(x-1,y-1)+f(x,y-1)+f(x+1,y-1)+f(x-1,y)+f(x+1,y)+f(x-1,y+1)+f(x,y+1)+f(x+1,y+1);
}
function miner_open(x,y) {
if(x<0 || y<0 || x>=miner_w || y>=miner_h) return;
if(miner_p[a=x+y*miner_w]==-1) miner_gameOver=true;
if(miner_p[a]==-2 && (miner_p[a]=miner_8(miner_e,x,y))==0) miner_8(miner_open,x,y);
}
function miner_click(x,y,e) {
if(miner_gameOver) return;
if(e) a=x+y*miner_w, miner_u[a]=(miner_u[a]+1)%3;
else miner_open(x,y);
for(a=0; a<miner_w*miner_h; a++) {
m = miner_p[a];
if(!miner_gameOver && m==-1) m=-2;
if(m==-2) m-=miner_u[a];
document.getElementById("c"+a).src = m+".png";
}
if(miner_gameOver) alert("Game Over!");
}
// (c) Aleksey Morozov, VinxRu, Aleksey.F.Morozov@gmail.com
</script>
</table>
<a href="http://vinxru.livejournal.com/32513.html">Leave a comment</a>
</center>