-
Notifications
You must be signed in to change notification settings - Fork 1
/
game.php
72 lines (69 loc) · 2.84 KB
/
game.php
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
<?php
session_start();
if(empty($_SESSION["user"])):
$_SESSION["user"] = [2, 1, 1];
endif;
$user = $_SESSION["user"];
$map = json_decode(file_get_contents(__DIR__ . "/maps/".$user[2].".json"), true);
if(!empty($_GET["pos"])):
var_dump($_GET["pos"]);
if($_GET["pos"] == "U" && $map[$user[0]][$user[1]]["moving"]["up"] == "T"):
$_SESSION["user"] = [--$user[0], $user[1], $user[2]];
elseif($_GET["pos"] == "D" && $map[$user[0]][$user[1]]["moving"]["down"] == "T"):
$_SESSION["user"] = [++$user[0], $user[1], $user[2]];
elseif($_GET["pos"] == "L" && $map[$user[0]][$user[1]]["moving"]["left"] == "T"):
$_SESSION["user"] = [$user[0], --$user[1], $user[2]];
elseif($_GET["pos"] == "R" && $map[$user[0]][$user[1]]["moving"]["right"] == "T"):
$_SESSION["user"] = [$user[0], ++$user[1], $user[2]];
endif;
endif;
if(!empty($map[$user[0]][$user[1]]["event"]["type"])):
switch($map[$user[0]][$user[1]]["event"]["type"]){
case "location":
$_SESSION["user"] = [0, 0, $map[$user[0]][$user[1]]["event"]["value"]];
$map = json_decode(file_get_contents(__DIR__ . "/maps/".$user[2].".json"), true);
break;
case "monster":
echo "С шансом " . $map[$user[0]][$user[1]]["event"]["chance"] . " можно было бы встретить монстра " . $map[$user[0]][$user[1]]["event"]["value"];
break;
case "npc":
echo "С шансом " . $map[$user[0]][$user[1]]["event"]["chance"] . " можно было бы встретить NPC " . $map[$user[0]][$user[1]]["event"]["value"];
break;
}
endif;
?>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/css/style.css" />
<script src="/js/jquery.js"> </script>
<title>MapNavigateExample</title>
</head>
<body>
<?php
foreach($map as $trN => $tr):
foreach($tr as $tdN => $td):
if($trN == $user[0] && $tdN == $user[1]):
echo "<span class='user'>";
echo "<img src='{$td['sprite']}' />";
echo "<img src='tiles/1.png' />";
echo "</span>";
else:
echo "<img src='{$td['sprite']}' />";
endif;
endforeach;
echo "<br />";
endforeach;
?>
<div class="control">
<a href="?pos=U">Вверх</a><br />
<a href="?pos=L">Влево</a>
<a href="?pos=R">Вправо</a><br />
<a href="?pos=D">Вниз</a><br /><br />
<a href="/game.php">Остаться здесь.</a>
</div>
</body>
</html>