php
This commit is contained in:
parent
350186ab06
commit
88837d8992
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
db_info.txt
|
17
index.html
17
index.html
@ -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
36
index.php
Normal 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>
|
22
js/index.js
22
js/index.js
@ -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 = {
|
||||
moveLeft: "ArrowLeft",
|
||||
moveRight: "ArrowRight",
|
||||
@ -23,10 +13,10 @@ var selectedAction = ""
|
||||
|
||||
function getKey(action) {
|
||||
key = localStorage.getItem(action) || actionsDefaultKeys[action]
|
||||
if (key == ' ')
|
||||
return "Space"
|
||||
else
|
||||
return key
|
||||
if (key == ' ') key = "Space"
|
||||
document.open()
|
||||
document.write(key)
|
||||
document.close()
|
||||
}
|
||||
|
||||
function changeKey(button, action) {
|
||||
@ -45,9 +35,5 @@ function keyUpHandler(e) {
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
Reference in New Issue
Block a user