You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

50 lines
1.4 KiB

<?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;
}
}
function getCoordForPt($t){
if (preg_match('/^check(\d{1,2})-(\d{1,2})$/', $t, $m) !== 0) {
return '[' . $m[2] . ',' . $m[1] . ']';
}
return null;
}
function getCoordForCase($t){
if (preg_match('/^check(\d{1,2})-(\d{1,2})$/', $t, $m) !== 0) {
return [$m[1], $m[2]];
}
return null;
}
$level = '[';
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).'];';
$file = '';
$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);
$_SESSION['file'] = $finalFilename;
header('Location: list/');