-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.php
125 lines (116 loc) · 4.67 KB
/
map.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* Created by PhpStorm.
* User: yanis
* Date: 11/12/2018
* Time: 10:08
*/
include "characters_&_tresures.php";
include "deplacement.php";
$_movementArray;
$dimensions_c;
$k = 0;
$p = 0;
$map;
$file = fopen("inputfile.txt", "r");
if ($file) {
while (($line_ = fgets($file)) !== false) {
$line = rtrim($line_);
if ($line[0] == "C") {
$dimensions_c = explode(" - ", $line);
for ($i = 0; $i <= $dimensions_c[2]; $i++){
for ($j = 0; $j <= $dimensions_c[1]; $j++){
$map[$i][$j] = new space;
}
}
}
elseif ($line[0] == "M") {
$dimensions = explode(" - ", $line);
$map[$dimensions[2]][$dimensions[1]] = new mountain($dimensions[1], $dimensions[2]);
}
elseif ($line[0] == "T") {
$dimensions = explode(" - ", $line);
$map[$dimensions[2]][$dimensions[1]] = new treasure($dimensions[1], $dimensions[2], $dimensions[3]);
}
elseif ($line[0] == "A") {
$dimensions = explode(" - ", $line);
$map[$dimensions[3]][$dimensions[2]] = new adventurer($dimensions[2], $dimensions[3], $dimensions[1], $dimensions[4], $dimensions[5], $k);
$_movementArray[$k] = $map[$dimensions[3]][$dimensions[2]];
$k++;
}
elseif ($line[0] == "O") {
$dimensions = explode(" - ", $line);
$map[$dimensions[2]][$dimensions[1]] = new orc($dimensions[1], $dimensions[2], $dimensions[3], $dimensions[4], $k);
$_movementArray[$k] = $map[$dimensions[2]][$dimensions[1]];
$k++;
}
elseif ($line[0] == "G") {
$dimensions = explode(" - ", $line);
$map[$dimensions[2]][$dimensions[1]] = new goblin($dimensions[1], $dimensions[2], $dimensions[3], $dimensions[4], $k);
$_movementArray[$k] = $map[$dimensions[2]][$dimensions[1]];
$k++;
}
}
fclose($file);
//afficher la map
for ($i = 0; $i <= $dimensions_c[2]; $i++){
for ($j = 0; $j <= $dimensions_c[1]; $j++){
echo $map[$i][$j]->read_symbole();
}
echo "<br>";
}
echo "<br>";
echo "<br>";
// traitement des deplacements
$l = 0;
while ($_movementArray[$l]->read_symbole() != "A"){
$l++;
}
$numberOfMovements = strlen($_movementArray[$l]->read_movements());
for ($index = 0; $index < $numberOfMovements; $index++) {
for ($index1 = 0; $index1 < $k; $index1++) {
if ($_movementArray[$index1]->read_state() == "L")
{
advance_orientation();
}
}
}
// affichage de fin
for ($i = 0; $i <= $dimensions_c[2]; $i++){
for ($j = 0; $j <= $dimensions_c[1]; $j++){
echo $map[$i][$j]->read_symbole();
}
echo "<br>";
}
} else {
echo "problem reading file";
}
$file = fopen("outputfile.txt", "w");
if ($file) {
for ($i = 0; $i <= $dimensions_c[2]; $i++) {
for ($j = 0; $j <= $dimensions_c[1]; $j++) {
if ($map[$i][$j]->read_symbole() == "M") {
fwrite($file, $map[$i][$j]->read_symbole() . " - " . $map[$i][$j]->read_x() . " - " . $map[$i][$j]->read_y() . "\n");
}
}
}
for ($i = 0; $i <= $dimensions_c[2]; $i++) {
for ($j = 0; $j <= $dimensions_c[1]; $j++) {
if ($map[$i][$j]->read_symbole() == "T") {
fwrite($file, $map[$i][$j]->read_symbole() . " - " . $map[$i][$j]->read_x() . " - " . $map[$i][$j]->read_y() . " - " . $map[$i][$j]->read_number() . "\n");
echo "<br>";
}
}
}
for ($j = 0; $j < $k; $j++) {
if ($_movementArray[$j]->read_symbole() == "A" && $_movementArray[$j]->read_state() == "L") {
fwrite($file, $_movementArray[$j]->read_symbole() . " - " . $_movementArray[$j]->read_name() . " - " . $_movementArray[$j]->read_x() . " - " . $_movementArray[$j]->read_y() . " - " . $_movementArray[$j]->read_orientation() . " - " . $_movementArray[$j]->read_level() . "\n");
}
if ($_movementArray[$j]->read_symbole() == "G") {
fwrite($file, $_movementArray[$j]->read_symbole() . " - " . $_movementArray[$j]->read_x() . " - " . $_movementArray[$j]->read_y() . " - " . $_movementArray[$j]->read_state() . " - " . $_movementArray[$j]->read_n_combats() . "\n");
}
if ($_movementArray[$j]->read_symbole() == "O") {
fwrite($file, $_movementArray[$j]->read_symbole() . " - " . $_movementArray[$j]->read_x() . " - " . $_movementArray[$j]->read_y() . " - " . $_movementArray[$j]->read_state() . " - " . $_movementArray[$j]->read_n_combats() . "\n");
}
}
}