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

  1. <?php
  2. session_start();
  3. $startingPoint = $_POST['startingPoint'];
  4. $endingPoint = $_POST['endingPoint'];
  5. $largeur = (int)$_POST['largeur'];
  6. $hauteur = (int)$_POST['hauteur'];
  7. $cases = array();
  8. foreach($_POST as $n=>$v){
  9. if(!in_array($n, array('startingPoint','endingPoint','largeur','hauteur'))){
  10. $coord = getCoordForCase($n);
  11. $cases[$coord[0]][$coord[1]] = 1;
  12. }
  13. }
  14. function getCoordForPt($t){
  15. if (preg_match('/^check(\d{1,2})-(\d{1,2})$/', $t, $m) !== 0) {
  16. return '[' . $m[2] . ',' . $m[1] . ']';
  17. }
  18. return null;
  19. }
  20. function getCoordForCase($t){
  21. if (preg_match('/^check(\d{1,2})-(\d{1,2})$/', $t, $m) !== 0) {
  22. return [$m[1], $m[2]];
  23. }
  24. return null;
  25. }
  26. $level = '[';
  27. for($i=0; $i<$hauteur; $i++){
  28. $level .= '[';
  29. for($j=0; $j<$largeur; $j++){
  30. if(!empty($cases[$i][$j])) {
  31. $level .= '1,';
  32. } else {
  33. $level .= '0,';
  34. }
  35. }
  36. $level = substr($level, 0, -1).'],';
  37. }
  38. $level = substr($level, 0, -1).'];';
  39. $file = '';
  40. $file .= 'currentPosition = '.getCoordForPt($startingPoint).';';
  41. $file .= 'finalPosition ='.getCoordForPt($endingPoint).';';
  42. $file .= 'level = '.$level;
  43. $tod = gettimeofday();
  44. $finalFilename = $tod['sec'].mt_rand(0,50).'.js';
  45. file_put_contents(__DIR__ .'/custom/'.$finalFilename, $file);
  46. $_SESSION['file'] = $finalFilename;
  47. header('Location: list/');