Форум программистов, компьютерный форум, киберфорум
JavaScript
Войти
Регистрация
Восстановить пароль
 
Рейтинг 4.63/52: Рейтинг темы: голосов - 52, средняя оценка - 4.63
sweetboy
1

Исходник сапера на javascript

20.05.2006, 15:02. Показов 9508. Ответов 3
Метки нет (Все метки)

Помогите пожалуйста найти исходник игры сапер на javascript. Очень нужно.
Заранее благодарю
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
20.05.2006, 15:02
Ответы с готовыми решениями:

Нужен исходник сапера
Мне нужен исходник сапера на Visual Basic .net. Весь Google периискал подходящего исходники не...

Нужен исходник для расчёта комплектации материалов или т.п. Исходник с расчётами, таблицами
Добрый день всем) Нужна помощь. Занимаюсь расчётами стоимость материалов и стоимость в оконной...

Создание многопользовательского сапера
Здравствуйте, уважаемые форумчане. Извините заранее за возможное нубство с моей стороны :). Дело...

Написать сапера на чистом си
//функция рисующая поле { for (int y = 0; y < size; y++){ for (int x = 0; x < size;...

3
Куплю статус. Не б/у.
36 / 26 / 1
Регистрация: 26.08.2008
Сообщений: 339
26.08.2008, 11:43 2
На javascript:

Javascript
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
<SCRIPT LANGUAGE="JavaScript">
 
<!-- Begin
dir = "";
var mines = [];
var shown = [];
var gridx, gridy, maxmines;
gridx = window.prompt("Введите ширину поля.","8");
gridxverify();
function gridxaccept(){
gridy = window.prompt("Введите высоту поля.","8");
gridyverify();
}
function gridyaccept(){
maxmines = window.prompt("Определите желаемое количество мин.","10");
maxminesverify();
}
function gridxverify(){
if (gridx > 50){
alert("Эта ширина слишком велика. Введите, пожалуйста, другую цифру.");
gridxreenter();
}
else if (gridx < 8){
alert("Эта ширина слишком мала. Введите, пожалуйста, другую цифру.");
gridxreenter();
}
else gridxaccept();
}
function gridyverify(){
if (gridy > 50){
alert("Эта высота слишком велика. Введите, пожалуйста, другую цифру.");
gridyreenter();
}
else if (gridy < 8){
alert("Эта высота слишком мала. Введите, пожалуйста, другую цифру.");
gridyreenter();
}
else gridyaccept();
}
function maxminesverify(){
if (maxmines > 500){
alert("Такое количество слишком велико. Введите, пожалуйста, другую цифру.");
maxminesreenter();
}
else if (maxmines < 10){
alert("Такое количество слишком мало. Введите, пожалуйста, другую цифру.");
maxminesreenter();
}
else accepted();
}
// Functions for reentering key variables, if necessary.
function gridxreenter(){
gridx = window.prompt("Пожалуйста, задайте ширину.","8");
gridxverify();
}
function gridyreenter(){
gridy = window.prompt("Пожалуйста, задайте высоту.","8");
gridyverify();
}
function maxminesreenter(){
maxmines = window.prompt("Задайте количество мин.","10");
maxminesverify();
}
function accepted(){
var squaresleft, flagsleft;
var elapsedtime;
var playing;
var placeflag;
var clicked;
}
var gridSq = gridx * 16;
var grid8 = gridSq - 128;
var grid16 = gridx - 8
var grid32 = grid16 * 8
var grid64 = grid16 * 16
var topBarWidth = 8 + grid64;
var menuBarWidth = 86 + grid64;
var wideWidth = gridx * 16;
var highHeight = gridy * 16;
var cplLeft = 6 + grid32;
var cplRight = 4 + grid32;
var totalWidth = gridSq + 32;
var tW6 = totalWidth - 6;
var ww2 = wideWidth + 2;
num=new Array(10);
for (var i=0;i<10;i++) {
num[i]=new Image()
num[i].src=i+"SW.gif"
}
function keyDown(e) {
if(document.layers)
placeflag = (e.modifiers & Event.CONTROL_MASK) > 0;
else
placeflag = window.event.ctrlKey;
setStatus();
}
function keyUp(e) {
placeflag = false;
setStatus();
}
function newgame() {
// reset state arrays. mines holds the position of each mine. shown keeps
// track of the image shown at each grid location
var y;
for(y = 0; y < gridy; ++y)
{
mines[y] = [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false];
shown[y] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
// Place the mines, making sure positions are unique
var m;
for(m = 0; m < maxmines; ++m) {
var x,y;
do {
x = Math.floor(Math.random() * gridx);
y = Math.floor(Math.random() * gridy);
} while(mines[y][x]);
mines[y][x] = true;
}
// initialize game variables
squaresleft = gridy * gridx;
flagsleft = maxmines;
elapsedtime = 0;
playing = true;
clicked = false
placeflag = false;
// insert the grid into the document
buildgrid();
// Set up keypress handlers
if (document.layers)
window.captureEvents(Event.KEYDOWN | Event.KEYUP);
window.onKeyDown = keyDown;
window.onKeyUp = keyUp;
// start the clock
setInterval("ticker()", 1000);
}
// clock tick handler
function ticker() {
if (playing) {
if (clicked) {
elapsedtime++;
setStatus();
}
}
}
// Refreshing control panel
function setStatus() {
document.images.elapse3.src= num[elapsedtime-(Math.floor(elapsedtime/10))*10].src;
document.images.elapse2.src= num[Math.floor((elapsedtime-(Math. floor(elapsedtime/100))*100)/10)].src;
document.images.elapse1.src=num[Math. floor(elapsedtime/100)].src;
document.images.flag3.src=num[flagsleft-(Math. floor(flagsleft/10))*10].src;
document.images.flag2.src= num[Math.floor((flagsleft-(Math. floor(flagsleft/100))*100)/10)].src;
document.images.flag1.src=num[Math. floor(flagsleft/100)].src;
}
//function to insert all the IMG tags into the document
function buildgrid() {
document.write("<!-- Window --><DIV align=center> "
+"<!-- Top Bar --> <table width="
+ totalWidth
+" border=0 cells"
+"pacing=0 cellpadding=0> <tr bgcolor=#bbbbbb heigh"
+"t=1> <td width=1 bgcolor=#bbbbbb></td><td width"
+"=1 bgcolor=#bbbbbb></td> <td width=1 bgcolor=#bbb"
+"bbb></td><td width="
+ tW6
+" bgcolor=#bbbbbb></td> <t"
+"d width=1 bgcolor=#bbbbbb></td> <td width=1 bgcol"
+"or=#bbbbbb></td> <td width=1 bgcolor=#000000></td"
+"></tr><tr height=1><td width=1 bgcolor=#bbbb"
+"bb></td><td width=1 bgcolor=#ffffff></td><td w"
+"idth=1 bgcolor=#ffffff></td><td bgcolor=#ffffff>"
+"</td><td width=1 bgcolor=#ffffff></td><td widt"
+"h=1 bgcolor=#888888></td><td width=1 bgcolor=#00"
+"0000></td></tr><tr height=1><td width=1 bgco"
+"lor=#bbbbbb></td><td width=1 bgcolor=#ffffff></t"
+"d><td width=1 bgcolor=#bbbbbb></td><td bgcolor"
+"=#bbbbbb></td><td width=1 bgcolor=#bbbbbb></td> "
+"<td width=1 bgcolor=#888888></td><td width=1 bg"
+"color=#000000></td></tr></table><!-- Title -->"
+"<table border=0 cellspacing=0 cellpadding=0><t"
+"r height=18><td width=1 bgcolor=#bbbbbb></td><"
+"td width=1 bgcolor=#ffffff></td><td width=1 bgco"
+"lor=#bbbbbb></td><td bgcolor=#000088><img src='t"
+"itle.gif'><img src='a.gif' height=1 width="
+ topBarWidth
+" name="
+"'titleBarEmptySpace'></td><td><img src='buttons."
+"gif'></td><td width=1 bgcolor=#bbbbbb></td><td"
+" width=1 bgcolor=#888888></td><td width=1 bgcolo"
+"r=#000000></td></tr></table><!-- Menu Bar --> "
+"<table border=0 cellspacing=0 cellpadding=0> <tr"
+" height=20 bgcolor=#bbbbbb> <td width=1 bgcolor=#"
+"bbbbbb></td> <td><img src='menu.gif'></td><td> <"
+"img src='a.gif' height=1 width="
+ menuBarWidth
+" name='menuBarEmp"
+"tySpace'></td> <td width=1 bgcolor=#bbbbbb></td> "
+"<td width=1 bgcolor=#888888></td> <td width=1 bg"
+"color=#000000></td> </tr></table> <!-- Mine Fiel"
+"d --> <table border=0 cellspacing=0 cellpadding=0"
+"> <tr height=11 width=160> <td width=1 bgcolor=#"
+"bbbbbb></td> <td width=1 bgcolor=#ffffff></td> <"
+"td width=1 bgcolor=#bbbbbb></td> <td><img src='tl"
+".gif'></td> <td><img src='header.gif' width="
+ ww2
+" height=11></td> <td><img src='tr.gif'></td><td><"
+"img src='right.gif' width=5 height=11></td> </tr>"
+"</table><table width="
+ totalWidth
+" border=0 cellspacing=0 cellpadd"
+"ing=0> <tr height=33> <td width=1 bgcolor=#bbbbb"
+"b></td> <td width=1 bgcolor=#ffffff></td> <td wi"
+"dth=1 bgcolor=#bbbbbb></td> <td><img src='cplleft"
+".gif' height=33 width=11></td> <td> <!-- Control"
+" Panel --> <table width="
+ ww2
+" border=0 cellspacing="
+"0 cellpadding=0><tr height=4 width="
+ ww2
+"><td bgcolor=#bbbbbb"
+"></td></tr></table> <table width="
+ ww2
+" border=0 cel"
+"lspacing=0 cellpadding=0><tr height=26><td "
+"width=5 bgcolor=#bbbbbb></td><td><!-- Mines Remai"
+"ning --> <table width=41 border=0 cellspacing=0 c"
+"ellpadding=0><tr bgcolor=#888888><td></td><td>"
+"</td><td></td> <td></td><td></td><td></td> <td><"
+"/td><td></td> <td width=1 bgcolor=#bbbbbb></td></"
+"tr> <tr bgcolor=#000000> <td width=1 bgcolor=#88"
+"8888></td> <td></td><td></td> <td></td><td></td>"
+"<td></td><td></td><td></td> <td width=1 bgcolor"
+"=#ffffff></td></tr> <tr bgcolor=#000000> <td wid"
+"th=1 bgcolor=#888888></td> <td width=1 bgcolor=#0"
+"00000></td> <td><img src='0SW.gif' name='flag1'></t"
+"d><td width=2></td><td><img src='1SW.gif' name='"
+"flag2'></td><td width=2></td><td><img src='0SW.g"
+"if' name='flag3'></td><td width=1></td> <td wid"
+"th=1 bgcolor=#ffffff></td></tr> <tr bgcolor=#0000"
+"00> <td width=1 bgcolor=#888888></td> <td></td><"
+"td></td> <td></td><td></td><td></td> <td></td><t"
+"d></td> <td width=1 bgcolor=#ffffff></td></tr> <"
+"tr bgcolor=#ffffff> <td width=1 bgcolor=#bbbbbb><"
+"/td> <td></td><td></td> <td></td><td></td><td></"
+"td> <td></td><td></td> <td></td></tr><"
+"tr bgcolor=#bbbbbb> <td width=1 bgcolor=#bbbbbb><"
+"/td> <td></td><td></td> <td></td><td></td><td></"
+"td> <td></td><td></td> <td></td></tr></table><!--"
+" End Mines Remaini"
+"ng --> </td> <td bgcolor=#bbbbbb><img height=1 "
+"src='a.gif' width=" + cplLeft + "name='cplLeft'>"
+"<td><img src='btnsmile.gif' name='condition' onmo"
+"usedown='document.images.condition.s"
+'rc="btnsmil2.gif"'
+";' onmouseu"
+"p='document.images.condition.s"
+'rc="btnsmile.gif";location.reload();'
+";'></td> <td width=4 bgcolor=#bbbbbb>"
+"<img height=1 src='a.gif'"
+" width=" + cplRight + ">"
+"</td> <td> <!-- Elapsed Time --> <table width=4"
+"1 border=0 cellspacing=0 cellpadding=0> <tr bgcol"
+"or=#888888> <td></td><td></td><td></td> <td></td"
+"><td></td><td></td><td></td><td></td> <td width"
+"=1 bgcolor=#bbbbbb></td></tr> <tr bgcolor=#000000"
+"> <td width=1 bgcolor=#888888></td> <td></td><td"
+"></td> <td></td><td></td><td></td> <td></td><td>"
+"</td> <td width=1 bgcolor=#ffffff></td></tr> <tr"
+" bgcolor=#000000> <td width=1 bgcolor=#888888></t"
+"d> <td width=1 bgcolor=#000000></td> <td><img sr"
+"c='0SW.gif' name='elapse1'></td> <td width=2></td> "
+"<td><img src='0SW.gif' name='elapse2'></td> <td wi"
+"dth=2></td> <td><img src='0SW.gif' name='elapse3'><"
+"/td> <td width=1></td> <td width=1 bgcolor=#ffff"
+"ff></td></tr> <tr bgcolor=#000000> <td width=1 b"
+"gcolor=#888888></td> <td></td><td></td> <td></td"
+"><td></td><td></td> <td></td><td></td> <td width"
+"=1 bgcolor=#ffffff></td></tr> <tr bgcolor=#ffffff"
+"> <td width=1 bgcolor=#bbbbbb></td> <td></td><td"
+"></td> <td></td><td></td><td></td> <td></td><td>"
+"</td> <td></td></tr> <"
+"tr bgcolor=#bbbbbb> <td width=1 bgcolor=#bbbbbb><"
+"/td> <td></td><td></td> <td></td><td></td><td></"
+"td> <td></td><td></td> <td></td></tr> "
+"</table> <!-- End Elapsed Time --> </td> <td "
+"width=7 bgcolor=#bbbbbb></td></tr></table><table "
+"width=" 
+ ww2
+" border=0 cellspacing=0 cellpadding=0> "
+"<tr height=3><td bgcolor=#bbbbbb></td></tr></table"
+"> <!-- End Control Panel --> </td> <td><img src"
+"='cplright.gif' height=33 width=11></td> <td><img"
+" src='right.gif' height=33 width=5></td> </tr></t"
+"able><!-- Separator --> <table border=0 cells"
+"pacing=0 cellpadding=0> <tr height=11 width="
+ totalWidth
+"> "
+"<td width=1 bgcolor=#bbbbbb></td> <td width=1 bg"
+"color=#ffffff></td> <td width=1 bgcolor=#bbbbbb><"
+"/td> <td><img src='ml.gif'></td><td><img src='"
+"separatr.gif' width="
+ wideWidth
+" height=11></td><td><img"
+" src='mr.gif'></td><td><img src='right.gif' width"
+"=5></td></tr></table> <!-- Mine Field --> <table"
+" width="
+ totalWidth
+" border=0 cellspacing=0 cellpadding=0> "
+"<tr height="
+ highHeight
+"> <td width=1 bgcolor=#bbbbbb></td>"
+" <td width=1 bgcolor=#ffffff></td> <td width=1 b"
+"gcolor=#bbbbbb></td> <td><img src='fielside.gif' "
+"width=12 height="
+ highHeight
+"></td> <td> <!-- Game Field -"
+"->");
var s = "";
var x, y;
for(y = 0; y < gridy; ++y) {
for(x = 0; x < gridx; ++x) {
s = s + '<a href="javascript:gridclick(' + y + ',' + x +');">' +
'<img src="' + dir + 'sqt0.gif" name="grd'+y+'_'+x+'" border=0></a>'
}
s = s + "<br>";
}
document.write(s);
document.write('<!-- End Game Field --></td><td'
+' valign=right><img src="fielside.gif" width=12 heig'
+'ht='
+ highHeight
+'></td> <td valign=right><img src="right.gif'
+'" width=5 height='
+ highHeight
+'></td></tr></table><!-- En'
+'d Mine Field --><!-- Footer --><table width='
+ totalWidth
+' border=0 cellspacing=0 cellpadding=0><tr heigh'
+'t=12> <td width=1 bgcolor=#bbbbbb></td> <td widt'
+'h=1 bgcolor=#ffffff></td> <td width=1 bgcolor=#bb'
+'bbbb></td> <td><img src="bl.gif"></td> <td><img '
+'src="footer.gif" width='
+ wideWidth
+' height=12></td> <td><i'
+'mg src="br.gif"></td> <td><img src="right.gif" he'
+'ight=12></td></tr></table><!-- Bottom --> <ta'
+'ble width='
+ totalWidth
+' border=0 cellspacing=0 cellpadding=0'
+'> <tr bgcolor=#bbbbbb height=1> <td width=1 bgco'
+'lor=#bbbbbb></td><td width=1 bgcolor=#ffffff></t'
+'d> <td width=1 bgcolor=#bbbbbb></td><td width='
+ tW6
+' bgcolor=#bbbbbb></td><td width=1 bgcolor=#bbb'
+'bbb></td> <td width=1 bgcolor=#888888></td> <td '
+'width=1 bgcolor=#000000></td> </tr> <tr height=1'
+'> <td width=1 bgcolor=#bbbbbb></td> <td width=1 '
+'bgcolor=#888888></td> <td width=1 bgcolor=#888888'
+'></td> <td bgcolor=#888888></td> <td width=1 bgc'
+'olor=#888888></td> <td width=1 bgcolor=#888888></'
+'td> <td width=1 bgcolor=#000000></td> </tr> <tr'
+' height=1> <td width=1 bgcolor=#000000></td> <td'
+' width=1 bgcolor=#000000></td> <td width=1 bgcolo'
+'r=#000000></td> <td bgcolor=#000000></td> <td wi'
+'dth=1 bgcolor=#000000></td> <td width=1 bgcolor=#'
+'000000></td> <td width=1 bgcolor=#000000></td> <'
+'/tr></table> </div>');
}
// Function to calculate the number of mines adjacent to a grid location
function surrounding(y,x) {
var count = 0;
if (y > 0 && x > 0 && mines[y-1][x-1]) count++;
if (y > 0 && mines[y-1][x]) count++;
if (y > 0 && x < gridx-1 && mines[y-1][x+1]) count++;
if (x > 0 && mines[y][x-1]) count++;
if (x < gridx-1 && mines[y][x+1]) count++;
if (y < gridy-1 && x > 0 && mines[y+1][x-1]) count++;
if (y < gridy-1 && mines[y+1][x]) count++;
if (y < gridy-1 && x < gridx-1 && mines[y+1][x+1]) count++;
return count;
}
// Recursive function to 'roll back' the grid when user clicks on a tile
// with no surrounding mines
function rollback(y,x) {
if (y >= 0 && y < gridy && x >=0 && x < gridx) {
if (shown[y][x] != 3) {
var c = surrounding(y,x);
shown[y][x] = 3;
squaresleft--;
document.images["grd"+y+"_"+x].src = dir + "sq"+c+".gif";
if (c == 0) {
rollback(y-1,x-1);
rollback(y-1,x);
rollback(y-1,x+1);
rollback(y,x-1);
rollback(y,x+1);
rollback(y+1,x-1);
rollback(y+1,x);
rollback(y+1,x+1);
}
}
}
}
// Function called when player steps on a mine. All mine locations are uncovered
function dead() {
var y, x;
for(y = 0; y < gridy; ++y) {
for(x = 0; x < gridx; ++x) {
if (mines[y][x]) {
if (shown[y][x] != 1) {
document.images["grd"+y+"_"+x].src = dir + "mine.gif";
}
}
else if (shown[y][x] == 1) {
document.images["grd"+y+"_"+x].src = dir + "nomine.gif";
}
}
}
document.images.condition.src = dir + "btndead.gif";
playing = false;
clicked = false;
}
// handler called whenever the grid is clicked
function gridclick(y, x) {
if (playing) {
clicked = true;
if (placeflag) {
if (shown[y][x] < 3) {
var s = shown[y][x];
var change = true;
if (s == 1) {
flagsleft++;
squaresleft++;
}
if (flagsleft == 0 && s == 0) {
change = false;
}
else {
if (s == 2) s = 0;
else s++;
if (s == 1) {
flagsleft--;
squaresleft--;
}
}
if (change) {
shown[y][x] = s;
document.images["grd"+y+"_"+x].src = dir + "sqt"+s+".gif";
setStatus();
}
if (squaresleft == 0) {
document.images.condition.src = dir + "btncool.gif";
playing = false;
}
}
}
// check not flagged as a mine
else if (shown[y][x] != 1) {
if (mines[y][x]) {
document.images["grd"+y+"_"+x].src = dir + "minered.gif";
dead();
}
else {
rollback(y,x);
}
}
}
}
// Start the game
newgame();
// End -->
</script>
Дальше дело техники))).
0
9 / 9 / 2
Регистрация: 18.08.2008
Сообщений: 127
26.08.2008, 18:07 3
Извините . Хотя я слаб в JavaScripte . Я в шоке, как легко в нем работать.
Вот ссылка где эта прога стоит вместе с картинками.

http://javascript.internet.com... eeper.html

и если бы не предыдущей ответ , я даже бы не знал это.
0
Администратор
80020 / 48582 / 244
Регистрация: 10.04.2006
Сообщений: 13,128
26.08.2008, 20:04 4
Код
<!-- ONE STEP TO INSTALL MINESWEEPER:

  1.  Copy the coding into the BODY of your HTML document  -->

<!-- STEP ONE: Paste this code into the BODY of your HTML document  -->

<BODY>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Peter Occil (poccil@yahoo.com) -->
<!-- Web Site:  http://www.geocities.com/poccil -->
<!-- Based on original code by Jason Hotchkiss -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
dir = "";
var mines = [];
var shown = [];
var gridx, gridy, maxmines;
gridx = window.prompt("Please enter a width.","8");
gridxverify();
function gridxaccept(){
gridy = window.prompt("Please enter a height.","8");
gridyverify();
}
function gridyaccept(){
maxmines = window.prompt("Please enter the number of mines you want.","10");
maxminesverify();
}
function gridxverify(){
if (gridx > 50){
alert("That width is too big. Please enter a new width.");
gridxreenter();
}
else if (gridx < 8){
alert("That width is too small. Please enter a new width.");
gridxreenter();
}
else gridxaccept();
}

function gridyverify(){
if (gridy > 50){
alert("That height is too big. Please enter a new height.");
gridyreenter();
}
else if (gridy < 8){
alert("That height is too small. Please enter a new height.");
gridyreenter();
}
else gridyaccept();
}
function maxminesverify(){
if (maxmines > 500){
alert("That number is too big. Please enter a new number of mines.");
maxminesreenter();
}
else if (maxmines < 10){
alert("That number is too small. Please enter a new number of mines.");
maxminesreenter();
}
else accepted();
}
// Functions for reentering key variables, if necessary.
function gridxreenter(){
gridx = window.prompt("Please enter a width.","8");
gridxverify();
}
function gridyreenter(){
gridy = window.prompt("Please enter a height.","8");
gridyverify();
}
function maxminesreenter(){
maxmines = window.prompt("Please enter the number of mines you want.","10");
maxminesverify();
}
function accepted(){
var squaresleft, flagsleft;
var elapsedtime;
var playing;
var placeflag;
var clicked;
}
var gridSq = gridx * 16;
var grid8 = gridSq - 128;
var grid16 = gridx - 8
var grid32 = grid16 * 8
var grid64 = grid16 * 16
var topBarWidth = 8 + grid64;
var menuBarWidth = 86 + grid64;
var wideWidth = gridx * 16;
var highHeight = gridy * 16;
var cplLeft = 6 + grid32;
var cplRight = 4 + grid32;
var totalWidth = gridSq + 32;
var tW6 = totalWidth - 6;
var ww2 = wideWidth + 2;
num=new Array(10);
for (var i=0;i<10;i++) {
num[i]=new Image()
num[i].src=i+".gif"
}
function keyDown(e) {
if(document.layers)
placeflag = (e.modifiers & Event.CONTROL_MASK) > 0;
else
placeflag = window.event.ctrlKey;
setStatus();
}
function keyUp(e) {
placeflag = false;
setStatus();
}
function newgame() {
// reset state arrays. mines holds the position of each mine. shown keeps
// track of the image shown at each grid location
var y;
for(y = 0; y < gridy; ++y)
{
mines[y] = [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false];
shown[y] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
// Place the mines, making sure positions are unique
var m;
for(m = 0; m < maxmines; ++m) {
var x,y;
do {
x = Math.floor(Math.random() * gridx);
y = Math.floor(Math.random() * gridy);
} while(mines[y][x]);
mines[y][x] = true;
}
// initialize game variables
squaresleft = gridy * gridx;
flagsleft = maxmines;
elapsedtime = 0;
playing = true;
clicked = false
placeflag = false;
// insert the grid into the document
buildgrid();
// Set up keypress handlers
if (document.layers)
window.captureEvents(Event.KEYDOWN | Event.KEYUP);
window.onKeyDown = keyDown;
window.onKeyUp = keyUp;
// start the clock
setInterval("ticker()", 1000);
}
// clock tick handler
function ticker() {
if (playing) {
if (clicked) {
elapsedtime++;
setStatus();
   }
  }
}

// Refreshing control panel
function setStatus() {
document.images.elapse3.src=num[elapsedtime-(Math.floor(elapsedtime/10))*10].src;
document.images.elapse2.src=num[Math.floor((elapsedtime-(Math.floor(elapsedtime/100))*100)/10)].src;
document.images.elapse1.src=num[Math.floor(elapsedtime/100)].src;
document.images.flag3.src=num[flagsleft-(Math.floor(flagsleft/10))*10].src;
document.images.flag2.src=num[Math.floor((flagsleft-(Math.floor(flagsleft/100))*100)/10)].src;
document.images.flag1.src=num[Math.floor(flagsleft/100)].src;
}
//function to insert all the IMG tags into the document
function buildgrid() {
document.write("<!-- Window --><DIV align=center> "
 +"<!-- Top Bar --> <table width="
 + totalWidth
 +" border=0 cells"
 +"pacing=0 cellpadding=0> <tr bgcolor=#bbbbbb heigh"
 +"t=1> <td width=1 bgcolor=#bbbbbb></td><td width"
 +"=1 bgcolor=#bbbbbb></td> <td width=1 bgcolor=#bbb"
 +"bbb></td><td width="
 + tW6
 +" bgcolor=#bbbbbb></td> <t"
 +"d width=1 bgcolor=#bbbbbb></td> <td width=1 bgcol"
 +"or=#bbbbbb></td> <td width=1 bgcolor=#000000></td"
 +"></tr><tr height=1><td width=1 bgcolor=#bbbb"
 +"bb></td><td width=1 bgcolor=#ffffff></td><td w"
 +"idth=1 bgcolor=#ffffff></td><td bgcolor=#ffffff>"
 +"</td><td width=1 bgcolor=#ffffff></td><td widt"
 +"h=1 bgcolor=#888888></td><td width=1 bgcolor=#00"
 +"0000></td></tr><tr height=1><td width=1 bgco"
 +"lor=#bbbbbb></td><td width=1 bgcolor=#ffffff></t"
 +"d><td width=1 bgcolor=#bbbbbb></td><td bgcolor"
 +"=#bbbbbb></td><td width=1 bgcolor=#bbbbbb></td> "
 +"<td width=1 bgcolor=#888888></td><td width=1 bg"
 +"color=#000000></td></tr></table><!-- Title -->"
 +"<table border=0 cellspacing=0 cellpadding=0><t"
 +"r height=18><td width=1 bgcolor=#bbbbbb></td><"
 +"td width=1 bgcolor=#ffffff></td><td width=1 bgco"
 +"lor=#bbbbbb></td><td bgcolor=#000088><img src='t"
 +"itle.gif'><img src='a.gif' height=1 width="
 + topBarWidth
 +" name="
 +"'titleBarEmptySpace'></td><td><img src='buttons."
 +"gif'></td><td width=1 bgcolor=#bbbbbb></td><td"
 +" width=1 bgcolor=#888888></td><td width=1 bgcolo"
 +"r=#000000></td></tr></table><!-- Menu Bar --> "
 +"<table border=0 cellspacing=0 cellpadding=0> <tr"
 +" height=20 bgcolor=#bbbbbb> <td width=1 bgcolor=#"
 +"bbbbbb></td> <td><img src='menu.gif'></td><td> <"
 +"img src='a.gif' height=1 width="
 + menuBarWidth
 +" name='menuBarEmp"
 +"tySpace'></td> <td width=1 bgcolor=#bbbbbb></td> "
 +"<td width=1 bgcolor=#888888></td> <td width=1 bg"
 +"color=#000000></td> </tr></table> <!-- Mine Fiel"
 +"d --> <table border=0 cellspacing=0 cellpadding=0"
 +"> <tr height=11 width=160> <td width=1 bgcolor=#"
 +"bbbbbb></td> <td width=1 bgcolor=#ffffff></td> <"
 +"td width=1 bgcolor=#bbbbbb></td> <td><img src='tl"
 +".gif'></td> <td><img src='header.gif' width="
 + ww2
 +" height=11></td> <td><img src='tr.gif'></td><td><"
 +"img src='right.gif' width=5 height=11></td> </tr>"
 +"</table><table width="
 + totalWidth
 +" border=0 cellspacing=0 cellpadd"
 +"ing=0> <tr height=33> <td width=1 bgcolor=#bbbbb"
 +"b></td> <td width=1 bgcolor=#ffffff></td> <td wi"
 +"dth=1 bgcolor=#bbbbbb></td> <td><img src='cplleft"
 +".gif' height=33 width=11></td> <td> <!-- Control"
 +" Panel --> <table width="
 + ww2
 +" border=0 cellspacing="
 +"0 cellpadding=0><tr height=4 width="
 + ww2
 +"><td bgcolor=#bbbbbb"
 +"></td></tr></table> <table width="
 + ww2
 +" border=0 cel"
 +"lspacing=0 cellpadding=0><tr height=26><td "
 +"width=5 bgcolor=#bbbbbb></td><td><!-- Mines Remai"
 +"ning --> <table width=41 border=0 cellspacing=0 c"
 +"ellpadding=0><tr bgcolor=#888888><td></td><td>"
 +"</td><td></td> <td></td><td></td><td></td> <td><"
 +"/td><td></td> <td width=1 bgcolor=#bbbbbb></td></"
 +"tr> <tr bgcolor=#000000> <td width=1 bgcolor=#88"
 +"8888></td> <td></td><td></td> <td></td><td></td>"
 +"<td></td><td></td><td></td> <td width=1 bgcolor"
 +"=#ffffff></td></tr> <tr bgcolor=#000000> <td wid"
 +"th=1 bgcolor=#888888></td> <td width=1 bgcolor=#0"
 +"00000></td> <td><img src='0.gif' name='flag1'></t"
 +"d><td width=2></td><td><img src='1.gif' name='"
 +"flag2'></td><td width=2></td><td><img src='0.g"
 +"if' name='flag3'></td><td width=1></td> <td wid"
 +"th=1 bgcolor=#ffffff></td></tr> <tr bgcolor=#0000"
 +"00> <td width=1 bgcolor=#888888></td> <td></td><"
 +"td></td> <td></td><td></td><td></td> <td></td><t"
 +"d></td> <td width=1 bgcolor=#ffffff></td></tr> <"
 +"tr bgcolor=#ffffff> <td width=1 bgcolor=#bbbbbb><"
 +"/td> <td></td><td></td> <td></td><td></td><td></"
 +"td> <td></td><td></td> <td></td></tr><"
 +"tr bgcolor=#bbbbbb> <td width=1 bgcolor=#bbbbbb><"
 +"/td> <td></td><td></td> <td></td><td></td><td></"
 +"td> <td></td><td></td> <td></td></tr></table><!--"
 +" End Mines Remaini"
 +"ng --> </td> <td bgcolor=#bbbbbb><img height=1 "
 +"src='a.gif' width=" + cplLeft + "name='cplLeft'>"
 +"<td><img src='btnsmile.gif' name='condition' onmo"
 +"usedown='document.images.condition.s"
 +'rc="btnsmil2.gif"'
 +";' onmouseu"
 +"p='document.images.condition.s"
 +'rc="btnsmile.gif";location.reload();'
 +";'></td> <td width=4 bgcolor=#bbbbbb>"
 +"<img height=1 src='a.gif'"
 +" width=" + cplRight + ">"
 +"</td> <td> <!-- Elapsed Time --> <table width=4"
 +"1 border=0 cellspacing=0 cellpadding=0> <tr bgcol"
 +"or=#888888> <td></td><td></td><td></td> <td></td"
 +"><td></td><td></td><td></td><td></td> <td width"
 +"=1 bgcolor=#bbbbbb></td></tr> <tr bgcolor=#000000"
 +"> <td width=1 bgcolor=#888888></td> <td></td><td"
 +"></td> <td></td><td></td><td></td> <td></td><td>"
 +"</td> <td width=1 bgcolor=#ffffff></td></tr> <tr"
 +" bgcolor=#000000> <td width=1 bgcolor=#888888></t"
 +"d> <td width=1 bgcolor=#000000></td> <td><img sr"
 +"c='0.gif' name='elapse1'></td> <td width=2></td> "
 +"<td><img src='0.gif' name='elapse2'></td> <td wi"
 +"dth=2></td> <td><img src='0.gif' name='elapse3'><"
 +"/td> <td width=1></td> <td width=1 bgcolor=#ffff"
 +"ff></td></tr> <tr bgcolor=#000000> <td width=1 b"
 +"gcolor=#888888></td> <td></td><td></td> <td></td"
 +"><td></td><td></td> <td></td><td></td> <td width"
 +"=1 bgcolor=#ffffff></td></tr> <tr bgcolor=#ffffff"
 +"> <td width=1 bgcolor=#bbbbbb></td> <td></td><td"
 +"></td> <td></td><td></td><td></td> <td></td><td>"
 +"</td> <td></td></tr> <"
 +"tr bgcolor=#bbbbbb> <td width=1 bgcolor=#bbbbbb><"
 +"/td> <td></td><td></td> <td></td><td></td><td></"
 +"td> <td></td><td></td> <td></td></tr> "
 +"</table> <!-- End Elapsed Time --> </td> <td "
 +"width=7 bgcolor=#bbbbbb></td></tr></table><table "
 +"width=" 
 + ww2
 +" border=0 cellspacing=0 cellpadding=0> "
 +"<tr height=3><td bgcolor=#bbbbbb></td></tr></table"
 +"> <!-- End Control Panel --> </td> <td><img src"
 +"='cplright.gif' height=33 width=11></td> <td><img"
 +" src='right.gif' height=33 width=5></td> </tr></t"
 +"able><!-- Separator --> <table border=0 cells"
 +"pacing=0 cellpadding=0> <tr height=11 width="
 + totalWidth
 +"> "
 +"<td width=1 bgcolor=#bbbbbb></td> <td width=1 bg"
 +"color=#ffffff></td> <td width=1 bgcolor=#bbbbbb><"
 +"/td> <td><img src='ml.gif'></td><td><img src='"
 +"separatr.gif' width="
 + wideWidth
 +" height=11></td><td><img"
 +" src='mr.gif'></td><td><img src='right.gif' width"
 +"=5></td></tr></table> <!-- Mine Field --> <table"
 +" width="
 + totalWidth
 +" border=0 cellspacing=0 cellpadding=0> "
 +"<tr height="
 + highHeight
 +"> <td width=1 bgcolor=#bbbbbb></td>"
 +" <td width=1 bgcolor=#ffffff></td> <td width=1 b"
 +"gcolor=#bbbbbb></td> <td><img src='fielside.gif' "
 +"width=12 height="
 + highHeight
 +"></td> <td> <!-- Game Field -"
 +"->");
var s = "";
var x, y;
for(y = 0; y < gridy; ++y) {
for(x = 0; x < gridx; ++x) {
s = s + '<a href="javascript:gridclick(' + y + ',' + x +');">' +
'<img src="' + dir + 'sqt0.gif" name="grd'+y+'_'+x+'" border=0></a>'
}
s = s + "<br>";
}
document.write(s);
document.write('<!-- End Game Field --></td><td'
 +' valign=right><img src="fielside.gif" width=12 heig'
 +'ht='
 + highHeight
 +'></td> <td valign=right><img src="right.gif'
 +'" width=5 height='
 + highHeight
 +'></td></tr></table><!-- En'
 +'d Mine Field --><!-- Footer --><table width='
 + totalWidth
 +' border=0 cellspacing=0 cellpadding=0><tr heigh'
 +'t=12> <td width=1 bgcolor=#bbbbbb></td> <td widt'
 +'h=1 bgcolor=#ffffff></td> <td width=1 bgcolor=#bb'
 +'bbbb></td> <td><img src="bl.gif"></td> <td><img '
 +'src="footer.gif" width='
 + wideWidth
 +' height=12></td> <td><i'
 +'mg src="br.gif"></td> <td><img src="right.gif" he'
 +'ight=12></td></tr></table><!-- Bottom --> <ta'
 +'ble width='
 + totalWidth
 +' border=0 cellspacing=0 cellpadding=0'
 +'> <tr bgcolor=#bbbbbb height=1> <td width=1 bgco'
 +'lor=#bbbbbb></td><td width=1 bgcolor=#ffffff></t'
 +'d> <td width=1 bgcolor=#bbbbbb></td><td width='
 + tW6
 +' bgcolor=#bbbbbb></td><td width=1 bgcolor=#bbb'
 +'bbb></td> <td width=1 bgcolor=#888888></td> <td '
 +'width=1 bgcolor=#000000></td> </tr> <tr height=1'
 +'> <td width=1 bgcolor=#bbbbbb></td> <td width=1 '
 +'bgcolor=#888888></td> <td width=1 bgcolor=#888888'
 +'></td> <td bgcolor=#888888></td> <td width=1 bgc'
 +'olor=#888888></td> <td width=1 bgcolor=#888888></'
 +'td> <td width=1 bgcolor=#000000></td> </tr> <tr'
 +' height=1> <td width=1 bgcolor=#000000></td> <td'
 +' width=1 bgcolor=#000000></td> <td width=1 bgcolo'
 +'r=#000000></td> <td bgcolor=#000000></td> <td wi'
 +'dth=1 bgcolor=#000000></td> <td width=1 bgcolor=#'
 +'000000></td> <td width=1 bgcolor=#000000></td> <'
 +'/tr></table> </div>');
}
// Function to calculate the number of mines adjacent to a grid location
function surrounding(y,x) {
var count = 0;
if (y > 0 && x > 0 && mines[y-1][x-1]) count++;
if (y > 0 && mines[y-1][x]) count++;
if (y > 0 && x < gridx-1 && mines[y-1][x+1]) count++;
if (x > 0 && mines[y][x-1]) count++;
if (x < gridx-1 && mines[y][x+1]) count++;
if (y < gridy-1 && x > 0 && mines[y+1][x-1]) count++;
if (y < gridy-1 && mines[y+1][x]) count++;
if (y < gridy-1 && x < gridx-1 && mines[y+1][x+1]) count++;
return count;
}
// Recursive function to 'roll back' the grid when user clicks on a tile
// with no surrounding mines
function rollback(y,x) {
if (y >= 0 && y < gridy && x >=0 && x < gridx) {
if (shown[y][x] != 3) {
var c = surrounding(y,x);
shown[y][x] = 3;
squaresleft--;
document.images["grd"+y+"_"+x].src = dir + "sq"+c+".gif";
if (c == 0) {
rollback(y-1,x-1);
rollback(y-1,x);
rollback(y-1,x+1);
rollback(y,x-1);
rollback(y,x+1);
rollback(y+1,x-1);
rollback(y+1,x);
rollback(y+1,x+1);
         }
      }
   }
}
// Function called when player steps on a mine. All mine locations are uncovered
function dead() {
var y, x;
for(y = 0; y < gridy; ++y) {
for(x = 0; x < gridx; ++x) {
if (mines[y][x]) {
if (shown[y][x] != 1) {
document.images["grd"+y+"_"+x].src = dir + "mine.gif";
   }
}
else if (shown[y][x] == 1) {
document.images["grd"+y+"_"+x].src = dir + "nomine.gif";
      }
   }
}
document.images.condition.src = dir + "btndead.gif";
playing = false;
clicked = false;
}
// handler called whenever the grid is clicked
function gridclick(y, x) {
if (playing) {
clicked = true;
if (placeflag) {
if (shown[y][x] < 3) {
var s = shown[y][x];
var change = true;
if (s == 1) {
flagsleft++;
squaresleft++;
}
if (flagsleft == 0 && s == 0) {
change = false;
}
else {
if (s == 2) s = 0;
else s++;
if (s == 1) {
flagsleft--;
squaresleft--;
   }
}
if (change) {
shown[y][x] = s;
document.images["grd"+y+"_"+x].src = dir + "sqt"+s+".gif";
setStatus();
}
if (squaresleft == 0) {
document.images.condition.src = dir + "btncool.gif";
playing = false;
      }
   }
}
// check not flagged as a mine
else if (shown[y][x] != 1) {
if (mines[y][x]) {
document.images["grd"+y+"_"+x].src = dir + "minered.gif";
dead();
}
else  {
rollback(y,x);
         }
      }
   }
}
// Start the game
newgame();
//  End -->
</script>

<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size:  15.73 KB -->
0
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
26.08.2008, 20:04

Заказываю контрольные, курсовые, дипломные работы и диссертации здесь.

Нужны исходники сапера
В Borland Delphi составить программы, реализующие следующие компьютерные игры сапер. с...

Решил написать сапера - неясности
Только недавно начал изучать C# и захотелось мне написать игру сапер. Решил сначала написать...

Класс кнопок для сапера Windows
Никак не могу сделать интерфейс сапера используя ВинАпи. Обычные кнопки не реагируют на нажатия...

Как создать стандартное виновское поле Сапера?
Подскажите плз, как создать стандартное виновское поле Сапера, которое можно было бы минять в...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
4
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2021, vBulletin Solutions, Inc.