Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="game">
  <button id="start">Start</button><span id="counter">0</span>
  <div id="minefield">
    <div class="square mine"></div>
    <div class="square flag"></div>
    <div class= "cf"></div>
    <div class="square found"></div>
    <div class="square found">2</div>
  </div>
  <div class="winner"><img alt="" src="data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAA8AAD/4QMvaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjYtYzA2NyA3OS4xNTc3NDcsIDIwMTUvMDMvMzAtMjM6NDA6NDIgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnhtcD0iaHR0c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debug"></div>



              
            
!

CSS

              
                body {
  background: #222;
}

.cf {
  clear: both;
}

.game {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%); 
  text-align: center;
}

button {
  margin-bottom: 10px;
}

#minefield {
  border: 1px solid #555;
}

.square {
  position: relative;
  float: left;
  width: 20px;
  height: 20px;
  background: #111;
  border: 1px solid #555;
  transition: all 0.2s;
  color: #ddd;
  text-align: center;
  line-height: 20px;
  font-weight: bold;
  font-size: 10px;
  &:not(.found) {
    &:hover {
      border-color: #aa0000;
      cursor: pointer;
    }
  }
}

.found {
  background: #444;
}

.mine:after,
.flag:after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 10px;
  height: 10px;
  margin: 5px;
  background: #0055ee;
}

.mine:after {
  background: #aa0000;
  border-radius: 50%;
}

#debug {
  color: white;
}

.winner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

#counter {
  font-weight: bold;
  padding-left: 20px;
  color: #ddd;
}
              
            
!

JS

              
                // setup
var width = 30;
var height = 16;
var minescount = 99;
$('.game').css({
  "width": (width * 22 + 2)+"px",
  "height": (height * 22 + 2)+"px"
});
var field = $('#minefield');
var mines = [];
var squares = [];
var play = true;
var foundcount = 0;
var timego = false;
var time = 0;

// shuffle array
function shuffle(o){
    for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
    return o;
}

// check for mine
function checkMine(y,x) {
  var match = false;
  for (i=0; i<minescount; i++) {
    if (y==mines[i][0] && x==mines[i][1]) {
      match = true;
    }
  }
  return match;
}

// stack of cells to check
var stack = [];
function addToStack(ar) {
  for (m=0; m<ar.length; m++) {
    if (!squares[ar[m][0]][ar[m][1]].hasClass('found')) {
      var match = false;
      for (n=0; n<stack.length; n++) {
        if (stack[n][0] == ar[m][0] && stack[n][1] == ar[m][1]) {
          match = true;
        }
      }
      if (!match) {
        stack.push(ar[m]);
        // cont = $('#debug').html();
        // $('#debug').html(cont+'<br>'+ar[m][0]+' - '+ar[m][1]);
      }
    }
  }
}

// return array of surrounding cells
function getSurroundCells(y,x) {
  var arr1 = [[y-1,x-1],[y-1,x],[y-1,x+1],[y,x-1],[y,x+1],[y+1,x-1],[y+1,x],[y+1,x+1]];
  var arr2 = [];
  for (ai=0; ai<arr1.length; ai++) {
    if (arr1[ai][0]<height && arr1[ai][1]<width && 0<=arr1[ai][0] && 0<=arr1[ai][1]) {
      arr2.push(arr1[ai]);
    }
  }
  return arr2;
}

// check surrounding squares for mines
function checkSurround(y,x) {
  var count = 0;
  var arr = getSurroundCells(y,x);
  for (p=0; p<arr.length; p++) {
    if (checkMine(arr[p][0],arr[p][1])) {
      count++;
    }
  }
  return count;
} 

// cell to check
function checkCell(y,x) {
  stack = [[y,x]];
  var st = 0;
  while (st < stack.length) {
    squares[stack[st][0]][stack[st][1]].addClass("found").removeClass('flag');
    foundcount++;
    
    var count = checkSurround(stack[st][0],stack[st][1]);
    if (count == 0) {
      addToStack(getSurroundCells(stack[st][0],stack[st][1]));
    } else {
      squares[stack[st][0]][stack[st][1]].html(count);
    }
    st++;
  }
  if (((width*height)-minescount) <= foundcount) {
    winGame();
  }
}

// win game
function winGame() {
  clearInterval(timer);
  timego = false;
  play = false;
  $('.winner').show();
}

// lose game
function loseGame() {
  clearInterval(timer);
  timego = false;
  play = false;
  for (mn=0; mn<minescount; mn++) {
    squares[mines[mn][0]][mines[mn][1]].addClass('mine');
  }
}

// initialise
function init() {
  clearInterval(timer);
  timego = false;
  time = 0;
  $('#counter').html(time);
  $('.winner').hide();
  foundcount = 0;
  play = true;
  field.empty();
  squares = [];
  mines = [];
  for (iy=0; iy<height; iy++) {
    squares[iy] = [];
    for (ix=0; ix<width; ix++) {
      squares[iy][ix] = $('<div class="square" data-y="'+iy+'" data-x="'+ix+'"></div>');
      field.append(squares[iy][ix]);
      mines.push([iy,ix]);
    }
    field.append('<div class="cf"></div>');
  }
  shuffle(mines);
  
  // when mine is clicked
  $('.square:not(.found)').on("contextmenu", function(evt) {evt.preventDefault();});
  $('.square:not(.found)').mousedown(function(event) {
    if (!$(this).hasClass('found') && play) {
    switch (event.which) {
      case 2:
        //alert('Middle Mouse button pressed.');
        break;
      case 3:
        if ($(this).hasClass('flag')) {
          $(this).removeClass('flag');
        } else {
          $(this).addClass('flag');
        }
        break;
      default:
        if ($(this).hasClass('flag')) {
          $(this).removeClass('flag');
        } else {
          if (!timego) {
            setTimer();  
          }
          timego = true;
          var x = $(this).data('x');
          var y = $(this).data('y');
          if (checkMine(y,x)) {
            loseGame(y,x);
          } else {
            checkCell(y,x);
          }   
        }
    }
    }
  });
}
init();

// start
$('#start').click(function(){
  init();
});

// timer
var timer = false;
function setTimer() {
  timer = setInterval(function(){
    time++;
    $('#counter').html(time);
  },1000);
}
              
            
!
999px

Console