🎨 starts cleaning code before adding labyrinth generation
This commit is contained in:
56
save.php
56
save.php
@@ -1,25 +1,29 @@
|
||||
<?php
|
||||
<?php
|
||||
session_start();
|
||||
$startingPoint = $_POST['startingPoint'];
|
||||
$endingPoint = $_POST['endingPoint'];
|
||||
$largeur = (int)$_POST['largeur'];
|
||||
$hauteur = (int)$_POST['hauteur'];
|
||||
$cases = array();
|
||||
foreach($_POST as $n=>$v){
|
||||
if(!in_array($n, array('startingPoint','endingPoint','largeur','hauteur'))){
|
||||
$coord = getCoordForCase($n);
|
||||
$cases[$coord[0]][$coord[1]] = 1;
|
||||
}
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
function getCoordForPt($t){
|
||||
if (preg_match('/^check(\d{1,2})-(\d{1,2})$/', $t, $m) !== 0) {
|
||||
function getCoordForPt($t)
|
||||
{
|
||||
if (preg_match('/^check(\d{1,2})-(\d{1,2})$/', $t, $m) !== 0) {
|
||||
return '[' . $m[2] . ',' . $m[1] . ']';
|
||||
}
|
||||
return null;
|
||||
|
||||
return null;
|
||||
}
|
||||
function getCoordForCase($t){
|
||||
if (preg_match('/^check(\d{1,2})-(\d{1,2})$/', $t, $m) !== 0) {
|
||||
|
||||
function getCoordForCase($t)
|
||||
{
|
||||
if (preg_match('/^check(\d{1,2})-(\d{1,2})$/', $t, $m) !== 0) {
|
||||
return [$m[1], $m[2]];
|
||||
}
|
||||
|
||||
@@ -27,24 +31,24 @@ function getCoordForCase($t){
|
||||
}
|
||||
|
||||
$level = '[';
|
||||
for($i=0; $i<$hauteur; $i++){
|
||||
$level .= '[';
|
||||
for($j=0; $j<$largeur; $j++){
|
||||
if(!empty($cases[$i][$j])) {
|
||||
for ($i = 0; $i < $hauteur; $i++) {
|
||||
$level .= '[';
|
||||
for ($j = 0; $j < $largeur; $j++) {
|
||||
if (!empty($cases[$i][$j])) {
|
||||
$level .= '1,';
|
||||
} else {
|
||||
$level .= '0,';
|
||||
}
|
||||
}
|
||||
$level = substr($level, 0, -1).'],';
|
||||
}
|
||||
$level = substr($level, 0, -1) . '],';
|
||||
}
|
||||
$level = substr($level, 0, -1).'];';
|
||||
$level = substr($level, 0, -1) . '];';
|
||||
$file = '';
|
||||
$file .= 'currentPosition = '.getCoordForPt($startingPoint).';';
|
||||
$file .= 'finalPosition ='.getCoordForPt($endingPoint).';';
|
||||
$file .= 'level = '.$level;
|
||||
$file .= 'currentPosition = ' . getCoordForPt($startingPoint) . ';';
|
||||
$file .= 'finalPosition =' . getCoordForPt($endingPoint) . ';';
|
||||
$file .= 'level = ' . $level;
|
||||
$tod = gettimeofday();
|
||||
$finalFilename = $tod['sec'].mt_rand(0,50).'.js';
|
||||
file_put_contents(__DIR__ .'/custom/'.$finalFilename, $file);
|
||||
$finalFilename = $tod['sec'] . mt_rand(0, 50) . '.js';
|
||||
file_put_contents(__DIR__ . '/custom/' . $finalFilename, $file);
|
||||
$_SESSION['file'] = $finalFilename;
|
||||
header('Location: list/');
|
Reference in New Issue
Block a user