🎨 starts cleaning code before adding labyrinth generation
This commit is contained in:
parent
69b6cafb28
commit
f7754632de
@ -1,3 +1,8 @@
|
||||
const KO = 0,
|
||||
OK = 1,
|
||||
WALL = 2,
|
||||
LOSE = 3,
|
||||
WIN = 4;
|
||||
let clicked = false,
|
||||
sounds = $.map(["ko.wav", "ok.wav", "undefined.wav", "gameover.wav", "welldone.wav"], function(sound) {
|
||||
return 'assets/sounds/'+sound;
|
||||
@ -5,7 +10,7 @@ let clicked = false,
|
||||
boardbg = '#FFFFFF',
|
||||
score = 0,
|
||||
time = 0,
|
||||
compte, nbsnd, oksnd, kosnd, nosnd, failsnd, level, left, top, bottom, right, currentPosition, toleft, toright, totop, tobot;
|
||||
compte, nbsnd, oksnd, kosnd, nosnd, failsnd, level, p_left, p_top, p_bottom, p_right, currentPosition, toright, totop, tobot;
|
||||
//console.log('level :'+level);
|
||||
$(document).ready(function(){
|
||||
|
||||
@ -34,15 +39,15 @@ $(document).ready(function(){
|
||||
|
||||
$('#ok').live('click', function(e){
|
||||
e.preventDefault();
|
||||
playSound(1);
|
||||
playSound(OK);
|
||||
});
|
||||
$('#ko').live('click', function(e){
|
||||
e.preventDefault();
|
||||
playSound(0);
|
||||
playSound(KO);
|
||||
});
|
||||
$('#unknown').live('click', function(e){
|
||||
e.preventDefault();
|
||||
playSound(2);
|
||||
playSound(WALL);
|
||||
});
|
||||
|
||||
$('#retry').live('click', function(e){
|
||||
@ -59,16 +64,16 @@ $(document).ready(function(){
|
||||
time = 0;
|
||||
nbsnd = sounds.length;
|
||||
//console.log('loading '+nbsnd+' sounds');
|
||||
oksnd = new Audio(sounds[1]);
|
||||
kosnd = new Audio(sounds[0]);
|
||||
nosnd = new Audio(sounds[2]);
|
||||
failsnd = new Audio(sounds[3]);
|
||||
endsnd = new Audio(sounds[4]);
|
||||
oksnd = new Audio(sounds[OK]);
|
||||
kosnd = new Audio(sounds[KO]);
|
||||
nosnd = new Audio(sounds[WALL]);
|
||||
failsnd = new Audio(sounds[LOSE]);
|
||||
endsnd = new Audio(sounds[WIN]);
|
||||
|
||||
left = 2;
|
||||
right = 2;
|
||||
top = 2;
|
||||
bottom = 2;
|
||||
p_left = 2;
|
||||
p_right = 2;
|
||||
p_top = 2;
|
||||
p_bottom = 2;
|
||||
|
||||
$('body').html('').append('<nav><a href="editor.html" title="Create your own labyrinth" class="left pill button">Create your own labyrinth</a><a href="list" title="Custom laby list" class="right pill button">Custom laby list</a></nav>').append('<div id="board"></div>');
|
||||
$('#board').append('<a href="#" id="start" title="click to start" class="primary positive button">Start?</a><br/><a href="#" id="instruction" title="Instructions to play" class="left button">Instruction</a> <a href="#" id="instructionfr" title="Instructions pour jouer" class="right button">Instructions en français</a>');
|
||||
@ -93,11 +98,11 @@ $(document).ready(function(){
|
||||
function playSound(sound){
|
||||
playColor(sound);
|
||||
switch(sound){
|
||||
case 0: kosnd.play(); break;
|
||||
case 1: oksnd.play(); break;
|
||||
case 2: nosnd.play(); break;
|
||||
case 3: failsnd.play(); break;
|
||||
case 4: endsnd.play(); break;
|
||||
case KO: kosnd.play(); break;
|
||||
case OK: oksnd.play(); break;
|
||||
case WALL: nosnd.play(); break;
|
||||
case LOSE: failsnd.play(); break;
|
||||
case WIN: endsnd.play(); break;
|
||||
default: /*failsnd.play();*/ break;
|
||||
}
|
||||
}
|
||||
@ -128,43 +133,18 @@ $(document).ready(function(){
|
||||
clearTimeout(totop);
|
||||
clearTimeout(toright);
|
||||
clearTimeout(tobot);
|
||||
left = level[currentPosition[1]][currentPosition[0]-1] == undefined ? 2 : level[currentPosition[1]][currentPosition[0]-1];
|
||||
shikitop = level[currentPosition[1]-1] == undefined ? 2 : level[currentPosition[1]-1][currentPosition[0]];
|
||||
right = level[currentPosition[1]][currentPosition[0]+1] == undefined ? 2 : level[currentPosition[1]][currentPosition[0]+1];
|
||||
bottom = level[currentPosition[1]+1] == undefined ? 2 : level[currentPosition[1]+1][currentPosition[0]];
|
||||
playSound(left); // left
|
||||
totop = setTimeout(playSound, 800, shikitop); // top
|
||||
toright = setTimeout(playSound, 1600, right); // right
|
||||
tobot = setTimeout(playSound, 2400, bottom); // bottom
|
||||
p_left = level[currentPosition[1]][currentPosition[0]-1] == undefined ? 2 : level[currentPosition[1]][currentPosition[0]-1];
|
||||
p_top = level[currentPosition[1]-1] == undefined ? 2 : level[currentPosition[1]-1][currentPosition[0]];
|
||||
p_right = level[currentPosition[1]][currentPosition[0]+1] == undefined ? 2 : level[currentPosition[1]][currentPosition[0]+1];
|
||||
p_bottom = level[currentPosition[1]+1] == undefined ? 2 : level[currentPosition[1]+1][currentPosition[0]];
|
||||
playSound(p_left); // left
|
||||
totop = setTimeout(playSound, 800, p_top); // top
|
||||
toright = setTimeout(playSound, 1600, p_right); // right
|
||||
tobot = setTimeout(playSound, 2400, p_bottom); // bottom
|
||||
}
|
||||
|
||||
function check1caseOnLeft(){
|
||||
return currentPosition[0] > 0;
|
||||
}
|
||||
|
||||
function check1caseOnTop(){
|
||||
return currentPosition[1] > 0;
|
||||
}
|
||||
function check1caseOnRight(){
|
||||
return currentPosition[0] + 1 < level[0].length;
|
||||
}
|
||||
function check1caseOnBottom(){
|
||||
return currentPosition[1] + 1 <= level.length;
|
||||
}
|
||||
function check2caseOnLeft(){
|
||||
return !(currentPosition[0] <= 1 || level[currentPosition[1]][currentPosition[0] - 1] == 1);
|
||||
}
|
||||
function check2caseOnTop(){
|
||||
return !(currentPosition[1] <= 1 || level[currentPosition[1] - 1][currentPosition[0]] == 1);
|
||||
}
|
||||
function check2caseOnRight(){
|
||||
|
||||
}
|
||||
function check2caseOnBottom(){
|
||||
|
||||
}
|
||||
function generateLevel(){
|
||||
// generer largeur / hauteur
|
||||
// generate largeur / hauteur
|
||||
var min = 5;
|
||||
var max = 15;
|
||||
var largeur = Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
@ -237,9 +217,8 @@ $(document).ready(function(){
|
||||
function gameover(){
|
||||
clearInterval(compte);
|
||||
clicked = false;
|
||||
//console.log('game over');
|
||||
playSound(3);
|
||||
var finalTime = parseFloat(time/10);
|
||||
playSound(LOSE);
|
||||
let finalTime = Math.round(time / 10);
|
||||
$('#board').html('You lost... <a href="#" id="retry" title="Click to try again">Do you want to try again?</a> You played : '+finalTime+'seconds');
|
||||
}
|
||||
|
||||
@ -256,7 +235,7 @@ $(document).ready(function(){
|
||||
function winningGame(){
|
||||
clicked = false;
|
||||
//console.log('You won !');
|
||||
playSound(4);
|
||||
playSound(WIN);
|
||||
$('#board').html('<a href="#" id="next" title="Load next level">Load next level</a>');
|
||||
}
|
||||
|
||||
@ -307,7 +286,7 @@ $(document).ready(function(){
|
||||
}
|
||||
break; // bas
|
||||
case 32: // barre espace
|
||||
playKey();
|
||||
playKey();
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
$file = isset($_GET['level']) ? $_GET['level'] : null;
|
||||
$file = $_GET['level'] ?? null;
|
||||
$custom = 'false';
|
||||
$niveau = '1';
|
||||
if ($file !== null && file_exists(__DIR__ .'/custom/'.$file.'.js')){
|
||||
@ -8,8 +8,9 @@ if ($file !== null && file_exists(__DIR__ .'/custom/'.$file.'.js')){
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Blind Laby</title>
|
||||
<link rel="stylesheet" type="text/css" href="assets/css/index.css" />
|
||||
<link rel="stylesheet" type="text/css" href="assets/css/css3buttons.css" />
|
||||
<style>
|
||||
|
@ -3,7 +3,7 @@ session_start();
|
||||
$currentFile = !empty($_SESSION['file']) ? $_SESSION['file'] : null;
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="index.css" />
|
||||
<style>
|
||||
@ -11,16 +11,17 @@ $currentFile = !empty($_SESSION['file']) ? $_SESSION['file'] : null;
|
||||
#start{display:block;}
|
||||
.current{background-color:yellow;}
|
||||
</style>
|
||||
<title>Blind Laby - Create your own</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="board">
|
||||
<?php
|
||||
$folder =new DirectoryIterator('../custom/');
|
||||
$folder = new DirectoryIterator('../custom/');
|
||||
|
||||
foreach($folder as $file){
|
||||
if(!$file->isDir()){
|
||||
if (!$file->isDir() && $file->getExtension() === 'js') {
|
||||
echo '<a href="http://labs.shikiryu.com/experimental-games/2/?level='.substr($file->getFileName(), 0, -3).'" title="laby '.substr($file->getFileName(), 0, -3).'"';
|
||||
if($currentFile !== null && $currentFile == $file->getFileName()) echo ' class="current"';
|
||||
if($currentFile !== null && $currentFile === $file->getFileName()) echo ' class="current"';
|
||||
echo '>laby '.substr($file->getFileName(), 0, -3).'</a><br/>';
|
||||
}
|
||||
}
|
||||
|
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/');
|
Loading…
Reference in New Issue
Block a user