{"id":168435,"date":"2013-02-06T06:15:03","date_gmt":"2013-02-06T02:15:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=168435"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=168435","title":{"rendered":"<span class=\"post_title\">\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u043f\u0451\u0440 \u043d\u0430 html5 \u0438 LibCanvas<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/624\/2aa\/2da\/6242aa2da8b1002ad0891b027cc282ed.png\"\/><\/p>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0430\u043c\u044b\u0439 \u043e\u0431\u044b\u0447\u043d\u044b\u0439, \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u043f\u0451\u0440 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 Html5 Canvas, AtomJS, \u0438 \u0442\u0430\u0439\u043b\u043e\u0432\u043e\u0433\u043e \u0434\u0432\u0438\u0436\u043a\u0430 LibCanvas.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u0434\u043b\u044f \u00ab\u0441\u0442\u0430\u0440\u0442\u0430\u00bb \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0412\u0430\u0436\u043d\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c js-\u0444\u0430\u0439\u043b\u044b \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt; &lt;html&gt;     &lt;head&gt;         &lt;meta charset=&quot;utf-8&quot; \/&gt;         &lt;title&gt;LibCanvas :: Mines&lt;\/title&gt;         &lt;link href=&quot;\/files\/styles.css&quot; rel=&quot;stylesheet&quot; \/&gt;         &lt;script src=&quot;\/files\/js\/atom.js&quot;&gt;&lt;\/script&gt;         &lt;script src=&quot;\/files\/js\/libcanvas.js&quot;&gt;&lt;\/script&gt;     &lt;\/head&gt;     &lt;body&gt;         &lt;p&gt;&lt;a href=&quot;\/&quot;&gt;Return to index&lt;\/a&gt;&lt;\/p&gt;         &lt;script&gt; new function () {     LibCanvas.extract();      atom.dom(function () {         new Mines.Controller();     }); };         &lt;\/script&gt;         &lt;script src=&quot;js\/controller.js&quot;&gt;&lt;\/script&gt;     &lt;\/body&gt; &lt;\/html&gt; <\/code><\/pre>\n<p>  \u042f \u043d\u0430\u0440\u0438\u0441\u043e\u0432\u0430\u043b \u0434\u0432\u0435 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u2014 \u043c\u0438\u043d\u044b \u0438 \u0444\u043b\u0430\u0433\u0430. \u0412\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u00ab\u0432\u0440\u0443\u0447\u043d\u0443\u044e\u00bb \u043f\u0440\u044f\u043c \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u041e\u0431\u044a\u0435\u0434\u0435\u043d\u0438\u043b \u0438\u0445 \u0432 \u043e\u0434\u0438\u043d \u0441\u043f\u0440\u0430\u0439\u0442 \u0434\u043b\u044f \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043f\u0440\u0435\u0434\u0437\u0430\u0433\u0440\u0443\u0436\u0443 \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u0412 \u043a\u043e\u0434\u0435 \u0442\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0430\u0440\u0435\u0437\u043a\u0443 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <a href=\"https:\/\/github.com\/theshock\/atomjs\/blob\/master\/Docs\/En\/Declare\/ImagePreloader.md\">atom.ImagePreloader<\/a>:<\/p>\n<pre><code>\/** @class Mines.Controller *\/ atom.declare( 'Mines.Controller', { \tinitialize: function () { \t\tatom.ImagePreloader.run({ \t\t\tflag: 'flag-mine.png [48:48]{0:0}', \t\t\tmine: 'flag-mine.png [48:48]{1:0}' \t\t}, this.start.bind(this) ); \t},  \tstart: function (images) { \t\tthis.images = images; \t} }); <\/code><\/pre>\n<h2>\u041e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430<\/h2>\n<p>  \u042f \u043b\u044e\u0431\u043b\u044e \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u043f\u0440\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u0441 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043a \u043b\u043e\u0433\u0438\u043a\u0435. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448 \u043a\u043e\u0434 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f <a href=\"https:\/\/github.com\/theshock\/libcanvas\/tree\/master\/Docs\/Ru\/Engines\/Tile\"><code>LibCanvas.Engines.Tile<\/code><\/a>. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043b\u0430\u0441\u0441 <code>View<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0430\u0448 \u0434\u0432\u0438\u0436\u043e\u043a. \u0422\u0430\u043a\u0436\u0435 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u0434\u0432\u0438\u0436\u043e\u043a \u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>TileEngine.Element.app<\/code>. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0435. \u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u0442\u043e\u0442 <code>View<\/code>, \u0432 \u043d\u0430\u0448\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435.<\/p>\n<pre><code>\/** @class Mines.View *\/ atom.declare( 'Mines.View', { \tinitialize: function (controller, fieldSize) { \t\tthis.images = controller.images;  \t\tthis.engine = new TileEngine({ \t\t\tsize: fieldSize, \t\t\tcellSize: new Size(24, 24), \t\t\tcellMargin: new Size(0, 0), \t\t\tdefaultValue: 'closed' \t\t}) \t\t.setMethod( this.createMethods() );  \t\tthis.app = new App({ \t\t\tsize  : this.engine.countSize(), \t\t\tsimple: true \t\t});  \t\tthis.element = TileEngine.Element.app( this.app, this.engine ); \t}, <\/code><\/pre>\n<pre><code>\/** @class Mines.Controller *\/  \/\/ ...  \tstart: function (images) { \t\tthis.images = images; \t\tthis.view = new Mines.View( this, new Size(15,8) ); \t}  <\/code><\/pre>\n<p>  \u041d\u0435 \u0442\u043e\u0440\u043e\u043f\u0438\u0442\u0435\u0441\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434, \u0443 \u043d\u0430\u0441 \u0435\u0449\u0451 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u043c\u0435\u0442\u043e\u0434 <code>createMethods<\/code> \u043a\u043b\u0430\u0441\u0441\u0430 <code>View<\/code>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u043e\u043e\u0431\u0449\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c\u0441\u044f \u0441 \u0442\u0435\u043c, \u043a\u0430\u043a\u0438\u0435 \u0443 \u043d\u0430\u0441 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u044f\u0447\u0435\u0439\u043a\u0438. <\/p>\n<p>  \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0438\u0433\u0440\u044b \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0438\u0434\u0435\u0442\u044c \u0442\u0430\u043a\u043e\u0435:<\/p>\n<p>  1. \u0427\u0438\u0441\u043b\u0430 \u043e\u0442 1 \u0434\u043e 8.<br \/>  2. \u0417\u0430\u043a\u0440\u044b\u0442\u0430\u044f \u044f\u0447\u0435\u0439\u043a\u0430<br \/>  3. \u041e\u0442\u043a\u0440\u044b\u0442\u0430\u044f, \u043d\u043e \u043f\u0443\u0441\u0442\u0430\u044f \u044f\u0447\u0435\u0439\u043a\u0430<br \/>  4. \u0424\u043b\u0430\u0436\u043e\u043a<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0435\u0451 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u2014 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<p>  1. \u0412\u0441\u0435 \u043c\u0438\u043d\u044b<br \/>  2. \u0415\u0441\u043b\u0438 \u043f\u043e\u0434\u043e\u0440\u0432\u0430\u043b\u0438\u0441\u044c \u043d\u0430 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445 \u2014 \u043e\u043d\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0430<br \/>  3. \u0415\u0441\u043b\u0438 \u0433\u0434\u0435-\u0442\u043e \u043d\u0435\u0432\u0435\u0440\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u0444\u043b\u0430\u0433<\/p>\n<p>  \u0418\u0442\u043e\u0433\u043e, 8 + 3 + 3 = 14 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439. \u041e\u043f\u0438\u0448\u0435\u043c \u0438\u0445 \u0432\u0441\u0435:<\/p>\n<pre><code>\/** @class Mines.View *\/  \/\/ ...  \tcreateMethods: function () { \t\treturn { \t\t\t1: this.number.bind(this, 1), \t\t\t2: this.number.bind(this, 2), \t\t\t3: this.number.bind(this, 3), \t\t\t4: this.number.bind(this, 4), \t\t\t5: this.number.bind(this, 5), \t\t\t6: this.number.bind(this, 6), \t\t\t7: this.number.bind(this, 7), \t\t\t8: this.number.bind(this, 8), \t\t\texplode : this.explode.bind(this), \t\t\tclosed  : this.closed .bind(this), \t\t\tmine    : this.mine   .bind(this), \t\t\tflag    : this.flag   .bind(this), \t\t\tempty   : this.empty  .bind(this), \t\t\twrong   : this.wrong  .bind(this) \t\t}; \t}, <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b <code>View<\/code>, \u043f\u0440\u0438\u0431\u0438\u043d\u0434\u0438\u0432 \u0438\u0445 \u043a \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u2014 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043a\u043b\u0435\u0442\u043a\u0438 \u043d\u0430 \u043f\u043e\u043b\u0435.<\/p>\n<pre><code>\/** @class Mines.Controller *\/ \/\/ ... \tstart: function (images) { \t\t\/\/ ...  \t\t\/\/ todo: remove after debug \t\t'1 2 3 4 5 6 7 8 empty mine flag explode wrong closed' \t\t\t.split(' ') \t\t\t.forEach(function (name, i) { \t\t\t\tthis.view.engine \t\t\t\t\t.getCellByIndex(new Point(i, 3)) \t\t\t\t\t.value = name; \t\t\t}.bind(this)); <\/code><\/pre>\n<p>  \u041c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0437\u044f\u043b\u0438 \u0432\u0441\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0438 \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u043b\u0438 \u0438\u0445 \u043f\u043e-\u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0440\u0430\u0437\u043d\u044b\u043c \u043a\u043b\u0435\u0442\u043a\u0430\u043c \u043f\u043e\u043b\u044f. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430. \u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u00ab\u0440\u0430\u0441\u0441\u043a\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c\u00bb \u044f\u0447\u0435\u0439\u043a\u0443 \u2014 \u0437\u0430\u043b\u0438\u0432\u0430\u0442\u044c \u0438 \u043e\u0431\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c \u0446\u0432\u0435\u0442\u043e\u043c. \u0415\u0441\u043b\u0438 \u043b\u0438\u043d\u0438\u044f \u0448\u0438\u0440\u0438\u043d\u043e\u0439 \u0432 1 \u043f\u0438\u043a\u0441\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0446\u0435\u043b\u044b\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u2014 \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0431\u043b\u0443\u0440\u0438\u0442\u044c\u0441\u044f <font color=\"#666\">(\u0441\u043c <a href=\"http:\/\/htmlbook.ru\/html5\/canvas\">htmlbook.ru\/html5\/canvas<\/a>, \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u00ab\u0412. \u041f\u043e\u0447\u0435\u043c\u0443 \u043c\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c x \u0438 y c 0.5, \u0430 \u043d\u0435 \u0441 0?\u00bb)<\/font>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u0430 <code>snapToPixel<\/code><\/p>\n<pre><code>\/** @class Mines.View *\/ \/\/ ... \tcolor: function (ctx, cell, fillStyle, strokeStyle) { \t\tvar strokeRect = cell.rectangle.clone().snapToPixel();  \t\treturn ctx \t\t\t.fill( cell.rectangle, fillStyle) \t\t\t.stroke( strokeRect, strokeStyle ); \t}, <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e-\u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u044b \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438. \u041f\u0443\u0441\u0442\u0430\u044f \u043a\u043b\u0435\u0442\u043a\u0430 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0440\u0430\u0441\u0438\u043c:<\/p>\n<pre><code>\/** @class Mines.View *\/ \/\/ ... \tempty: function (ctx, cell) { \t\treturn this.color(ctx, cell, '#999', '#aaa'); \t}, <\/code><\/pre>\n<p>  \u041c\u0438\u043d\u0430 \u0438 \u0444\u043b\u0430\u0433 \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u043d\u0430 \u043f\u0443\u0441\u0442\u043e\u0439 \u043a\u043b\u0435\u0442\u043a\u0435:<\/p>\n<pre><code>\/** @class Mines.View *\/ \/\/ ... \tmine: function (ctx, cell) { \t\treturn this \t\t\t.empty(ctx, cell) \t\t\t.drawImage( this.images.get('mine'), cell.rectangle ); \t},  \tflag: function (ctx, cell) { \t\treturn this \t\t\t.empty(ctx, cell) \t\t\t.drawImage( this.images.get('flag'), cell.rectangle ); \t}, <\/code><\/pre>\n<p>  \u041c\u0438\u043d\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u043f\u043e\u0434\u043e\u0440\u0432\u0430\u043b\u0438\u0441\u044c \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043a\u0440\u0430\u0441\u043d\u044b\u043c \u0444\u043e\u043d\u043e\u043c:<\/p>\n<pre><code>\/** @class Mines.View *\/ \/\/ ... \texplode: function (ctx, cell) { \t\treturn this \t\t\t.color(ctx, cell, '#c00', '#aaa') \t\t\t.drawImage( this.images.get('mine'), cell.rectangle ); \t}, <\/code><\/pre>\n<p>  \u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0444\u043b\u0430\u0433 \u2014 \u043a\u0440\u0430\u0441\u043d\u044b\u0439 \u043a\u0440\u0435\u0441\u0442. \u041e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u2014 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0443 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u0430 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>clip<\/code>.<br \/>  \u0417\u0430\u043b\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0444\u043e\u043d\u043e\u043c, \u0430 \u043f\u043e\u0442\u043e\u043c \u0440\u0438\u0441\u0443\u0435\u043c \u0434\u0432\u0435 \u043a\u0440\u0430\u0441\u043d\u044b\u0445 \u043b\u0438\u043d\u0438\u0438 \u2014 \u0441 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e-\u043b\u0435\u0432\u043e\u0433\u043e \u0432 \u043d\u0438\u0436\u043d\u0438\u0439-\u043f\u0440\u0430\u0432\u044b\u0439 \u0438 \u0441 \u043d\u0438\u0436\u043d\u0435\u0433\u043e-\u043b\u0435\u0432\u043e\u0433\u043e \u0443\u0433\u043b\u0430 \u0432 \u0432\u0435\u0440\u0445\u043d\u0438\u0439-\u043f\u0440\u0430\u0432\u044b\u0439.<\/p>\n<pre><code>\/** @class Mines.View *\/ \/\/ ... \twrong: function (ctx, cell) { \t\tvar r = cell.rectangle;  \t\treturn this.empty(ctx, cell) \t\t\t.save() \t\t\t.clip( r ) \t\t\t.set({ lineWidth: Math.round(cell.rectangle.width \/ 8) }) \t\t\t.stroke( new Line( r.from      , r.to       ), '#900' ) \t\t\t.stroke( new Line( r.bottomLeft, r.topRight ), '#900' ) \t\t\t.restore(); \t}, <\/code><\/pre>\n<p>  \u0417\u0430\u043a\u0440\u044b\u0442\u0430\u044f \u044f\u0447\u0435\u0439\u043a\u0430 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u0436\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u2014 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442 \u043e\u0442 \u0442\u0451\u043c\u043d\u043e\u0433\u043e \u043a \u0441\u0432\u0435\u0442\u043b\u043e\u043c\u0443, \u0441 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e-\u043b\u0435\u0432\u043e\u0433\u043e \u0443\u0433\u043b\u0430 \u0432 \u043d\u0438\u0436\u043d\u0438\u0439-\u043f\u0440\u0430\u0432\u044b\u0439.<\/p>\n<pre><code>\/** @class Mines.View *\/ \/\/ ... \tclosed: function (ctx, cell) { \t\treturn ctx.fill( cell.rectangle, \t\t\tctx.createGradient(cell.rectangle, { \t\t\t\t0: '#eee', 1: '#aaa' \t\t\t}) \t\t); \t}, <\/code><\/pre>\n<p>  \u0418, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0446\u0438\u0444\u0440\u044b. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0432 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0446\u0432\u0435\u0442\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0446\u0438\u0444\u0440\u044b. \u041d\u0443\u043b\u044f \u043d\u0435\u0442\u0443, \u043f\u043e\u0442\u043e\u043c\u0443 \u0441\u0442\u0430\u0432\u0438\u043c \u043d\u0443\u043b.<br \/>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0443 \u043d\u0430\u0441 <code>number<\/code>. \u0418\u043c\u0435\u043d\u043d\u043e \u0435\u0433\u043e \u043c\u044b \u0431\u0438\u043d\u0434\u0438\u043b\u0438 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <code>createMethods<\/code>.<br \/>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0440\u0438\u0441\u0443\u0435\u043c \u043a\u043b\u0435\u0442\u043a\u0443, \u043a\u0430\u043a \u043f\u0443\u0441\u0442\u0443\u044e, \u0430 \u0441\u0432\u0435\u0440\u0445\u0443, \u0442\u0435\u043a\u0441\u0442\u043e\u043c, \u043f\u0438\u0448\u0435\u043c \u0446\u0438\u0444\u0440\u0443.<\/p>\n<pre><code>\/** @class Mines.View *\/ \/\/ ... \tnumberColors: [null, '#009', '#060', '#550', '#808', '#900', '#555', '#055', '#000' ],  \tnumber: function (number, ctx, cell) { \t\tvar size = Math.round(cell.rectangle.height * 0.8);  \t\treturn this.empty(ctx, cell) \t\t\t.text({ \t\t\t\ttext  : number, \t\t\t\tcolor : this.numberColors[number], \t\t\t\tsize  : size, \t\t\t\tlineHeight: size, \t\t\t\tweight: 'bold', \t\t\t\talign : 'center', \t\t\t\tto    : cell.rectangle \t\t\t}); \t} <\/code><\/pre>\n<p>  \u041d\u0430\u0448\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043c\u0435\u043d\u044f\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u044f\u0447\u0435\u0435\u043a \u0438 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/b12\/4ff\/1e9\/b124ff1e91a22fad7c68c04a8e56e07f.png\"\/><\/p>\n<h2>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043c\u0438\u043d<\/h2>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0433\u043e\u0442\u043e\u0432\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0438 \u043a\u043b\u0435\u0442\u043a\u0430 \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u0439 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0432\u0438\u0434.<\/p>\n<p>  \u0423\u0434\u0430\u043b\u0438\u043c \u043d\u0430\u0448 \u0434\u0435\u0431\u0430\u0433-\u043a\u043e\u0434 \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438\u043d\u0441\u0442\u0430\u043d\u0441 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430:  <\/p>\n<pre><code>\/** @class Mines.Controller *\/ \/\/ .. \tstart: function (images) { \t\tthis.images = images; \t\t \t\tthis.size  = new Size(15, 8); \t\tthis.mines = 20;  \t\tthis.view = new Mines.View( this, this.size ); \t\tthis.generator = new Mines.Generator( this.size, this.mines ); \t} <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u0440\u0430\u0437\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u043f\u043e \u043f\u043e\u043b\u044e \u043c\u0438\u043d\u044b. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0431\u044b\u043b\u043e \u0431\u044b \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u044f\u043a\u0438\u0435 \u0441\u043e\u043c\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043d\u043e \u043f\u043e\u043a\u0430 \u0443 \u043d\u0430\u0441 \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u043e\u0434\u043d\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435 \u2014 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0435 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043a\u043b\u0438\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0442\u043e\u0442 \u043d\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u043b\u0441\u044f \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u043d\u0430 \u043c\u0438\u043d\u0443.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/4de\/eed\/e8a\/4deeede8a775c77b53bbaf4561dd8163.png\"\/><\/p>\n<p>  \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u0438\u043d \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u2014 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a (\u0432\u0441\u0435, \u043a\u0440\u043e\u043c\u0435 \u0442\u043e\u0439, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043a\u043b\u0438\u043a\u043d\u0443\u043b\u0438) \u2014 \u043c\u0435\u0442\u043e\u0434 <code>snapshot<\/code>, \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u00ab\u0432\u044b\u0434\u0451\u0440\u0433\u0438\u0432\u0430\u0435\u043c\u00bb \u0438\u0437 \u043d\u0438\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u2014 \u043c\u0435\u0442\u043e\u0434 <code>createMines<\/code>:  <\/p>\n<pre><code>\/** @class Mines.Generator *\/ atom.declare( 'Mines.Generator', {  \tmines: null,  \tinitialize: function (fieldSize, minesCount) { \t\tthis.fieldSize  = fieldSize; \t\tthis.minesCount = minesCount; \t},  \t\/** @private *\/ \tsnapshot: function (ignore) { \t\tvar x, y, point, \t\t\tresult = [], \t\t\tsize = this.fieldSize;  \t\tfor (y = size.height; y--;) for (x = size.width; x--;) { \t\t\tpoint = new Point(x, y);  \t\t\tif (!point.equals(ignore)) { \t\t\t\tresult.push(point); \t\t\t} \t\t}  \t\treturn result; \t},  \t\/** @private *\/ \tcreateMines: function (count, ignore) { \t\tvar snapshot = this.snapshot( ignore );  \t\treturn atom.array.create(count, function () { \t\t\treturn snapshot.popRandom(); \t\t}); \t}  }); <\/code><\/pre>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0430\u0433 \u2014 \u044d\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c api-\u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u044d\u0442\u0438\u0445 \u043c\u0438\u043d \u0438 \u0437\u0430\u043d\u043e\u0441\u0438\u0442\u044c \u0438\u0445 \u0432 \u0438\u043d\u0434\u0435\u043a\u0441 \u0434\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0439 \u0445\u0435\u0448 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 1, \u0433\u0434\u0435 \u043c\u0438\u043d\u0430 \u0435\u0441\u0442\u044c \u0438 0, \u0433\u0434\u0435 \u043c\u0438\u043d\u044b \u043d\u0435\u0442\u0443. \u041d\u0430\u043c \u0432\u0430\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e Integer, \u043f\u0440\u0438\u0447\u0438\u043d\u0443 \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u043d\u0438\u0436\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>isMine<\/code> \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f, \u0435\u0441\u0442\u044c \u043b\u0438 \u043c\u0438\u043d\u0430 \u043f\u043e \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0435. \u041c\u0435\u0442\u043e\u0434 <code>isReady<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u0430\u043c, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u043b\u0438 \u0443\u0436\u0435 \u043c\u0438\u043d\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.<\/p>\n<pre><code>\/** @class Mines.Generator *\/ \/\/ .. \t \tisReady: function () { \t\treturn this.mines != null; \t},  \tisMine: function (point) { \t\treturn this.mines[point.y][point.x]; \t},  \tgenerate: function (ignore) { \t\tvar mines, minesIndex, \t\t\tsize = this.fieldSize;  \t\tmines = this.createMines(this.minesCount, ignore);  \t\tminesIndex = atom.array.fillMatrix(size.width, size.height, 0);  \t\tmines.forEach(function (point) { \t\t\tminesIndex[point.y][point.x] = 1; \t\t});  \t\tthis.mines = minesIndex; \t}, <\/code><\/pre>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0430\u0433 \u2014 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043b\u0435\u0442\u043a\u0438, \u0435\u0441\u043b\u0438 \u0442\u0430\u043c \u043c\u0438\u043d\u044b \u043d\u0435\u0442. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442 \u2014 \u0431\u0435\u0440\u0451\u043c \u0432\u0441\u0435\u0445 \u0441\u043e\u0441\u0435\u0434\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0432\u044b\u0445\u043e\u0434\u044f\u0442 \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u043f\u043e\u043b\u044f, \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0441\u0443\u043c\u0443 \u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0418\u043c\u0435\u043d\u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0442\u043e, \u0447\u0442\u043e \u043c\u0438\u043d\u0430 \u0435\u0441\u0442\u044c Integer \u043d\u0430\u043c \u0438 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u043b\u043e\u0441\u044c. <\/p>\n<pre><code>\/** @class Mines.Generator *\/ \/\/ .. \tinitialize: function (fieldSize, minesCount) { \t\t\/\/ \u044d\u0442\u0438 \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u043a\u0430\u043a \u043a\u043e\u043b\u0431\u0435\u043a\u0438, \u043f\u043e\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0432\u044f\u0436\u0435\u043c \u0438\u0445 \u043a \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443 \t\tthis.bindMethods([ 'isValidPoint', 'isMine' ]);   \/\/ .. \tgetValue: function (point) { \t\t\/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435\u0445 \u0441\u043e\u0441\u0435\u0434\u0435\u0439 \t\treturn this.getNeighbours(point) \t\t\t\/\/ \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0438\u0445 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u0438\u043d (1 \u0438 0) \t\t\t.map(this.isMine) \t\t\t\/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u0438\u043d \u0432 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u043a\u043b\u0435\u0442\u043a\u0430\u0445 \t\t\t.sum(); \t},  \t\/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u0442\u043e\u0447\u043a\u0430 \u043d\u0435 \u0432\u044b\u0448\u043b\u0430 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u043f\u043e\u043b\u044f \tisValidPoint: function (point) { \t\treturn point.x &gt;= 0 \t\t\t&& point.y &gt;= 0 \t\t\t&& point.x &lt; this.fieldSize.width \t\t\t&& point.y &lt; this.fieldSize.height; \t},  \t\/\/ \u0421\u043f\u0438\u0441\u043e\u043a \u0441\u043e\u0441\u0435\u0434\u0435\u0439 - \u044d\u0442\u043e \u0432\u0441\u0435 \u0441\u043e\u0441\u0435\u0434\u0438, \u043a\u0440\u043e\u043c\u0435 \u0442\u0435\u0445, \u0447\u0442\u043e \u0432\u044b\u0445\u043e\u0434\u044f\u0442 \u0437\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \tgetNeighbours: function (point) { \t\treturn point.neighbours.filter( this.isValidPoint ); \t}, <\/code><\/pre>\n<h2>\u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c<\/h2>\n<p>  \u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0432\u0438\u0436\u043e\u043a \u0438\u0433\u0440\u044b, \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u0441\u0451 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0433\u0440\u043e\u0439, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u043e\u0433\u0438\u043a\u043e\u0439. \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043b\u0430\u0441\u0441 <code>Action<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u0437\u0430 \u0432\u0441\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u2014 \u044d\u0442\u043e \u0440\u0435\u0430\u043a\u0446\u0438\u044e \u043d\u0430 \u043a\u043b\u0438\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>TileEngine.Mouse<\/code> \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043b\u0443\u0448\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043c\u044b\u0448\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043b\u0435\u043c. \u0412\u0435\u0448\u0430\u0435\u043c <code>Mouse.prevent<\/code> \u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 <code>'contextmenu'<\/code>, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0432\u044b\u0441\u043a\u0430\u043a\u0438\u0432\u0430\u043b\u043e \u043d\u0430\u0434\u043e\u0435\u0434\u043b\u0438\u0432\u043e\u0435 \u043c\u0435\u043d\u044e. \u041f\u0440\u0438 \u043a\u043b\u0438\u043a\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043a\u043d\u043e\u043f\u043a\u0443. \u041b\u0435\u0432\u0430\u044f \u043a\u043d\u043e\u043f\u043a\u0430 \u043c\u044b\u0448\u0438 \u0440\u0430\u0432\u043d\u0430 0, \u0441\u0440\u0435\u0434\u043d\u044f\u044f \u0440\u0430\u0432\u043d\u0430 1, \u043f\u0440\u0430\u0432\u0430\u044f \u0440\u0430\u0432\u043d\u0430 2. \u041d\u0430\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u0433\u0440\u0435 \u043a\u043b\u0438\u043a \u043b\u0435\u0432\u043e\u0439 \u043e\u0437\u043d\u0430\u0447\u0430\u043b \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u043a\u043b\u0435\u0442\u043a\u0438, \u043a\u0440\u0438\u043a \u0441\u0440\u0435\u0434\u043d\u0435\u0439 \u2014 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0432\u0441\u0435\u0445 \u043e\u043a\u0440\u0443\u0436\u0430\u044e\u0449\u0438\u0445, \u0430 \u043a\u043b\u0438\u043a \u043f\u0440\u0430\u0432\u043e\u0439 \u2014 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043c\u0438\u043d\u044b.<\/p>\n<pre><code>\/** @class Mines.Controller *\/ \/\/ .. \tstart: function (images) { \t\t\/\/ .. \t\tthis.action = new Mines.Action(this); \t} <\/code><\/pre>\n<pre><code>\/** @class Mines.Action *\/ atom.declare( 'Mines.Action', { \tactions: [ 'open', 'all', 'close' ],  \tinitialize: function (controller) { \t\tthis.controller = controller; \t\tthis.bindMouse(); \t},  \tbindMouse: function () { \t\tvar view, mouse;  \t\tview = this.controller.view; \t\tmouse = new Mouse(view.app.container.bounds);  \t\tnew App.MouseHandler({ mouse: mouse, app: view.app }) \t\t\t.subscribe( view.element );  \t\tmouse.events.add( 'contextmenu', Mouse.prevent );  \t\tnew TileEngine.Mouse( view.element, mouse ).events \t\t\t.add( 'click', function (cell, e) { \t\t\t\tthis.activate(cell, e.button); \t\t\t}.bind(this)); \t},  \tactivate: function (cell, actionCode) { \t\tconsole.log( cell.point.dump(), actionCode ); \t} }); <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0435\u0440\u0432\u0443\u044e \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0438, \u0437\u0430\u043e\u0434\u043d\u043e \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u2014 <code>close<\/code>. \u0415\u0441\u043b\u0438 \u043a\u043b\u0435\u0442\u043a\u0430 \u0437\u0430\u043a\u0440\u044b\u0442\u0430, \u0442\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043d\u0430 \u043d\u0435\u0451 \u0444\u043b\u0430\u0433, \u0435\u0441\u043b\u0438 \u043d\u0430 \u043a\u043b\u0435\u0442\u043a\u0435 \u0443\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u0444\u043b\u0430\u0433, \u0442\u043e \u043e\u0442\u043c\u0435\u0447\u0430\u0435\u043c \u0435\u0451 \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0439. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043f\u0435\u0440\u0432\u043e\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u2014 \u043f\u043e \u043f\u0440\u0430\u0432\u043e\u0439 \u043a\u043d\u043e\u043f\u043a\u0435 \u043c\u044b\u0448\u0438 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0444\u043b\u0430\u0433 \u043d\u0430 \u043a\u043b\u0435\u0442\u043a\u0435.<\/p>\n<pre><code>\/** @class Mines.Action *\/  \/\/ ...  \tactivate: function (cell, actionCode) { \t\tif (typeof actionCode == 'number') { \t\t\tactionCode = this.actions[actionCode]; \t\t}  \t\tthis[actionCode](cell); \t},  \tclose: function (cell) { \t\tif (cell.value == 'closed') { \t\t\tcell.value = 'flag'; \t\t} else if (cell.value == 'flag') { \t\t\tcell.value = 'closed'; \t\t} \t},  \topen: function (cell) {  \t},  \tall: function (cell) {  \t} <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u0438\u0448\u0435\u043c \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u043a\u043b\u0435\u0442\u043a\u0438. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u043a\u043b\u0435\u0442\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u044b. \u041d\u0435\u0447\u0435\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0432\u0441\u044f\u043a\u0438\u043c\u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u043c\u0438 \u0446\u0438\u0444\u0440\u0430\u043c\u0438 \u0438 \u0444\u043b\u0430\u0433\u0430\u043c\u0438. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0433\u043e\u0442\u043e\u0432\u044b \u043b\u0438 \u043d\u0430\u0448\u0438 \u043c\u0438\u043d\u044b \u0438, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u2014 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0430 \u043c\u0438\u043d\u0430, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>lose<\/code>, \u0433\u0434\u0435 \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u043c \u043a\u043b\u0435\u0442\u043a\u0443, \u043a\u0430\u043a \u0432\u0437\u043e\u0440\u0432\u0430\u0432\u0448\u0443\u044e\u0441\u044f.<br \/>  \u0415\u0441\u043b\u0438 \u0432 \u043a\u043b\u0435\u0442\u043a\u0435 \u0435\u0441\u0442\u044c \u0446\u0438\u0444\u0440\u0430, \u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0438\u0448\u0435\u043c \u0435\u0451, \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0441 \u044d\u0442\u043e\u0439 \u043a\u043b\u0435\u0442\u043a\u043e\u0439 \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<br \/>  \u0415\u0441\u043b\u0438 \u043a\u043b\u0435\u0442\u043a\u0430 \u043f\u0443\u0441\u0442\u0430, \u0442\u043e \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043a\u043b\u0435\u0442\u043a\u0438 \u0432\u043e\u043a\u0440\u0443\u0433, \u043f\u043e\u0442\u043e\u043c\u0443 \u043f\u043e\u043a\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043c\u0435\u0442\u043e\u0434 \u0438 \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u043c \u043a\u043b\u0435\u0442\u043a\u0443 \u043a\u0430\u043a \u043f\u0443\u0441\u0442\u0443\u044e.<\/p>\n<pre><code>\/** @class Mines.Action *\/  \/\/ ...  \topen: function (cell) { \t\tif (cell.value != 'closed') return; \t\t \t\tvar value, gen = this.controller.generator;  \t\tif (!gen.isReady()) { \t\t\tgen.generate(cell.point); \t\t}  \t\tif (gen.isMine(cell.point)) { \t\t\tthis.lose(cell); \t\t} else { \t\t\tvalue = gen.getValue(cell.point);  \t\t\tif (value) { \t\t\t\tcell.value = value; \t\t\t} else { \t\t\t\tthis.openEmpty(cell); \t\t\t} \t\t} \t},  \tlose: function () { \t\tcell.value = 'explode'; \t},  \topenEmpty: function (cell) { \t\tcell.value = 'empty'; \t}, <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u0432\u0441\u0435\u0445 \u043a\u043b\u0435\u0442\u043e\u043a \u0432\u043e\u043a\u0440\u0443\u0433 \u043f\u0443\u0441\u0442\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043e\u0441\u0435\u0434\u0435\u0439 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432 \u043c\u0435\u0442\u043e\u0434 <code>open<\/code>. \u042d\u0442\u0438\u043c \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0434\u043b\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0433\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u043f\u0443\u0441\u0442\u044b\u0445 \u043a\u043b\u0435\u0442\u043e\u043a \u0438 \u0434\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u043f\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u0439 \u043a\u043d\u043e\u043f\u043a\u0435 \u043c\u044b\u0448\u0438.<\/p>\n<pre><code>\/** @class Mines.Action *\/  \/\/ ... \topenNeighbours: function (cell) { \t\tthis.controller.generator \t\t\t.getNeighbours(cell.point) \t\t\t.forEach(function (point) { \t\t\t\tthis.open( this.getCell(point) ); \t\t\t}.bind(this)); \t},  \topenEmpty: function (cell) { \t\tcell.value = 'empty';  \t\tthis.openNeighbours(cell); \t},  \tgetCell: function (point) { \t\treturn this.controller.view.engine.getCellByIndex(point); \t},  \tall: function (cell) { \t\tif (parseInt(cell.value)) { \t\t\tthis.openNeighbours(cell); \t\t} \t}, <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0438\u0433\u0440\u044b\u0448\u044c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u0442\u0430\u043a \u2014 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u0432\u0441\u0435 \u043a\u043b\u0435\u0442\u043a\u0438, \u0433\u0434\u0435 \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u043e \u0438 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0431\u044b\u043b\u0430 \u043c\u0438\u043d\u0430 \u2014 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u043c\u0438\u043d\u0443. \u0413\u0434\u0435 \u0443 \u043d\u0430\u0441 \u0441\u0442\u043e\u044f\u043b \u0444\u043b\u0430\u0433, \u0430 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043c\u0438\u043d\u044b \u043d\u0435\u0442\u0443 \u2014 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443. \u0422\u0430\u043a \u0436\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u044b <code>open<\/code> \u0438 <code>close<\/code> \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0448\u0430.<\/p>\n<pre><code>\/** @class Mines.Action *\/  \/\/ ... \tlost: false, \t \tlose: function (cell) { \t\tthis.lost = true; \t\t \t\tcell.value = 'explode';  \t\tthis.controller.view.engine.cells \t\t\t.forEach(this.checkCell.bind(this)); \t},  \tcheckCell: function (cell) { \t\tif (cell.value == 'closed' || cell.value == 'flag') { \t\t\tvar isMine = this.controller.generator.isMine(cell.point); \t\t\t \t\t\tif (isMine && cell.value == 'closed') { \t\t\t\tcell.value = 'mine'; \t\t\t} \t\t\tif (!isMine && cell.value == 'flag') { \t\t\t\tcell.value = 'wrong'; \t\t\t} \t\t} \t},   \/\/ ... \tclose: function (cell) { \t\tif (this.lost) return; \/\/ ... \topen: function (cell) { \t\tif (this.lost) return; \/\/ ... <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/567\/62b\/32c\/56762b32c5c67733cb4c0879c1301fa3.png\"\/><\/p>\n<h2>\u041f\u043e\u0431\u0435\u0434\u0430!<\/h2>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u043f\u043e\u0431\u0435\u0434\u0443, \u0437\u0430\u0442\u0440\u0430\u0447\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0438 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u0438\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u044c. \u041d\u0435 \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043c\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0432\u0438\u0434\u043e\u043c, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0433\u0438\u043a\u043e\u0432\u0441\u043a\u0438\u043c, \u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u043c <code>atom.trace<\/code>. \u041f\u043e\u043b\u0443\u0447\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u0438\u043d. \u041f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0443\u0441\u0442\u044b\u0445 \u043a\u043b\u0435\u0442\u043e\u043a \u2014 \u044d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0435\u0442\u043e\u043a \u0432\u0441\u0435\u0433\u043e \u043c\u0438\u043d\u0443\u0441 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u0438\u043d. \u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0438 \u043a\u043b\u0435\u0442\u043a\u0438 \u0431\u0443\u0434\u0435\u043c \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0443\u0441\u0442\u044b\u0445 \u043d\u0430 \u043e\u0434\u0438\u043d. \u041a\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442 \u043d\u0443\u043b\u044f \u2014 \u0438\u0433\u0440\u0430 \u0432\u044b\u0438\u0433\u0440\u0430\u043d\u0430. \u0414\u0430\u0434\u0438\u043c \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0445\u043e\u043b\u0441\u0442\u0443 \u0438 \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0430\u043b\u0435\u0440\u0442.<\/p>\n<pre><code>\/** @class Mines.Action *\/  \/\/ ... \tinitialize: function (controller) {  \t\t\/\/ ...  \t\tthis.startTime = null;  \t\tthis.minesLeft = controller.mines; \t\tthis.minesTrace = atom.trace(0); \t\tthis.changeMines(0);  \t\tthis.emptyCells = controller.size.width * controller.size.height - this.minesLeft; \t},  \tchangeMines: function (delta) { \t\tthis.minesLeft += delta; \t\tthis.minesTrace.value = &quot;Mines: &quot; + this.minesLeft; \t},  \t\/\/ ...  \topen: function (cell) { \t\t\/\/ ...  \t\tif (!gen.isReady()) { \t\t\t\/\/ ... \t\t\tthis.startTime = Date.now(); \t\t}  \t\tif (gen.isMine(cell.point)) { \t\t\t\/\/ ... \t\t} else { \t\t\t\/\/ ...  \t\t\tif (--this.emptyCells == 0) { \t\t\t\tthis.win(); \t\t\t} \t\t} \t},  \t\/\/ ... \twin: function () { \t\tvar time = Math.round( (Date.now()-this.startTime) \/ 1000 ); \t\talert.delay(100, window, ['Congratulations! Mines has been neutralized in '+ time +' sec!']); \t},  \t\/\/ ... \tclose: function (cell) { \t\t\/\/ ...  \t\tif (cell.value == 'closed') { \t\t\t\/\/ ... \t\t\tthis.changeMines(-1); \t\t} else if (cell.value == 'flag') { \t\t\t\/\/ ... \t\t\tthis.changeMines(+1); \t\t} \t}, <\/code><\/pre>\n<h2><a href=\"http:\/\/libcanvas.github.com\/games\/mines\/\">\u0418\u0433\u0440\u0430\u0442\u044c \u0432 \u0441\u0430\u043f\u0451\u0440<\/a><\/h2>\n<div class=\"polling\">\n<form action=\"\/json\/polling\/\" class=\"poll\" method=\"post\">\n<div class=\"poll_title\">\u041d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u043b\u0438 \u0432\u0430\u043c \u0444\u043e\u0440\u043c\u0430\u0442 \u0442\u043e\u043f\u0438\u043a\u0430 \u00ab\u041a\u0440\u0430\u0442\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 + \u041a\u0443\u0441\u043e\u043a \u043a\u043e\u0434\u0430\u00bb?<\/div>\n<p>  \t\t<input type=\"hidden\" name=\"post_id\" value=\"168435\"\/> \t\t<input type=\"hidden\" name=\"polling_question_id\" value=\"7121\"\/>  \t\t<\/p>\n<table class=\"answer\">\n<tr>\n<td class=\"input\"> \t\t\t\t\t<input type=\"radio\" id=\"vv37231\" \t\t\t\t\t\tclass=\"radio js-field-data\" \t\t\t\t\t\tname=\"variant[]\" \t\t\t\t\t\tvalue=\"37231\" \/> \t\t\t\t<\/td>\n<td class=\"label\"> \t\t\t\t\t<label for=\"vv37231\">\u0434\u0430<\/label> \t\t\t\t<\/td>\n<\/tr>\n<tr>\n<td class=\"input\"> \t\t\t\t\t<input type=\"radio\" id=\"vv37233\" \t\t\t\t\t\tclass=\"radio js-field-data\" \t\t\t\t\t\tname=\"variant[]\" \t\t\t\t\t\tvalue=\"37233\" \/> \t\t\t\t<\/td>\n<td class=\"label\"> \t\t\t\t\t<label for=\"vv37233\">\u043d\u0435\u0442<\/label> \t\t\t\t<\/td>\n<\/tr>\n<\/table>\n<p class=\"for_users_only_msg\">\u0422\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u043f\u0440\u043e\u0441\u0435. <a href=\"\/login\/\">\u0412\u043e\u0439\u0434\u0438\u0442\u0435<\/a>, \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430.<\/p>\n<p class=\"total\">\u041f\u0440\u043e\u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b 1 \u0447\u0435\u043b\u043e\u0432\u0435\u043a. \u0412\u043e\u0437\u0434\u0435\u0440\u0436\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u043d\u0435\u0442.<\/p>\n<\/p><\/form>\n<\/p><\/div>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/168435\/\"> http:\/\/habrahabr.ru\/post\/168435\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/624\/2aa\/2da\/6242aa2da8b1002ad0891b027cc282ed.png\"\/><\/p>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0430\u043c\u044b\u0439 \u043e\u0431\u044b\u0447\u043d\u044b\u0439, \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u043f\u0451\u0440 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 Html5 Canvas, AtomJS, \u0438 \u0442\u0430\u0439\u043b\u043e\u0432\u043e\u0433\u043e \u0434\u0432\u0438\u0436\u043a\u0430 LibCanvas.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-168435","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/168435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=168435"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/168435\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=168435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=168435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=168435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}