View Single Post
Old 01-30-2013, 10:08 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I really hated that ugly array of arrays.
Here's a simpler way to do it, I think:
Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>met@verse Test</title>
<style type="text/css">
#myMap {
    font-family: courier;
    font-size: x-large;
}
</style>
</head>
<body>
<div id="myMap"></div>
<script type="text/javascript">
(
  function()
  {
      var map = [
         "#####",
         "#...#",
         "#...#",
         "#...#",
         "#####"
      ];

      function replaceCharAt( str, char, at )
      {
          var temp = str.split("");
          temp[at] = char;
          return temp.join("");
      }

      function plotCurrentLocation( x, y )
      {
          // clone the master map
          var useMap = [].concat(map);

          // replace the appropriate character in the appropriate row:
          useMap[y] = replaceCharAt( useMap[y], "@", x );

          // dump it all out as a single string to the div's contents:
          document.getElementById("myMap").innerHTML =
              useMap.join("<br/>");
      }          
 
      // demo that it works
      var userx = 3;
      var usery = 2;
      plotCurrentLocation( userx, usery );
  }
)();
</script>
</body>
</html>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote