View Single Post
Old 01-30-2013, 05:35 PM   PM User | #1
coolguy8
New to the CF scene

 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
coolguy8 is an unknown quantity at this point
Write out a variable via JS in a specific font

Hi all. I'm trying to make a simple online roguelike in javascript. Right now, I'm simply trying to print a map and the location of a user.

I can print out everything but it's all in the default font. I need it to be a monospaced font, preferably courier. I have managed to do this with the user cursor, but not the map tiles. I think that this a super easy problem, which is why I can't find a solution anywhere online. Here is the code:

<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>met@verse Test</title>

</head>
<body>
<script>
var map =
[ ['#','#','#','#','#'],
['#','.','.','.','#'],
['#','.','.','.','#'],
['#','.','.','.','#'],
['#','#','#','#','#']];

var userx = 1;
var usery = 1;


function print_2d_string_array (array)
{
for (row=0; row < array.length; row++)
{
for (col = 0; col < array.length; col++)
{
if (userx==col && usery==row)
{
document.write('<font face=courier>@</font>');
}
else
{
document.write(array[row][col]);
}

}
document.write("<br>");

}
}

print_2d_string_array (map);

</script>


</body>
</html>
coolguy8 is offline   Reply With Quote