Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your variable <code>Map</code> should be an array of arrays, rather than an object. </p> <p>Another way to initialize it that is a bit more visual:</p> <pre><code>// Splits each row by character to from a new array var map = [ "####################".split(''), "# #".split(''), "# #".split(''), "# #".split(''), "# #".split(''), "# #".split(''), "# #".split(''), "# #".split(''), "# #".split(''), "####################".split('')]; </code></pre> <p>The result of this is the same as in @Bergi's answer. </p> <p>You mentioned in your question wanting to "output the first array exactly as it appears". If you are doing this in the browser, one way to do that would be to make use of the <code>pre</code> tag:</p> <p>HTML:</p> <pre><code>&lt;pre id="map"&gt;&lt;/pre&gt; </code></pre> <p>Code:</p> <pre><code>function updateMap() { // Iterates the array, joining each subarray with no separator, // then joining the result with a new line mapEle.innerText = map.map(function (val, idx, arr) { return val.join(''); }).join('\n'); } </code></pre> <p>Each time you modify the map, you can render it by calling <code>updateMap()</code>.</p> <p>For example:</p> <pre><code>var chars = ['|', '/', '\u2014', '\\']; var counter = 0; window.setInterval(function () { map[4][9] = chars[counter % chars.length]; updateMap(); counter++; }, 200); </code></pre> <p><kbd><a href="http://jsfiddle.net/davidcl64/zdygR/" rel="nofollow noreferrer">Demo Fiddle</a></kbd></p> <p>Take a look a <a href="https://gamedev.stackexchange.com/questions/51788/good-technological-solutions-to-build-an-ascii-map-and-moving-characters-in-a-br">this question on gamedev.stackexchange</a> and its answers - if you want to focus on the game rather than building parts of the engine, the linked libraries may be interesting:</p> <ul> <li><a href="http://tapiov.net/unicodetiles.js/" rel="nofollow noreferrer">unicodetiles.js</a></li> <li><a href="http://ondras.github.com/rot.js/hp/" rel="nofollow noreferrer">rot.js</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload