jQuery plugin to implement minesweeper game (1)

jQuery plugin to implement minesweeper game (1)

This article shares the specific code of the first article of the minesweeper game with the jquery plug-in for your reference. The specific content is as follows

Make a Minesweeper

Part 1 : Complete the drawing and clicking actions

The effect is as follows

Code section

* {
 margin: 0px;
 padding: 0px;
 font-size: 12px;
}

#div {
 position: fixed;
 top: 10px;
 bottom: 10px;
 left: 10px;
 right: 10px;
 border: 1px solid lightgray;
 border-radius: 5px;
 display: flex;
 justify-content: center;
 align-items: center;
 overflow: hidden;
}

#box {
 border: 1px solid lightgray;
 border-radius: 5px;
}

.row {
 white-space: nowrap;
 height: 30px;
}

.item {
 display: inline-flex;
 justify-content: center;
 align-items: center;
 height: 30px;
 width: 30px;
 border-right: 1px solid lightgray;
 border-bottom: 1px solid lightgray;
 cursor: pointer;
 position: relative;
}
.item::before{
 position: absolute;
 content: '';
 top: 0.5px;
 left:0.5px;
 bottom: 0.5px;
 right: 0.5px;
 background-color: gray;
}
.item.click::before{
 content: none;
}
.item:hover{
 outline: 1px solid #2c3e50;
}

#menu {
 border-bottom: 1px solid lightgray;
 position: absolute;
 top: 0;
 left: 0;
 right: 0;
 height: 30px;
 display: flex;
 background-color: white;
}
.mitem{
 flex: 1;
 display: flex;
 justify-content: center;
 align-items: center;
}
.sl{
 border: none;
 border-bottom: 1px solid lightgray;
 outline: none;
 width: 60%;
 height: 80%;
}
.btn{
 border: none;
 border: 1px solid lightgray;
 outline: none;
 width: 60%;
 height: 80%;
 background-color: transparent;
 cursor: pointer;
}
.mitem *:hover{
 background-color: lightgray;
}
<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title>Make a Minesweeper</title>
  <script src="js/jquery-3.4.1.min.js"></script>
  <script src="js/yqlsl.js"></script>
  <link href="css/yqlsl.css" rel="external nofollow" rel="stylesheet" type="text/css" />
 </head>
 <body>
  <div id="div">
   <div id="box">
    
   </div>
   <div id="menu">
    <div class="mitem">
     <select class="sl" id="x">
      <option value="10">10</option>
      <option value="11">11</option>
      <option value="12">12</option>
      <option value="13">13</option>
      <option value="14">14</option>
      <option value="15">15</option>
      <option value="16">16</option>
      <option value="17">17</option>
      <option value="18">18</option>
      <option value="19">19</option>
      <option value="20">20</option>
     </select>
    </div>
    <div class="mitem">
     <select class="sl" id="y">
      <option value="10">10</option>
      <option value="11">11</option>
      <option value="12">12</option>
      <option value="13">13</option>
      <option value="14">14</option>
      <option value="15">15</option>
      <option value="16">16</option>
      <option value="17">17</option>
      <option value="18">18</option>
      <option value="19">19</option>
      <option value="20">20</option>
     </select>
    </div>
    <div class="mitem">
     <select class="sl" id="c">
      <option value="10">10</option>
      <option value="20">20</option>
      <option value="30">30</option>
      <option value="40">40</option>
      <option value="50">50</option>
      <option value="60">60</option>
      <option value="70">70</option>
      <option value="80">80</option>
      <option value="90">90</option>
      <option value="99">99</option>
     </select>
    </div>
    <div class="mitem">
     <button type="button" class="btn" id="pro">Generate</button>
    </div>
   </div>
  </div>
 </body>
</html>
$(document).ready(function() {
 var x = 10; //x axisvar y = 10; //y axisvar c = 10; //number of bombsvar boom = []; //coordinates for generating bombsvar $menu = $("#menu");
 var $box = $("#box");



 //Synchronous parameters $("#x").change(function() {
  x = parseInt($(this).val());
  console.log(x);
 })
 $("#y").change(function() {
  y = parseInt($(this).val());
 })
 $("#c").change(function() {
  c = parseInt($(this).val());
 })
 $(document).on('click', '#box .item', function() {
  $(this).addClass("click");
 })
 $("#pro").click(function() {
  console.log(x,y,c)
  draw();
 })
 draw();
 function draw() { //Draw the picture $box.html('');
  for (var a = 0; a < x; a++) {
   var $row = $("<div class='row'></div>");
   for (var b = 0; b < y; b++) {
    var $item = $("<div class='item'></div>");
    $item.appendTo($row);
   }
   $row.appendTo($box);
  }
 }
})

Explanation of ideas

  • The first is the generation of parameters and the drawing of content, which is easy to do.
  • Then you need to prepare to mark the coordinates of each block to facilitate subsequent calculations and direct operation.
  • Then the click effect is achieved through the pseudo-class. When there is no click, the pseudo-class generates an overlay mask, which can be removed after the click.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • jQuery plugin to implement minesweeper game (3)
  • jQuery plugin to implement minesweeper game (2)
  • jQuery implements the minesweeper game

<<:  MySQL 5.6.22 installation and configuration method graphic tutorial

>>:  How to install PostgreSQL11 on CentOS7

Recommend

The difference between VOLUME and docker -v in Dockerfile

There are obvious differences between volume moun...

Solution to blank page after Vue packaging

1. Solution to the problem that the page is blank...

Summary of 7 pitfalls when using react

Table of contents 1. Component bloat 2. Change th...

Solve the problem of docker log mounting

The key is that the local server does not have wr...

Practical record of handling MySQL automatic shutdown problems

I recently helped someone with a project and the ...

Four completely different experiences in Apple Watch interaction design revealed

Today is still a case of Watch app design. I love...

Detailed example of deploying Nginx+Apache dynamic and static separation

Introduction to Nginx dynamic and static separati...

MySQL online deadlock analysis practice

Preface I believe that everyone has had a simple ...

SQL merge operation of query results of tables with different columns

To query two different tables, you need to merge ...

Details about the like operator in MySQL

1. Introduction When filtering unknown or partial...

Detailed steps to install MySQL 5.7 via YUM on CentOS7

1. Go to the location where you want to store the...

MySQL deduplication methods

MySQL deduplication methods 【Beginner】There are v...

Make your website run fast

Does performance really matter? Performance is im...