You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// import stylesimport'../styles/app.css';// import dependenciesimport{polyfillaspromisePolyfill}from'es6-promise';importfetchfrom'isomorphic-fetch';importDOMDisplayfrom'./modules/dom-display';importGamefrom'./modules/game/game';importmyLevelfrom'./custom-levels/my-level';// execute promise polyfillpromisePolyfill();consturls=['basic','easy-start','hard-to-get-drunk',];getLevels(urls).then((levels)=>{// create game instanceconstgame=newGame();// add my custom level to the fetched levels§// we use the fancy spread operator (...) for thislevels.push(...[myLevel]);// startgame.run(levels,DOMDisplay);});/** * getLevels * @param {array} levelNames * @return {promise array} levelsPromise */functiongetLevels(levelNames){letlevelPromises=levelNames.map(function(level){returngetLevel(level);});returnPromise.all(levelPromises);}/** * getLevel * @param {string} levelName * @return {promise array} levelPromises */functiongetLevel(levelName){letlevelUrl=`http://localhost:8080/levels/${levelName}.json`;returnfetch(levelUrl).then(function(response){returnresponse.json();}).then(function(level){returnlevel;}).catch(function(error){console.error('something went wrong');returnerror;});}
custom-levels/my-level.js
/** * Create your level from these building blocks: * * Legende: * @ = Player start position * o = Coins * x = Solid surfaces * ! = Non-moving lava * = = Vertical moving lava * v = Dripping lava * | = Horizontal moving lava */exportdefault[" "," o "," o "," o "," o "," @ "," xxxxxx xxx "," xx xx xx!xx "," x o o xx x!!!x "," xx!xx "," xxxxx xvx "," xxx xx "," xx o o x "," x o x "," x xxxxx o x "," x xxxx o x "," x x x xxxxx x "," xxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx "," ================ x x x x |||||| "," ================ x!!!x x!!!!!x |||||| "," ================ x!!!x x!!!!!x |||||| "," ================ xxxxx xxxxxxx |||||| "," "," "];