JSFiddle - React, Tailwind, and code Playground

by Sam Fereday

JavaScript

// This is pretty much for my money a very simple but pretty effective dungeon roguelike adventure. Currently
// it's only text-based but any sort of media could be attached to the idea.
// I'm considering making something interesting out of it anyway, and using ROT.js to generate some interesting map data for it to boot. Perhaps a dynamic story could be created using the map data and ROT?
// That might need a bit of thought however. Some sort of linear placement of content along the path would likely do the job. I think ROT has a path generator as well, so that could quite easily be used.
// Perhaps multiple pathing points could be made, but you can only access the next route of things when you've done the first one. Beware of this and cross-overs however.
// Dynamic content creation in a random dungeon is bloody hard, and more so the fact it needs to be made interesting at the same time.
console.clear();

const MAP_DATA = [{
    x: 3,
    y: 3,
    runsOnce: true,
    evIndex: 0,
    events: [
      "You awaken surrounded by {n} corridors."
    ]
  },
  {
    x: 5,
    y: 3,
    runsOnce: false,
    evIndex: 0,
    events: [
      "The door slams shut behind you.",
      "The door seems to be now locked."
    ]
  }
];

const NORTH = 1;
const EAST = 2;
const SOUTH = 4;
const WEST = 8;

const w = 6;
const h = 6;

const onStandardArea = 'You keep walking...';

// Base map generation
const GRID_SEQ = Array.from(Array(w * h).keys());
const BASE_GRID = GRID_SEQ.map((i) => {
  const calculatedY = Math.floor((i) / h) * h;
  const x = i % w;
  const y = calculatedY / h;

  return {
    x,
    y
  }
});

// Some game methods
const unpackMap = () => {
  // ...
}

const findArea = (x, y, data) => {
  return data.find(cell => cell.x === x && cell.y === y);
}

const onArrived = (eventData, defaultData) => {
  if (eventData) {
    // Need to do something clever here with map data and progressing through it. Perhaps
    // a linear string of conditions need to happen before...