var G; if (parseInt(navigator.appVersion)>3) { document.onmousedown = mouseDown; if (navigator.appName=="Netscape") document.captureEvents(Event.MOUSEDOWN); } function Game() { this.gg_name='Сапёр'; this.gg_version='1.0'; this.gg_bgcolor='#919191'; this.gg_field_bgcolor='#C8C8C8'; this.gg_bgcolor_status='#FFFFA8'; this.gg_mine_colors = new Array("", "#0000b3", "#00b300", "#b30000", "#f9f900", "#b300b3", "#00b3b3"); this.gg_img_dir='/games/minesweeper/images/'; this.gg_cell_size=40; this.gg_mines_num= 10; this.gg_field_size=9; var cur_url = new String(window.location); var url_re = /(16)\.html/i; if (cur_url.match(url_re)!=null) { this.gg_field_size = RegExp.$1 this.gg_mines_num= 35; this.gg_img_dir='/games/minesweeper/images-small/'; this.gg_cell_size=30; } this.gg_delay=300; this.gg_base_url=''; this.gg_ajaxurl='/games/minesweeper/minesweeper.ajax.php'; this.gg_ajaxmode = new String; this.gu_status=''; this.gu_game_data=''; this.gu_mines=0; this.gu_time= new String; this.gi_time_id = 0; this.gi_time_start; this.gi_time_int = 0; this.gi_x_pos_old=-1; this.gi_y_pos_old=-1; this.gi_x_pos_new=-1; this.gi_y_pos_new=-1; this.gi_rclick=false; this.gi_game_finished=false; this.gi_game_started=false; this.gi_around_cells = new Array(); this.gi_opened = 0; this.gi_mines_orig = 0; // this.gd_btn_captions = new Array('Новая игра', 'Загрузить', 'Сохранить', 'Настройки', 'Правила'); this.gd_btn_ids = new Array('_gamebuttonnew', '_gamebuttonload', '_gamebuttonsave', '_gamebuttonsettings', '_gamebuttonrules'); this.gd_btn_act = new Array('newGame()', 'alert(\'отключено\')', 'alert(\'отключено\')', 'displayRadio(G.gg_field_size);winOpen(\'_gameparams\');', '#rules'); for (var i=0;i\n'); document.writeln('\n'); document.writeln(''); document.writeln('\n'); document.writeln('\n'); document.writeln('\n'); document.writeln('
Мины: Время: 00:00:00
\n'); document.writeln(''); document.writeln('\n'); document.writeln('\n'); document.writeln('\n'); document.writeln('\n'); for (var j=0;j\n'); for (var i=0;i\n'); } document.writeln('\n'); } document.writeln('
\n'); document.writeln('\n'); document.writeln('\n'); document.writeln('\n'); document.writeln(''); for (var i=0;i2) { var href='#'; var onclk = 'javascript:return true'; if (this.gd_btn_act[i] == "#rules") { href=this.gd_btn_act[i]; } else { onclk ='javascript:' + this.gd_btn_act[i] + ';'; } document.writeln('\n'); } } document.writeln('\n'); document.writeln('\n'); document.writeln('\n'); document.writeln('\n'); document.writeln('
\n'); } this.setStatus=function setStatus(s) { if (document.getElementById('_gamestatus')) { document.getElementById('_gamestatus').innerHTML=s; } } this.showCell=function showCell(x_pos,y_pos) { var m=0; if (this.getCell(x_pos,y_pos) != 2) { this.gi_opened++; this.setCell(x_pos,y_pos,2); var x_start = x_pos - 1; if (x_start < 0) { x_start = 0; } var x_end = x_pos + 1; if (x_end == this.gg_field_size) { x_end = x_pos; } var y_start = y_pos - 1; if (y_start < 0) { y_start = 0; } var y_end = y_pos + 1; if (y_end == this.gg_field_size) { y_end = y_pos; } for (var j=y_start; j <= y_end; j++) { for (var i=x_start; i <= x_end; i++) { if (this.getCell(i, j) == 1 || this.getCell(i, j) == 11) { m++; } } } if (m > 0) { document.getElementById('cell_'+x_pos+'_'+y_pos).style.color=this.gg_mine_colors[m]; document.getElementById('cell_'+x_pos+'_'+y_pos).innerHTML=m; } else { document.getElementById('cell_'+x_pos+'_'+y_pos).innerHTML=''; } } return m; } this.showCells=function showCells(x_pos,y_pos, t) { if (this.showCell(x_pos,y_pos) == 0) { var x = x_pos; var y = y_pos; this.gi_around_cells[this.gg_field_size*y + x] = t; if (x>0 && y>0) { if (this.gi_around_cells[this.gg_field_size*(y-1) + (x-1)] == 0) { this.showCells(x-1,y-1,t); } } if (y>0) { if (this.gi_around_cells[this.gg_field_size*(y-1) + x] == 0) { this.showCells(x,y-1,t); } } if (y>0 && x < (this.gg_field_size-1)) { if (this.gi_around_cells[this.gg_field_size*(y-1) + (x+1)] == 0) { this.showCells(x+1,y-1,t); } } if (x > 0) { if (this.gi_around_cells[this.gg_field_size*y + (x - 1)] == 0) { this.showCells(x-1,y,t); } } if (x < (this.gg_field_size-1)) { if (this.gi_around_cells[this.gg_field_size*y + (x+1)] == 0) { this.showCells(x+1,y,t); } } if (x > 0 && y < (this.gg_field_size-1)) { if (this.gi_around_cells[this.gg_field_size*(y+1) + (x-1)] == 0) { this.showCells(x-1,y+1,t); } } if (y < (this.gg_field_size-1)) { if (this.gi_around_cells[this.gg_field_size*(y+1) + x] == 0) { this.showCells(x,y+1,t); } } if (x < (this.gg_field_size-1) && y < (this.gg_field_size-1)) { if (this.gi_around_cells[this.gg_field_size*(y+1) + (x+1)] == 0) { this.showCells(x+1,y+1,t); } } } return t; } this.openCell=function openCell(x_pos,y_pos) { var r = true; var v=this.getCell(x_pos,y_pos); if (v==2) { this.setStatus("Ячейка уже открыта"); } if (v==1) { this.gi_game_finished=true; for (var i=0;i'; } } } this.setStatus("В ячейке бомба. Игра завершена."); } if (v==0) { var t = new Date(); t = t.getTime(); this.showCells(x_pos,y_pos,t); for (var y=0;y0 && y>0) { if (this.gi_around_cells[this.gg_field_size*(y-1) + (x-1)] == 1) { this.showCell(x-1,y-1); } } if (y>0) { if (this.gi_around_cells[this.gg_field_size*(y-1) + x] == 1) { this.showCell(x,y-1); } } if (y>0 && x < (this.gg_field_size-1)) { if (this.gi_around_cells[this.gg_field_size*(y-1) + (x+1)] == 1) { this.showCell(x+1,y-1); } } if (x > 0) { if (this.gi_around_cells[this.gg_field_size*y + (x - 1)] == 1) { this.showCell(x-1,y); } } if (x < (this.gg_field_size-1)) { if (this.gi_around_cells[this.gg_field_size*y + (x+1)] == 1) { this.showCell(x+1,y); } } if (x > 0 && y < (this.gg_field_size-1)) { if (this.gi_around_cells[this.gg_field_size*(y+1) + (x-1)] == 1) { this.showCell(x-1,y+1); } } if (y < (this.gg_field_size-1)) { if (this.gi_around_cells[this.gg_field_size*(y+1) + x] == 1) { this.showCell(x,y+1); } } if (x < (this.gg_field_size-1) && y < (this.gg_field_size-1)) { if (this.gi_around_cells[this.gg_field_size*(y+1) + (x+1)] == 1) { this.showCell(x+1,y+1); } } } } } } return r; } this.processClick=function processClick(x_pos,y_pos) { if (this.gi_game_finished==false) { if (this.gi_game_started==false) { this.gi_game_started=true; this.setStartTime(); } if (this.gi_rclick) { var v = this.getCell(x_pos,y_pos); if (v>=10) { this.gu_mines++; this.setCell(x_pos,y_pos,(this.getCell(x_pos,y_pos)-10)); document.getElementById('cell_'+x_pos+'_'+y_pos).innerHTML=''; } else { if (v != 2) { this.setCell(x_pos,y_pos,(this.getCell(x_pos,y_pos)+10)); this.gu_mines--; document.getElementById('cell_'+x_pos+'_'+y_pos).innerHTML=''; } } document.getElementById('gamemines').innerHTML='Мины: ' + this.gu_mines; } else this.openCell(x_pos,y_pos); if (this.gu_mines == 0 && this.gi_opened == ((this.gg_field_size*this.gg_field_size) - this.gi_mines_orig)) { this.gi_game_finished=true; this.gg_ajaxmode="check"; var s = new String; for (var i=0;i= 10) { v=1; } else { v=0; } s = s.concat(v); } } this.setStatus("Проверка игры..."); callServer(null, this.gg_ajaxurl+'?check/'+this.gu_game_data+'/'+s, null, null, readData, G); } } } this.markAroundCells=function markAroundCells(x_pos,y_pos) { var v = this.getCell(x_pos, y_pos) ; var x_start = x_pos - 1; if (x_start < 0) { x_start = 0; } var x_end = x_pos + 1; if (x_end == this.gg_field_size) { x_end = x_pos; } var y_start = y_pos - 1; if (y_start < 0) { y_start = 0; } var y_end = y_pos + 1; if (y_end == this.gg_field_size) { y_end = y_pos; } var m=0; for (var j=y_start; j <= y_end; j++) { for (var i=x_start; i <= x_end; i++) { if (this.gi_around_cells[this.gg_field_size*j + i]==0) { this.gi_around_cells[this.gg_field_size*j + i] = 1; } } } this.gi_around_cells[this.gg_field_size*y_pos + x_pos] = 2; } this.getDebug=function getDebug() { var s = new String; /* for (var i=0;i'; } else { document.getElementById('cell_'+j+'_'+i).innerHTML=''; this.markAroundCells(j, i); k++; } } } this.setStatus("Игра загружена."); this.gu_game_data=in_data; this.gi_game_started=false; this.gi_game_finished=false; this.gi_opened=0; document.getElementById('gametime').innerHTML="Время: 00:00:00"; this.gu_mines=k; this.gi_mines_orig=k; document.getElementById('gamemines').innerHTML="Мины: " + this.gu_mines; } else { this.setStatus("Ошибка данных."); } } this.updateTime=function updateTime() { if (this.gi_game_finished==false && this.gi_game_started==true) { var st = new Array(); var t = new Date(); var d = Math.floor((t.getTime() - this.gi_time_start)/1000); if (d < 0) { d = Math.floor(this.gi_time_int/3); } var ta = new Array(0,0,0); var tac = new Array(3600,60,1); var time_out = new String; for (var i = 0; i < ta.length; i++) { ta[i] = Math.floor(d/tac[i]); d = d - tac[i]*ta[i]; z = new String(":"); if (i == 0) { z = ""; } if (ta[i] < 10) { z = z.concat("0"); } time_out = time_out.concat(z,ta[i]); } document.getElementById('gametime').innerHTML="Время: " +time_out; this.gu_time = time_out; this.gi_time_int++; } } this.setStartTime=function setStartTime() { this.gi_time_start = new Date(); this.gi_time_start = this.gi_time_start.getTime(); if (this.gi_time_id == 0) { this.gi_time_id = setInterval("G.updateTime()",300); } } } function startGame() { G=new Game(); var win_width = (G.gg_field_size*G.gg_cell_size); document.getElementById('_gamearea').style.width = win_width + 'px' ; G.drawField(); newGame(); } function newGame() { G.setStatus("Загружается новая игра..."); G.gg_ajaxmode = "new"; callServer(null, G.gg_ajaxurl+'?new/'+G.gg_field_size+'/'+G.gg_mines_num, null, null, readData, G); } function ConfigureGame(input_data) { G.gg_mines_num = input_data; } function readData(obj, responseText, responseXML, statusCode, statusText) { if (statusCode==200 || statusCode==201) { response = responseXML.documentElement; if (G.gg_ajaxmode == "new") { obj.loadGame(responseXML.getElementsByTagName('data')[0].firstChild.data); } if (G.gg_ajaxmode == "check") { r = new String(responseXML.getElementsByTagName('data')[0].firstChild.data); if (r == '1') { alert('Поздравляем! Игра завершена за ' + G.gu_time + '.'); } else { alert('Мины определены неверно.'); } G.setStatus("Игра завершена."); } } else { obj.setStatus("Загрузить информацию не удалось: "+statusText+'('+statusCode+')'); } } function Click(x_pos,y_pos) { G.processClick(x_pos,y_pos); } function mouseDown(e) { var shiftPressed=0; G.gi_rclick=false; if (parseInt(navigator.appVersion)>3) { var evt = navigator.appName=="Netscape" ? e:event; if (navigator.appName=="Netscape" && parseInt(navigator.appVersion)==4) { var mString =(e.modifiers+32).toString(2).substring(3,6); shiftPressed=(mString.charAt(0)=="1"); } else { shiftPressed=evt.shiftKey; } if (shiftPressed) { G.gi_rclick=true; } } return true; }