Пятнашки )))
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1251" />
<title>15</title>
<style type="text/css">
td{
height: 40px; width: 40px; text-align: center; color: #FFFFF0; font-weight: bold; font-size: large;
}
</style>
</head>
<body>
<script language="JavaScript" type="text/javascript">
for (var m = [], l = 4, k = 1, z = [l - 1, l - 1], // l--размер поля
b = ["background-color: #4169E1;", "background-color: #C0C0C0;color: #C0C0C0;"],
t = document.createElement("table"), c = 0; c < l; c++) {
var tr = t.insertRow(c);
m[c] = [];
for (var s = 0; s < l; s++) {
var td = tr.insertCell(s);
td.style.cssText = b[0];
td.onclick = function (a, e) {
return function () {
cl_go(a, e)
}
}(c, s);
m[c][s] = k;
td.innerHTML = k++
}
}
t.rows[l - 1].cells[l - 1].style.cssText = b[1];
t.rows[l - 1].cells[l - 1].innerHTML='';
m[l - 1][l - 1] = 0;
document.body.appendChild(t);
var end = m.toString().split(",").join(""),
v = l * l * 2;
function go() {
for (var a = [
[-1, 0],
[0, -1],
[1, 0],
[0, 1]
]; a.length;) {
var e = Math.floor(Math.random() * a.length),
d = a[e];
a.splice(e, 1);
if (m[z[0] + d[0]] && m[z[0] + d[0]][z[1] + d[1]]) break
}
m[z[0]][z[1]] = m[z[0] + d[0]][z[1] + d[1]];
t.rows[z[0]].cells[z[1]].style.cssText = b[0];
t.rows[z[0]].cells[z[1]].innerHTML = m[z[0]][z[1]];
t.rows[z[0] + d[0]].cells[z[1] + d[1]].style.cssText = b[1];
t.rows[z[0] + d[0]].cells[z[1] + d[1]].innerHTML = '';
m[z[0] + d[0]][z[1] + d[1]] = 0;
z = [z[0] + d[0], z[1] + d[1]];
if (m[l - 1][l - 1] || v > 0) {
v--;
setTimeout(arguments.callee, 100)
} else {
alert("Please play!!!");
v = l * l * 2
}
}
function cl_go(a, e) {
for (var d = [
[-1, 0],
[0, -1],
[1, 0],
[0, 1]
]; d.length;) {
var g = Math.floor(Math.random() * d.length),
f = d[g];
d.splice(g, 1);
if (m[a + f[0]] && m[a + f[0]][e + f[1]] == 0) {
m[a + f[0]][e + f[1]] = m[a][e];
m[a][e] = 0;
t.rows[a].cells[e].style.cssText = b[1];
t.rows[a].cells[e].innerHTML = '';
t.rows[a + f[0]].cells[e + f[1]].style.cssText = b[0];
t.rows[a + f[0]].cells[e + f[1]].innerHTML = m[a + f[0]][e + f[1]];
z = [a, e];
break
}
}
end == m.toString().split(",").join("") && alert("Game over")
};
</script>
<input type="button" name="" value="Mix" onclick="go()"/>
</body>
</html>