<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
a
{
    font-family:"Monospace";
text-decoration: none;
    font-size:2em;
}
#player
{
color:#00ff00;
}
</style>
</head>

<body>

<?php

/*sql nfo*/
$user = "speile";
$pass = "speile";
$host = "localhost";
$db = "speile";
$table = "overworld";
/*sql connect*/
$sql = mysql_connect($host,$user,$pass);
if (!$sql){die('mysql err ' . mysql_error());}
mysql_select_db($db, $sql);

/*get map data*/
$x = $_GET["x"];
$y = $_GET["y"];
echo $x . " " . $y . "<br />";

$cnt = 0;
$type = array(
    "plain" => '_', 
    "lake" => '~', 
    "sea" => '~', 
    "mountain" => 'M', 
    "plateau" => '-', 
    "forest" => 'T' , 
    "desert" => 'W', 
    "jungle" => 'T'
    );
$q = "SELECT * FROM ". $table . " WHERE x < " . ($x+10) . " AND x > " . ($x-10) . " AND y < " . ($y+10) . " AND y > " . ($y-10) . " ORDER BY y ASC, x ASC";
$data = mysql_query($q);
while($tile = mysql_fetch_array($data))
{
    if ($cnt == 19)
    {
        $cnt = 0;
        echo "<br />";
    }
    $cnt += 1;
    if (($tile['x'] < ($x-5)) || ($tile['x'] > ($x+5)) || ($tile['y'] < ($y-5)) || ($tile['y'] > ($y+5)))
    {
        echo "<a>" . $type[$tile['type']] . "</a>";
    }
    elseif (($tile['x'] == $x) && ($tile['y'] == $y))
    {
        echo "<a id='player' href='player.php'>" . 0 . "</a>";
    }
    else
    {
        echo "<a href='go.php?x=". $tile['x'] ."&y=". $tile['y'] ."' id=". $tile['type'] .">" . $type[$tile['type']] . "</a>";
    }
}

/*end*/
mysql_close($con);
?>


</html>
