{"id":290310,"date":"2018-10-04T13:00:28","date_gmt":"2018-10-04T09:00:28","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=290310"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=290310","title":{"rendered":"\u041a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e: \u043f\u0438\u0448\u0435\u043c \u00ab\u0421\u0430\u043f\u0435\u0440\u0430\u00bb \u0437\u0430 4 \u043c\u0438\u043d\u0443\u0442\u044b"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/47d\/77b\/444\/47d77b44493995b16ccc5dd6b4e49326.jpg\" alt=\"image\"><\/p>\n<p>  <b>\u041e\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430:<\/b> \u044d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u2014 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 <a href=\"https:\/\/medium.com\/@mackycheese21\/making-minesweeper-in-10-minutes-e4c4e810fa06\">\u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438<\/a> \u041c\u0430\u043a\u0438 \u0427\u0438\u0437\u0430, \u043e\u043f\u044b\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0438\u0448\u0435\u0442 \u043a\u043b\u0430\u0441\u0441\u043d\u044b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u043d\u043e \u0438 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432 \u0441\u0432\u043e\u0438\u043c \u043a\u043e\u043b\u043b\u0435\u0433\u0430\u043c, \u043a\u0430\u043a \u043d\u043e\u0432\u0438\u0447\u043a\u0430\u043c, \u0442\u0430\u043a \u0438 \u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u0430\u043c.<\/p>\n<p>  \u00ab\u0421\u0430\u043f\u0435\u0440\u00bb \u2014 \u0432\u0435\u0441\u0435\u043b\u0430\u044f \u0438\u0433\u0440\u0430, \u043c\u043d\u043e\u0433\u0438\u0435 \u0438\u0437 \u043d\u0430\u0441 \u0432 \u043d\u0435\u0435 \u0438\u0433\u0440\u0430\u044e\u0442. \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u00ab\u0421\u0430\u043f\u0435\u0440\u0430\u00bb \u0441\u0430\u043c\u0438?<br \/>  <a name=\"habracut\"><\/a>   <\/p>\n<blockquote><p><b>Skillbox \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442:<\/b> \u041e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0443\u0440\u0441 <a href=\"https:\/\/skillbox.ru\/webdev\/?utm_source=skillbox.media&amp;utm_medium=habr.com&amp;utm_campaign=WEBDEV&amp;utm_content=articles&amp;utm_term=minesweeper\">\u00ab\u041f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u044f \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u00bb<\/a>.<br \/>  <b>\u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c:<\/b> <i>\u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 \u00ab\u0425\u0430\u0431\u0440\u0430\u00bb \u2014 \u0441\u043a\u0438\u0434\u043a\u0430 10 000 \u0440\u0443\u0431\u043b\u0435\u0439 \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0430 \u043b\u044e\u0431\u043e\u0439 \u043a\u0443\u0440\u0441 Skillbox \u043f\u043e \u043f\u0440\u043e\u043c\u043e\u043a\u043e\u0434\u0443 \u00ab\u0425\u0430\u0431\u0440\u00bb.<\/i><\/p><\/blockquote>\n<p>  \u0423\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438\u0433\u0440\u044b \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d\u0430 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u0435\u0441\u044c\u043c\u0430 \u0443\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f. \u0412 \u00ab\u0421\u0430\u043f\u0435\u0440\u0435\u00bb \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0445\u0438\u0442\u0440\u043e\u0439 \u0433\u0435\u0439\u043c\u043f\u043b\u0435\u0439\u043d\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u043a\u0438, \u0432\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0436\u0438\u043c\u0430\u0435\u0442\u0435 \u043d\u0430 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u043a\u0438, \u043d\u0430\u0434\u0435\u044f\u0441\u044c, \u0447\u0442\u043e \u043f\u043e\u0434 \u043d\u0438\u043c\u0438 \u043d\u0435\u0442 \u043c\u0438\u043d\u044b. <\/p>\n<p>  \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u00ab\u0421\u0430\u043f\u0435\u0440\u0430\u00bb \u043d\u0430 Processing. \u042d\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Java. \u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043d\u0435\u0433\u043e <a href=\"https:\/\/processing.org\/\">\u0432\u043e\u0442 \u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  \u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043d\u0430\u0447\u0430\u0442\u044c, \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d \u043d\u0430 \u0442\u0435\u0445, \u043a\u0442\u043e \u0443\u0436\u0435 \u0437\u043d\u0430\u0435\u0442 Java. \u041e\u043f\u044b\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Processing \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c. \u041f\u0435\u0440\u0432\u044b\u0439 \u0448\u0430\u0433 \u2014 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438\u0433\u0440\u044b. \u042f \u0440\u0435\u0448\u0438\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u043e\u0442 \u0442\u0430\u043a.  <\/p>\n<pre><code class=\"java\">int gridW; \/\/ grid width int gridH; \/\/ grid height int numMines; \/\/ number of mines on the board   int[][] mines; \/\/ entry is 1 for having a mine and 0 for not boolean[][] flags; \/\/ entry is true if you have flagged that spot boolean[][] revealed; \/\/ entry is true if that spot is revealed<\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c, \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0432\u0441\u0435, \u043a\u0440\u043e\u043c\u0435 \u0432\u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u043a\u0430: <i>int[][] mines<\/i>. \u041f\u043e\u0447\u0435\u043c\u0443 \u0441\u0435\u0442\u043a\u0430 \u043c\u0438\u043d \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0446\u0435\u043b\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c, \u0430 \u043d\u0435 \u0431\u0443\u043b\u0435\u0432\u044b\u043c? \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u044f\u0434\u043e\u043c \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439.  <\/p>\n<pre><code class=\"java\">int calcNear(int x, int y) {   int i=0;   for (int offsetX=-1; offsetX&lt;=1; offsetX++) {     for (int offsetY=-1; offsetY&lt;=1; offsetY++) {       i+=mines[offsetX+x][offsetY+y];     }   }   return i; }<\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u044f\u0434\u043e\u043c \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u0443\u0447\u0430\u0441\u0442\u043a\u043e\u043c. \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u044b \u0443\u0431\u0435\u0440\u0435\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u043d\u0430 \u044d\u0442\u043e:  <\/p>\n<pre><code class=\"java\">boolean outBounds(int x,int y){   return x&lt;0||y&lt;0||x&gt;=gridW||y&gt;=gridH; }   int calcNear(int x, int y) {   if(outBounds(x,y))return 0;   int i=0;   for (int offsetX=-1; offsetX&lt;=1; offsetX++) {     for (int offsetY=-1; offsetY&lt;=1; offsetY++) {       if (outBounds(offsetX+x, offsetY+y))continue;       i+=mines[offsetX+x][offsetY+y];     }   }   return i; }<\/code><\/pre>\n<p>  \u0413\u043b\u0430\u0432\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u0430\u043c\u043e\u0439 \u0438\u0433\u0440\u044b \u2014 \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u044b, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0442\u043e\u0447\u043a\u0438 \u0445, \u0443.   <\/p>\n<pre><code class=\"java\">void reveal(int x, int y){   if(outBounds(x,y))return;   if(revealed[x][y])return;   revealed[x][y]=true;   if(calcNear(x,y)!=0)return;   reveal(x-1,y-1);   reveal(x-1,y+1);   reveal(x+1,y-1);   reveal(x+1,y+1);   reveal(x-1,y);   reveal(x+1,y);   reveal(x,y-1);   reveal(x,y+1); }<\/code><\/pre>\n<p>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c:  <\/p>\n<ul>\n<li>\u0415\u0441\u043b\u0438 \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u043f\u043e\u043b\u044f, end;<\/li>\n<li>\u0415\u0441\u043b\u0438 \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0440\u0430\u0441\u043a\u0440\u044b\u0442\u0430, end;<\/li>\n<li>\u0420\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u043f\u043e\u0437\u0438\u0446\u0438\u044e;<\/li>\n<li>\u0415\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0431\u043e\u043c\u0431\u0430 \u0440\u044f\u0434\u043e\u043c \u0441 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439, end;<\/li>\n<li>\u0415\u0441\u043b\u0438 \u043c\u044b \u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u043f\u0443\u043d\u043a\u0442\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0431\u044b\u043b\u0430 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0430 \u0438 \u0440\u044f\u0434\u043e\u043c \u0441 \u043d\u0435\u0439 \u043d\u0435\u0442 \u0431\u043e\u043c\u0431, \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u043c\u0435\u0436\u043d\u044b\u0435 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u044b.<\/li>\n<\/ul>\n<p>  \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0432\u0441\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0438\u0433\u0440\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435. \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438, \u043f\u0435\u0440\u0435\u0439\u0434\u044f \u043f\u043e <a href=\"https:\/\/github.com\/mackycheese\/UbuntuProcessingProjects\/blob\/master\/MineSweeper\/MineSweeper.pde\">\u044d\u0442\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0443\u0437\u043d\u0430\u0442\u044c \u043e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<p>  <b>\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/b><\/p>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043d\u043e \u044f \u043e\u0431\u044a\u044f\u0441\u043d\u044e \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f cellSize, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0430\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0435.  <\/p>\n<pre><code class=\"java\">void settings(){   size(gridW*cellSize, gridH*cellSize); }<\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u043e\u043b\u0435 \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u0430\u043c\u0438 gridW x gridH, \u0433\u0434\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0430 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0432\u043d\u044f\u0442\u044c\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e cellSize.<\/p>\n<p>  \u0417\u0430\u0442\u0435\u043c \u043c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435.   <\/p>\n<pre><code class=\"java\">void setup(){   \/\/initialize and clear the arrays   mines=new int[gridW][gridH];   flags=new boolean[gridW][gridH];   revealed=new boolean[gridW][gridH];   for(int x=0;x&lt;gridW;x++){     for(int y=0;y&lt;gridH;y++){       mines[x][y]=0;       flags[x][y]=false;       revealed[x][y]=false;     }   } }<\/code><\/pre>\n<p>   \u0414\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044f:   <\/p>\n<pre><code class=\"java\">\/\/Place numMines mines on the grid void placeMines(){   int i=0;   while(i&lt;numMines){\/\/We don't want mines to overlap, so while loop     int x=int(random(gridW));     int y=int(random(gridH));     if(mines[x][y]==1)continue;     mines[x][y]=1;     i++;   } } \/\/Clear the mines void clearMines() {   for (int x=0; x&lt;gridW; x++) {     for (int y=0; y&lt;gridH; y++) {       mines[x][y]=0;     }   } }<\/code><\/pre>\n<p>   \u0418 \u0434\u0430\u043b\u0435\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0440\u0435\u0430\u043a\u0446\u0438\u044e \u043d\u0430 \u043a\u043b\u0438\u043a\u0438 \u043c\u044b\u0448\u044c\u044e.  <\/p>\n<pre><code class=\"java\">\/\/We don't want the first click to be a mine boolean firstClick=true;   void mousePressed() {   int x=int(mouseX\/cellSize);   int y=int(mouseY\/cellSize);   \/\/Right-click is flagging or de-flagging a square   if (mouseButton==RIGHT) {     flags[x][y]=!flags[x][y];     return;   } else {\/\/left-click     \/\/Avoid making the first click a mine     if (firstClick) {       firstClick=false;       do {         clearMines();         placeMines();       } while (calcNear(x,y)!=0);     }     \/\/Check for game loss     if (mines[x][y]!=0) {       println(\"Dang!\");       exit();     } else {\/\/If game not lost, reveal starting from that square       reveal(x, y);     }   } }<\/code><\/pre>\n<p>  \u0418 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0435\u0435 \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u0430\u0434\u0440\u0430.   <\/p>\n<pre><code class=\"java\">void draw() {   background(0);   \/\/For each cell   for (int x=0; x&lt;gridW; x++) {     for (int y=0; y&lt;gridH; y++) {       \/\/The colors alternate for texture       color col1=color(2*255\/5);       color col2=color(3*255\/5);         color txtColor=color(0);         int near=calcNear(x, y);         if (flags[x][y]) {         col1=color(255, 0, 0);         col2=color(4*255\/5, 255\/5, 255\/5);       } else if (revealed[x][y]) {         col1=color(255\/2);         col2=color(255\/2);       }         if (near==1)txtColor=color(255*1\/4, 255*1\/4, 255*3\/4);       if (near==2)txtColor=color(255*1\/4, 255*3\/4, 155*1\/4);       if (near==3)txtColor=color(255, 0, 0);       if (near==4)txtColor=color(0, 0, 255);       if (near==5)txtColor=color(255, 0, 0);         boolean alternate=(x+y)%2==0;       if (alternate) {         fill(col2);         stroke(col2);       } else {         fill(col1);         stroke(col1);       }         \/\/if(mines[x][y]&gt;0){       \/\/fill(0,255,0);       \/\/stroke(0,255,0);       \/\/}         rect(x*cellSize, y*cellSize, cellSize, cellSize);       \/\/If there is a mine near this spot and it is revealed       if (near&gt;0&amp;&amp;revealed[x][y]) {         fill(txtColor);         noStroke();         textAlign(LEFT, TOP);         textSize(cellSize);         text(\"\"+near, x*cellSize, y*cellSize);       }     }   } }<\/code><\/pre>\n<p>  \u0418 \u0432\u0441\u0435, \u0432\u043e\u0442 \u0438 \u043d\u0430\u0448 \u00ab\u0421\u0430\u043f\u0435\u0440\u00bb.<\/p>\n<p>  \u0418\u0433\u0440\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u043e\u0441\u0442\u043e, \u043d\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u043e\u043d\u0430 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u0430. \u0418 \u043f\u043e\u043c\u043d\u0438\u0442\u0435: \u00ab\u0421\u0430\u043f\u0435\u0440\u00bb \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0438\u0432\u044b\u043a\u0430\u043d\u0438\u0435!<\/p>\n<blockquote><p><b>Skillbox \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442:<\/b><\/p>\n<ul>\n<li>\u041e\u043d\u043b\u0430\u0439\u043d-\u043a\u0443\u0440\u0441 <a href=\"https:\/\/skillbox.ru\/frontend-developer\/?utm_source=skillbox.media&amp;utm_medium=habr.com&amp;utm_campaign=FRENDEV&amp;utm_content=articles&amp;utm_term=minesweeper\">\u00ab\u041f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u044f frontend-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u00bb<\/a>.<\/li>\n<li>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0433\u043e\u0434\u043e\u0432\u043e\u0439 \u043a\u0443\u0440\u0441 <a href=\"https:\/\/skillbox.ru\/php\/?utm_source=skillbox.media&amp;utm_medium=habr.com&amp;utm_campaign=PHPDEV&amp;utm_content=articles&amp;utm_term=minesweeper\">PHP-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a<\/a>.<\/li>\n<li>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u0443\u0440\u0441 <a href=\"https:\/\/skillbox.ru\/agima\/?utm_source=skillbox.media&amp;utm_medium=habr.com&amp;utm_campaign=AGIMA&amp;utm_content=articles&amp;utm_term=minesweeper\">\u00ab\u041c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a PRO\u00bb<\/a>.<\/li>\n<\/ul>\n<\/blockquote>\n<\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/post\/425317\/\"> https:\/\/habr.com\/post\/425317\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/47d\/77b\/444\/47d77b44493995b16ccc5dd6b4e49326.jpg\" alt=\"image\"><\/p>\n<p>  <b>\u041e\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430:<\/b> \u044d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u2014 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 <a href=\"https:\/\/medium.com\/@mackycheese21\/making-minesweeper-in-10-minutes-e4c4e810fa06\">\u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438<\/a> \u041c\u0430\u043a\u0438 \u0427\u0438\u0437\u0430, \u043e\u043f\u044b\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0438\u0448\u0435\u0442 \u043a\u043b\u0430\u0441\u0441\u043d\u044b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u043d\u043e \u0438 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432 \u0441\u0432\u043e\u0438\u043c \u043a\u043e\u043b\u043b\u0435\u0433\u0430\u043c, \u043a\u0430\u043a \u043d\u043e\u0432\u0438\u0447\u043a\u0430\u043c, \u0442\u0430\u043a \u0438 \u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u0430\u043c.<\/p>\n<p>  \u00ab\u0421\u0430\u043f\u0435\u0440\u00bb \u2014 \u0432\u0435\u0441\u0435\u043b\u0430\u044f \u0438\u0433\u0440\u0430, \u043c\u043d\u043e\u0433\u0438\u0435 \u0438\u0437 \u043d\u0430\u0441 \u0432 \u043d\u0435\u0435 \u0438\u0433\u0440\u0430\u044e\u0442. \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u00ab\u0421\u0430\u043f\u0435\u0440\u0430\u00bb \u0441\u0430\u043c\u0438?  <\/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-290310","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/290310","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=290310"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/290310\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=290310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=290310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=290310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}