Сообщение от nub
|
только будит ли работать если им движение задать?
|
на 10 спрятавшемся в кролчатнике игра заканчивается
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<style type="text/css">
body{
background: url(http://learn.javascript.ru/files/play/52/8a/528a0db7e024b.jpg) #008000;
color: #FFFFFF;
font-size: x-large;
}
</style>
</head>
<body>
<div id="ok">0</div> <div id="cl">0</div>
<input type="radio" name="boom" value="30" id="boom30" checked="checked" ><label for="boom30">30</label>
<input type="radio" name="boom" value="100" id="boom100"><label for="boom100">100</label>
<input type="radio" name="boom" value="200" id="boom200"><label for="boom200">200</label>
<script>
var p = document.createElement("div");
p.style.width = "100px";
p.style.zIndex = -1E3;
p.style.height = "79px";
p.style.backgroundImage = "url('http://learn.javascript.ru/files/play/52/8a/528a0db7774f9.gif')";
p.style.position = "absolute";
p.style.top = "155px";
p.style.left = "365px";
document.body.appendChild(p);
var random = function (b) {
return Math.ceil(Math.random() * b)
}, rabbitsArray = [],
win = 0,
cln = 0,
timer;
function unit() {
if (-10 >= cln) return !1;
for (var b = rabbitsArray.length; 10 > b; b++) {
rabbitsArray[b] = [random(400), random(800)];
var e = rabbitsArray[b];
e.start = (new Date).getTime();
e.duration = 5E3 + random(2E4);
e.bunny = document.createElement("div");
var a = e.bunny;
a.style.width = "30px";
a.style.height = "30px";
a.style.backgroundImage = "url('http://learn.javascript.ru/files/play/52/8a/528a0db80b9f9.gif')";
a.style.backgroundPosition = "center center";
a.style.backgroundRepeat = "no-repeat";
a.style.position = "absolute";
a.style.top = e[0] + "px";
a.style.left = e[1] + "px";
document.body.appendChild(a)
}
move()
}
unit();
function move() {
function b(a) {
if (0.3 > a) return 49.4 * Math.pow(a, 4);
if (0.4 > a) return 9 * a - 2.3;
if (0.5 > a) return -13 * a + 6.5;
if (0.6 > a) return 4 * a - 2;
if (0.7 > a) return 0.4;
if (0.75 > a) return 4 * a - 2.4;
if (0.8 > a) return -4 * a + 3.6;
if (0.8 <= a) return 1 - Math.sin(Math.acos(a))
}
if (-10 == cln) return !1;
window.clearTimeout(timer);
for (var e = 0; rabbitsArray.length > e; e++) {
var a = [200, 400],
c = rabbitsArray[e],
d = c.bunny,
f = ((new Date).getTime() - c.start) / c.duration,
g = (a[0] - c[0]) * b(f) + c[0];
d.style.top = g + "px";
g = (a[1] - c[1]) * f + c[1];
d.style.left = g + "px";
1 < f && (document.getElementById("cl").innerHTML = --cln, d.style.border = "#FFFF00 1px solid", d.style.top = a[0] + "px", d.style.left = a[1] + "px", d = rabbitsArray.splice(c, 1), window.setTimeout(function (a) {
return function () {
document.body.removeChild(a)
}
}(d[0].bunny), 1E3))
} - 10 < cln ? timer = window.setTimeout(move, 50) : alert("end")
}
function bum(b) {
for (var e = document.querySelector(":checked").value, a = rabbitsArray.length - 1, c; c = rabbitsArray[a]; a--) {
var d = parseInt(c.bunny.style.top, 10),
f = parseInt(c.bunny.style.left, 10),
d = Math.pow(d - (b[0] - 15), 2) + Math.pow(f - (b[1] - 15), 2),
d = Math.sqrt(d);
e > d && (win++, document.getElementById("ok").innerHTML = win, c.bunny.style.border = "#FF0000 1px solid", c = rabbitsArray.splice(a, 1), window.setTimeout(function (a) {
return function () {
document.body.removeChild(a)
}
}(c[0].bunny), 500))
}
window.setTimeout(unit, 1E3)
}
document.onclick = function (b) {
if (-10 >= cln) return !1;
b = b || event;
bum([b.clientY, b.clientX])
};
</script>
</body>
</html>