class Game { constructor() { this.mapInstance = null; this.level = 153; this.lives = 10; this.points = 0; this.totalMoves = 0; this.levelMoves = {}; } initializeLevel() { this.mapInstance = new Map(); this.mapInstance.generateMapArray(); this.loop(); } loop() { this.mapInstance.display(); // this.mapInstance.waitForInput(); // this.mapInstance.checkWinCondition(); } handlePoints() {} } class Map { constructor() { this.level = g.level; this.levelMap = levels[this.level][0]; this.levelPar = levels[this.level][1]; this.mapArray = []; this.storageLocations = []; this.playerX = null; this.playerY = null; this.previousElement = " "; this.win = false; this.lose = false; this.breakCondition = true; this.totalWin = g.level + 1 == levels.length; this.finalPointsGiven = false; } generateMapArray() { g.levelMoves[this.level] = 0; let levelArray = this.levelMap.split("\n"); for (let i = 0; i < levelArray.length; i++) { if (i === 0 || i === levelArray.length - 1) { continue; } let rowElements = levelArray[i].split(""); if (rowElements.includes("@")) { this.playerX = i - 1; this.playerY = rowElements.indexOf("@"); } let storageTypes = [".", "*"]; for (let j = 0; j < storageTypes.length; j++) { if (storageTypes[j] in rowElements) { for (let k = 0; k < rowElements.length; k++) { if (rowElements[k] === storageTypes[j]) { this.storageLocations.push([i - 1, k]); } } } } this.mapArray.push(rowElements); } } display() { let map = ""; for (let i = 0; i < this.mapArray.length; i++) { for (let j = 0; j < this.mapArray[i].length; j++) { if (this.mapArray[i][j] === "#") { map += ''; } else if (this.mapArray[i][j] === " ") { map += ''; } else if (this.mapArray[i][j] === "0") { map += ''; } else if (this.mapArray[i][j] === "*") { map += ''; } else if (this.mapArray[i][j] === "@") { map += ''; } else if (this.mapArray[i][j] === ".") { map += ''; } } map += "
"; } let mapDiv = document.getElementById("map"); mapDiv.innerHTML = map; } } let levels = microban_levels; let g = new Game(); g.initializeLevel();