Git Product home page Git Product logo

doom_minesweeper's Introduction

The Doom (stylized as DOOM) franchise is a series of first-person shooter video games developed by id Software. The series focuses on the exploits of an unnamed space marine operating under the auspices of Union Aerospace Corporation (UAC), who fights hordes of demons and the undead in order to survive.

The objective of the game is to clear a rectangular board containing hidden "mines" or bombs without detonating any of them, with help from clues about the number of neighboring mines in each field.

This game is a hybrid of both of these games. The gameplay of Minesweeper and the theme of DOOM.

The game is built using React, Redux and Typescript.

Here is the code which 'conjures' the 'demons' (mines) on the game matrix. It will loop until all demons have been set in the game:

const conjureDemons = (data: ICellMap, totalDemons: number, width: number, height: number): ICellMap => {
  let demonsConjured = 0;
  const tempData = {...data};

  while (demonsConjured < totalDemons) {
    const x = getRandomNumber(width);
    const y = getRandomNumber(height);
    const id = genXy(x, y);

    if (!tempData[id].isDemon) {
      tempData[id] = {...data[id], isDemon: true, demonId: getRandomNumber(MAX_KNOWN_DEMON_TYPES)};
      demonsConjured++;
    }
  }

  return tempData;
};

Here is another piece of code from the Cells Reducer. It's a recurisve function which is initiated from exposing an empty cell and looking for other adjacent empty cells.

const traverseFromEmpty = (data: ICellMap, initialCell: ICell): void => {
  const adjacentCoordinates = genSurrounding(initialCell.x, initialCell.y);
  adjacentCoordinates.forEach(coordinate => {
    const cell = data[coordinate];
    if (cell && !cell.isExposed && !cell.isDemon && !cell.isFlagged) {
      data[coordinate].isExposed = true;
      if (!cell.adjacentDemons) {
        traverseFromEmpty(data, data[coordinate]);
      }
    }
  });
};

doom_minesweeper's People

Stargazers

 avatar  avatar

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.