1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
| <!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Игра "Собери кристаллы"</title>
<style>
html, body {height: 100%; margin: 0; padding: 0; overflow: hidden; background-color: #fff}
td {font-weight: 900; font-size: 16px; font-family: monospace; text-align: right; color: #aaa}
div {position: relative; border: 2px solid #aaa; background-color: #fafafa}
img {position: absolute}
</style>
<script>
onload = function ()
{
var tbl = document.createElement ('TABLE');
tbl.cellSpacing = tbl.cellPadding = 0; tbl.align = 'center';
tbl.style.marginTop = tbl.style.marginBottom = '10px';
var ro = tbl.insertRow (-1),
ce = ro.insertCell (-1); ce.appendChild (document.createTextNode ('Выпало кристаллов:'));
ce = ro.insertCell (-1); ce.style.width = '4ex'; ce.appendChild (document.createTextNode (0));
ce = ro.insertCell (-1); ce.rowSpan = 2; ce.innerHTML = ' ';
ce = ro.insertCell (-1); ce.rowSpan = 2; ce.appendChild (document.createTextNode ('01:00'));
with (ce.style) color = '#fff', padding = '0 5px', fontSize = '28px', backgroundColor = '#aaa';
ro = tbl.insertRow (-1);
ce = ro.insertCell (-1); ce.appendChild (document.createTextNode ('Собрано кристаллов:'));
ce = ro.insertCell (-1); ce.style.width = '4ex'; ce.appendChild (document.createTextNode (0));
MyTable = document.body.appendChild (tbl);
var th = MyTable.offsetHeight + 20,
bw = document.body.clientWidth - th * 2,
bh = document.body.clientHeight - th * 2;
with (MyTable.rows [0])
cells [2].style.width = (bw - cells [0].offsetWidth - cells [1].offsetWidth - cells [3].offsetWidth) + 'px';
var dv = document.createElement ('DIV');
with (dv.style) width = (bw - 4) + 'px', height = bh + 'px', marginLeft = th + 'px';
GameZone = document.body.appendChild (dv);
alert ('Начать игру.');
var im1 = document.createElement ('IMG');
with (im1.style) width = height = '20px', backgroundColor = '#888';
Picker = GameZone.appendChild (im1);
var im2 = document.createElement ('IMG');
with (im2.style) width = height = '25px', backgroundColor = 'gold';
with (im2.style) zIndex = 4, visibility = 'hidden';
Crystal = GameZone.appendChild (im2);
document.body.onkeydown = function (ev)
{
var e = window.event || ev, k = e.keyCode;
if (k == 37) delLeft = -Speed;
else if (k == 38) delUp = -Speed;
else if (k == 39) delRight = Speed;
else if (k == 40) delBottom = Speed;
}
document.body.onkeyup = function (ev)
{
var e = window.event || ev, k = e.keyCode;
if (k == 37) delLeft = 0;
else if (k == 38) delUp = 0;
else if (k == 39) delRight = 0;
else if (k == 40) delBottom = 0;
}
BRS = (navigator.userAgent.indexOf ('MSIE') >= 0);
F_Start ();
}
function F_Start ()
{
LeftPicker = F_Rand (0, parseInt (GameZone.style.width ) - Picker.offsetWidth ),
TopPicker = F_Rand (0, parseInt (GameZone.style.height) - Picker.offsetHeight);
with (Picker.style) left = LeftPicker + 'px', top = TopPicker + 'px', zIndex = 5;
Speed = 5, MyTimeOut = 20, Eff = 1,
delLeft = delUp = delRight = delBottom = PartOfSecond = 0;
F_Process ();
}
function F_Rand (mi, ma) {return parseInt ((ma - mi) * Math.random () + mi)}
function F_Process ()
{
if (self.TMR) clearTimeout (TMR);
var ad0 = function (x) {return (((x < 10) ? '0' : '') + x)}
PartOfSecond += MyTimeOut;
if (PartOfSecond == 1000)
{
PartOfSecond = 0;
var tx = MyTable.rows [0].cells [3].innerHTML.split (':'),
tm = parseInt (tx [0] * 60, 10) + parseInt (tx [1], 10) - 1;
MyTable.rows [0].cells [3].innerHTML = '0' + Math.floor (tm / 60) + ':' + ad0 (tm % 60);
if (!tm)
{
var proc = Math.floor (MyTable.rows [1].cells [1].innerHTML / MyTable.rows [0].cells [1].innerHTML * 100);
if (confirm ('Вы собрали ' + proc + '% выпавших кристаллов.\n\nЖелаете сыграть ещё раз?'))
{
MyTable.rows [1].cells [1].innerHTML = MyTable.rows [0].cells [1].innerHTML = 0;
MyTable.rows [0].cells [3].innerHTML = '01:00';
Crystal.style.visibility = 'hidden';
F_Start ();
}
return;
}
}
var wC = Crystal.offsetWidth, hC = Crystal.offsetHeight,
wP = Picker.offsetWidth , hP = Picker.offsetHeight,
wGZ = parseInt (GameZone.style.width),
hGZ = parseInt (GameZone.style.height),
lMax = wGZ - wP,
tMax = hGZ - hP;
LeftPicker += delLeft + delRight ,
TopPicker += delUp + delBottom;
if (LeftPicker < 0) LeftPicker = 0; if (LeftPicker > lMax) LeftPicker = lMax;
if (TopPicker < 0) TopPicker = 0; if (TopPicker > tMax) TopPicker = tMax;
with (Picker.style) left = LeftPicker + 'px', top = TopPicker + 'px';
if (Eff) --Eff; if (!Eff) MyTable.style.backgroundColor = '#fff';
if (Crystal.style.visibility == 'hidden')
{
var lMin = LeftPicker - 3 * Picker.offsetWidth; if (lMin < 0 ) lMin = 0;
var lMax = LeftPicker + 4 * Picker.offsetWidth; if (lMax > wGZ) lMin = wGZ;
var tMin = TopPicker - 3 * Picker.offsetHeight; if (tMin < 0 ) tMin = 0;
var tMax = TopPicker + 4 * Picker.offsetHeight; if (tMax > hGZ) tMax = hGZ;
do {
LeftCrystal = F_Rand (0, parseInt (GameZone.style.width ) - Crystal.offsetWidth ),
TopCrystal = F_Rand (0, parseInt (GameZone.style.height) - Crystal.offsetHeight);
}
while ((LeftCrystal >= lMin && LeftCrystal <= lMax && TopCrystal >= tMin && TopCrystal <= tMax)
|| (LeftCrystal + wC >= lMin && LeftCrystal + wC <= lMax && TopCrystal >= tMin && TopCrystal <= tMax)
|| (LeftCrystal + wC >= lMin && LeftCrystal + wC <= lMax && TopCrystal + hC >= tMin && TopCrystal + hC <= tMax)
|| (LeftCrystal >= lMin && LeftCrystal <= lMax && TopCrystal + hC >= tMin && TopCrystal + hC <= tMax));
with (Crystal.style) visibility = 'visible', left = LeftCrystal + 'px', top = TopCrystal + 'px';
MyTable.rows [0].cells [1].innerHTML = parseInt (MyTable.rows [0].cells [1].innerHTML) + 1;
var dL = LeftPicker - LeftCrystal, dT = TopPicker - TopCrystal;
TimeCrystalCurrent = TimeCrystalMax = parseInt (Math.sqrt (dL * dL + dT * dT) * 1.5 / Speed);
}
else
{
var op = parseInt (--TimeCrystalCurrent / TimeCrystalMax * 100);
if (BRS) Crystal.style.filter = 'alpha(opacity=' + op + ')'; else Crystal.style.opacity = .01 * op;
if (op <= 10) Crystal.style.visibility = 'hidden';
else if ((LeftPicker > LeftCrystal && LeftPicker < LeftCrystal + wC && TopPicker > TopCrystal && TopPicker < TopCrystal + hC)
|| (LeftPicker + wP > LeftCrystal && LeftPicker + wP < LeftCrystal + wC && TopPicker > TopCrystal && TopPicker < TopCrystal + hC)
|| (LeftPicker + wP > LeftCrystal && LeftPicker + wP < LeftCrystal + wC && TopPicker + hP > TopCrystal && TopPicker + hP < TopCrystal + hC)
|| (LeftPicker > LeftCrystal && LeftPicker < LeftCrystal + wC && TopPicker + hP > TopCrystal && TopPicker + hP < TopCrystal + hC))
{
Crystal.style.visibility = 'hidden';
MyTable.style.backgroundColor = 'gold'; Eff = 10;
MyTable.rows [1].cells [1].innerHTML = parseInt (MyTable.rows [1].cells [1].innerHTML) + 1;
}
}
TMR = setTimeout (F_Process, MyTimeOut);
}
</script>
</head>
<body></body>
</html> |