blob: 5b7a77b17ff49bded9f89b67603323d12cabbad9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
<?PHP
include "includes/maps.php";
include "includes/db.inc.php";
include "includes/mapoftheday.php";
include "includes/datas.php";
// encode array $json to JSON string
//echo "working...";
if ($_GET['act'] == "getmap") {
$maptype = $_GET['maptype'] + 0;
if (!is_int($maptype))
return;
if ($maptype > 4)
return;
if ($maptype < 1)
return;
$motd = MapOfTheDay($maptype);
$map = $motd['map'];
$mapID = $motd['id'];
//print_r($map);
echo translatemap($map, $mapID);
}
function translatemap($mapMatrix, $mapID) {
$mapdata['height'] = $mapMatrix[0][0];
$mapdata['width'] = $mapMatrix[0][1];
$waypoints = $mapMatrix[0][2];
$mapdata['rocks'] = $mapMatrix[0][3];
$walls = $mapMatrix[0][4];
$mapdata['teleports'] = $mapMatrix[0][5];
$r .= "<level>";
$r .= "\n <properties>";
$r .= "\n <mapID>$mapID</mapID>";
$r .= "\n <availableCost>$walls</availableCost>";
$r .= "\n <waypoints>$waypoints</waypoints>";
$r .= "\n </properties>";
$r .= "\n <tiles>";
$r .= "\n <rows>";
for ($i = 1; $i < count($mapMatrix); $i++) {
$r .= "\n <row>";
for ($j = 0; $j < count($mapMatrix[$i]); $j++) {
switch($mapMatrix[$i][$j]) {
case 's': $r .= "02 "; break;
case 'f': $r .= "03 "; break;
case 't': $r .= "50 "; break;
case 'u': $r .= "61 "; break;
//TP2
case 'm': $r .= "51 "; break;
case 'n': $r .= "62 "; break;
//TP3
case 'g': $r .= "52 "; break;
case 'h': $r .= "63 "; break;
//TP4
case 'i': $r .= "53 "; break;
case 'j': $r .= "64 "; break;
//TP5
case 'k': $r .= "54 "; break;
case 'l': $r .= "65 "; break;
case 'a': $r .= "40 "; break;
case 'b': $r .= "41 "; break;
case 'c': $r .= "42 "; break;
case 'd': $r .= "43 "; break;
case 'e': $r .= "44 "; break;
case 'r': $r .= "00 "; break; //rock
case 'w': $r .= "01 "; break; //wall
//default: $r .= "<td class='grid_td' id='$handle' onClick='grid_click(this)' >".$index."</td>";
default: $r .= "10 ";
//default: $r .= "<td class='grid_td' id='$handle' onClick='grid_click(this)' >".$mapMatrix[$i][$j]."</td>";
}
}
$r .= "</row>";
}
$r .= "\n </rows>";
$r .= "\n </tiles>";
$r .= "\n</level>";
return $r;
}
|