Game Map
"; //now we start building the table
//now we want to add an extra row at the top that just shows the coordinate numbers
//across the top of the map.
echo " | "; //we start a row, and add an extra blank column to offset the
//coordinate numbers added over the map (so 0 starts over the first W in the map)
for ($i = 0; $i <= $mapwidth; $i++) //now we want to draw numbers for the width of the map
echo "$i | "; //this shows the numbers in a column
echo "
"; //that's the end of this row, we now have all the numbers across the top of the map
//now it's time to start drawing the map
for ($i = 0; $i <= $mapheight; $i++) //we want to draw the entire height
{
echo ""; //each row in the map starts off with a number as well
echo "$i | "; //so we can tell which coordinate it's at
//now we want to draw what's in that part of the map for the entire width
for ($j = 0; $j <= $mapwidth; $j++)
{
if ($x == $i && $y == $j && $map[$i][$j] != "T") //if this is not treasure
echo "C | "; //and the character is standing here
//draw the C instead of what's on the map
//and make it show up green
else if ($x == $i && $y == $j && $map[$i][$j] == "T") //this is the treasure
echo "C | "; //and the character is standing here
//draw the C instead of what's on the map
//and make it show up green
else
echo "" . $map[$i][$j] . " | "; //this is just a lonely map space, show whatever it is
}
echo "
";
}
//now our table is done, we can end it, and under that
//we'll show the coordinates of the character so we can
//tell what spot they're inside of the map numerically
echo "
";
echo "Your coordinates are: ($x, $y)";
echo "
";
}
//we're only going to show the map
//if they decide they want to cheat...
if ($_GET['showmap'])
{
//call our custom draw map function
//make sure we pass it all the parameters we need
drawMap($_SESSION['x'], $_SESSION['y'], $maze, 6, 4);
}
?>
Pits of Doom