2024-04-25 17:52:58 +02:00
|
|
|
<?php
|
2020-08-04 12:22:09 +02:00
|
|
|
session_start();
|
|
|
|
$startingPoint = $_POST['startingPoint'];
|
|
|
|
$endingPoint = $_POST['endingPoint'];
|
2024-04-25 17:52:58 +02:00
|
|
|
$largeur = (int)$_POST['largeur'];
|
|
|
|
$hauteur = (int)$_POST['hauteur'];
|
|
|
|
$cases = [];
|
|
|
|
foreach ($_POST as $n => $v) {
|
|
|
|
if (!in_array($n, ['startingPoint', 'endingPoint', 'largeur', 'hauteur'])) {
|
|
|
|
$coord = getCoordForCase($n);
|
|
|
|
$cases[$coord[0]][$coord[1]] = 1;
|
|
|
|
}
|
2020-08-04 12:22:09 +02:00
|
|
|
}
|
|
|
|
|
2024-04-25 17:52:58 +02:00
|
|
|
function getCoordForPt($t)
|
|
|
|
{
|
|
|
|
if (preg_match('/^check(\d{1,2})-(\d{1,2})$/', $t, $m) !== 0) {
|
2020-08-04 12:22:09 +02:00
|
|
|
return '[' . $m[2] . ',' . $m[1] . ']';
|
|
|
|
}
|
2024-04-25 17:52:58 +02:00
|
|
|
|
|
|
|
return null;
|
2020-08-04 12:22:09 +02:00
|
|
|
}
|
2024-04-25 17:52:58 +02:00
|
|
|
|
|
|
|
function getCoordForCase($t)
|
|
|
|
{
|
|
|
|
if (preg_match('/^check(\d{1,2})-(\d{1,2})$/', $t, $m) !== 0) {
|
2020-08-04 12:22:09 +02:00
|
|
|
return [$m[1], $m[2]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$level = '[';
|
2024-04-25 17:52:58 +02:00
|
|
|
for ($i = 0; $i < $hauteur; $i++) {
|
|
|
|
$level .= '[';
|
|
|
|
for ($j = 0; $j < $largeur; $j++) {
|
|
|
|
if (!empty($cases[$i][$j])) {
|
2020-08-04 12:22:09 +02:00
|
|
|
$level .= '1,';
|
|
|
|
} else {
|
|
|
|
$level .= '0,';
|
|
|
|
}
|
2024-04-25 17:52:58 +02:00
|
|
|
}
|
|
|
|
$level = substr($level, 0, -1) . '],';
|
2020-08-04 12:22:09 +02:00
|
|
|
}
|
2024-04-25 17:52:58 +02:00
|
|
|
$level = substr($level, 0, -1) . '];';
|
2020-08-04 12:22:09 +02:00
|
|
|
$file = '';
|
2024-04-25 17:52:58 +02:00
|
|
|
$file .= 'currentPosition = ' . getCoordForPt($startingPoint) . ';';
|
|
|
|
$file .= 'finalPosition =' . getCoordForPt($endingPoint) . ';';
|
|
|
|
$file .= 'level = ' . $level;
|
2020-08-04 12:22:09 +02:00
|
|
|
$tod = gettimeofday();
|
2024-04-25 17:52:58 +02:00
|
|
|
$finalFilename = $tod['sec'] . mt_rand(0, 50) . '.js';
|
|
|
|
file_put_contents(__DIR__ . '/custom/' . $finalFilename, $file);
|
2020-08-04 12:22:09 +02:00
|
|
|
$_SESSION['file'] = $finalFilename;
|
|
|
|
header('Location: list/');
|