Giter Club home page Giter Club logo

minesweeper's Introduction

Minesweeper By Energy Marketing Company

This is a full Javascript Minesweeper full with runnable tests, game logic, and GUI.

⚡ BY KRIS @ ENERGY MARKETING COMPANY ⚡ ENERGYMARKETING.CO ⚡ [email protected]

Commit Log

COMMIT 53:

Minor changes

Changes

a. Added fast mine on tile double click when flags in cell == number in tile

====================================

COMMIT 52:

Game is FINALLY fully functional!!!! (2/28/2020)

Changes

a. Added cell chain reaction !! b. Fixed bug where if a bomb was double clicked it would not run the highlight function, thus revealing that the cell is a mine. Caused by bomb cells not having a [neighbors] property.

Bug Fixes

a. Fixed timer bug

COMMIT 50:

Bugs mentioned in Commit 45 are still present. Minor bug fixes.

Bug Fixes

a. Fixed errorCan't read property hasFlag of undefined when a number is clicked b. Fixed bug where cell highlighting functionality wasn't working when a number is clicked c. Added functionality to to Easy Dom function $() to accept numbers as ID and Class names

====================================

COMMIT 47:

Bugs mentioned in Commit 45 are still present. Extremely minor changes and some optimizations.

Changes

Below are the changes:

  1. Removed unneeded console.log()'s that were clogging this terminal and slowing the game

Bug Fixes

a. Fixed bug where cell highlight functionality wasn't working after game reset b. Fixed bug where bomb locations weren't being appended to the game.bombLocations array

====================================

COMMIT 46:

Changes

Below are the changes:

1. Refactored code

a. Changed way bomb locations are calculated to avoid collisions b. Removed padding cells in favor of increased boolean logic c. To calculate cells, I added the "neighbors" property to each tile object. d. Added "Tile" class for each tile

2. Added Easy-Dom.js functions to native prototypes

a. Added the changeHTML (element.addHTML) & addHTML (element.addHTML) functions to the HTMLElement prototype b. Added eventListenerAll() to the NodeList prototype ( NodeList.addEventListenerAll() )

3. Added function double click function

a. When a tile is double clicked, it will highlight all neighbors remaining on the board by making them blend with the background (light gray)

Bugs:

hideBoard() is broken

a. After running hideBoard(), click events are broken

Timer function is broken

a. Timer function does not work after second restart, as picture below

Timer Example Gif

Todo:

a. Cell "chain reaction" b. Improved GUI?

minesweeper's People

Contributors

krisb1220 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

minesweeper's Issues

Wrong number calculation (on edge?)

Numbers on the edge are not calculating correctly. Calculating the last 2 cells. Fix by adding an extra cell before & after each row.

Right on Edge

image

1 over

image

?

image

Append numbers to page AFTER button click

The current procedure appends the numbers to each element BEFORE the buttons are clicked. For both cheating & general flow reasons, it should be AFTER the click.

Code needs to be refactored to delete padding cells + add logic for detecting mines in tile 1, x, last, and last-x

Padding cells are no longer needed after the implementation of the following code. Logic for tile 1, tile x, last cell, and last cell - x is needed before padding cells can be deleted.

      //right
      if(field.fieldObject[value.integerLocation + 1].hasBomb && value.integerLocation % field.x != 2 ) {
        bombsInCell++;
      } 

      //left
     if(field.fieldObject[value.integerLocation - 1].hasBomb && value.integerLocation % field.x != 3) {
        bombsInCell++;
      }      


      //top
      if(field.fieldObject[value.integerLocation - field.x].hasBomb) { 
        bombsInCell++;
      } 

      //top right
      if(field.fieldObject[(value.integerLocation - field.x)+1].hasBomb && value.integerLocation % field.x != 2 ) {
        bombsInCell++;
      } 

      //top left
      if(field.fieldObject[(value.integerLocation - field.x)-1].hasBomb  && value.integerLocation % field.x != 3) {
        
        bombsInCell++;
      }       

      //bottom
      if(field.fieldObject[value.integerLocation + field.x].hasBomb) {
        bombsInCell++;
      } 

      //bottom right
      if(field.fieldObject[(value.integerLocation + field.x)+1].hasBomb && value.integerLocation % field.x != 2 ) {
        bombsInCell++;
      } 

      //bottom left
      if(field.fieldObject[(value.integerLocation + field.x)-1].hasBomb  && value.integerLocation % field.x != 3 ) {
        bombsInCell++;
      }       

When you click a mined cell's number it returns an error in the console

The error is happening because of the following code in game.js:

function detectClicks() {

  let tiles = document.querySelectorAll(".tile") 

  forEach(tiles, function(tile){
    tile.addEventListener("click", function(event){

      clicked = field.fieldObject[event.target.id]

       if(event.shiftKey) {
         placeFlag(clicked);
       }

       else if(!event.shiftKey){
        clicked.hasBomb ? lose() : mineTile(clicked);
       }
  });
});

and the following code in game-helpers.js from line 128 - 131

	if(!tile.isMined) {
		document.getElementById(tile.integerLocation).innerHTML = "<p class='number'>" + tile.bombsInCell + "</p>";
		document.getElementById(tile.integerLocation).classList.add("tile-mined");
	} 

This can be fixed by changing the tile numbering from an ID to a class, then appending the classname to the paragraph holding the number.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.