This commit is contained in:
Adrien MALINGREY 2019-10-28 03:08:01 +01:00
parent 350186ab06
commit 88837d8992
9 changed files with 2446 additions and 2440 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
db_info.txt

View File

@ -1,17 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Webtris</title>
<link rel="stylesheet" type="text/css" href="css/index.css" />
<script type="text/javascript" src="js/index.js"></script>
</head>
<body>
<h1>WEBTRIS</h1>
<div id="actions">
</div>
<div class="play">
<a href="webtris.html"><b>JOUER</b></a>
</div>
</body>
</html>

36
index.php Normal file
View File

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Webtris</title>
<link rel="stylesheet" type="text/css" href="css/index.css" />
<script type="text/javascript" src="js/index.js"></script>
</head>
<body>
<h1>WEBTRIS</h1>
<div id="actions">
<?php
$actionLabel = array(
"moveLeft" => "GAUCHE",
"moveRight" => "DROITE",
"softDrop" => "CHUTE LENTE",
"hardDrop" => "CHUTE RAPIDE",
"rotateCW" => "ROTATION HORAIRE",
"rotateCCW:" => "ROTATE INVERSE",
"hold" => "GARDE",
"pause" => "PAUSE",
);
foreach($actionLabel as $action => $label)
{
echo " <div>$label</div>\n";
echo " <button type='button' onclick='changeKey(this, \"$action\")'>\n";
echo " <script>getKey(\"$action\")</script>\n";
echo " </button>\n";
}
?>
</div>
<div class="play">
<a href="webtris.html"><b>JOUER</b></a>
</div>
</body>
</html>

View File

@ -1,13 +1,3 @@
const actionLabel = [
{name: "moveLeft", label: "GAUCHE"},
{name: "moveRight", label: "DROITE"},
{name: "softDrop", label: "CHUTE LENTE"},
{name: "hardDrop", label: "CHUTE RAPIDE"},
{name: "rotateCW", label: "ROTATION HORAIRE"},
{name: "rotateCCW:", label: "ROTATE INVERSE"},
{name: "hold", label: "GARDE"},
{name: "pause", label: "PAUSE"}
]
const actionsDefaultKeys = { const actionsDefaultKeys = {
moveLeft: "ArrowLeft", moveLeft: "ArrowLeft",
moveRight: "ArrowRight", moveRight: "ArrowRight",
@ -23,10 +13,10 @@ var selectedAction = ""
function getKey(action) { function getKey(action) {
key = localStorage.getItem(action) || actionsDefaultKeys[action] key = localStorage.getItem(action) || actionsDefaultKeys[action]
if (key == ' ') if (key == ' ') key = "Space"
return "Space" document.open()
else document.write(key)
return key document.close()
} }
function changeKey(button, action) { function changeKey(button, action) {
@ -45,9 +35,5 @@ function keyUpHandler(e) {
} }
window.onload = function() { window.onload = function() {
document.getElementById("actions").innerHTML = actionLabel.map(action => `<div>${action.label}</div>
<button type="button" onclick="changeKey(this, '${action.name}')">${getKey(action.name)}</button>
`).join("\n")
addEventListener("keyup", keyUpHandler, false) addEventListener("keyup", keyUpHandler, false)
} }