code-katas/snake/snake.html

60 lines
2.6 KiB
HTML
Raw Normal View History

2014-12-08 19:49:28 -06:00
<!doctype html>
<html>
<head>
2014-12-09 14:59:06 -06:00
<meta name=charset value=utf-8>
<title>Snake</title>
<link href='http://fonts.googleapis.com/css?family=Exo+2:400,900' rel='stylesheet' type='text/css'>
2014-12-11 22:52:55 -06:00
<link href="snake.css" type="text/css" rel="stylesheet">
2014-12-08 19:49:28 -06:00
<script src="snake.js" type="application/javascript"></script>
</head>
<body>
2014-12-09 14:59:06 -06:00
<header><h1>Snake</h1></header>
2014-12-09 00:00:25 -06:00
<section id=controls>
<label>Rows</label>
<input id=rows type=text placeholder="Rows" value=20><br>
<label>Columns</label>
<input id=cols type=text placeholder="Columns" value=40><br>
<label>Speed (higher = faster)</label>
<input id=fps type=text placeholder="Speed (higher = faster)" value=10><br>
<input name=editor type=radio value="Game" checked>Game</input>
<input id=useEditor name=editor type=radio value="Editor">Editor</input>
<input id=reset type=button value="Apply">
</section>
<section id=gameData>
<label> Custom Level:</label><br>
<textarea class=boardData></textarea>
</section>
<section id=editorControls>
<textarea class=boardData></textarea>
<input type=button value=Reload>
</section>
<section id=help>
Arrow keys change direction.<br>
Pause key pauses the game.<br>
Enter restarts the game.<br>
</section>
2014-12-08 19:49:28 -06:00
2014-12-09 00:00:25 -06:00
<br>
<canvas id=gameCanvas width=800 height=400 tabIndex=100></canvas>
2014-12-08 19:49:28 -06:00
<script type="application/javascript">
var canvas = document.getElementById("gameCanvas");
var resetButton = document.getElementById("reset");
2014-12-09 00:00:25 -06:00
var customLevelData = document.querySelector("#gameData textarea");
2014-12-08 19:49:28 -06:00
2014-12-09 00:00:25 -06:00
Snake.initialize({ rows: parseInt(document.getElementById("rows").value),
2014-12-08 19:49:28 -06:00
cols: parseInt(document.getElementById("cols").value),
fps: parseInt(document.getElementById("fps").value)});
resetButton.onclick = function() {
2014-12-09 00:00:25 -06:00
if (customLevelData.value.trim().length > 0) {
Snake.initialize(JSON.parse(customLevelData.value)); }
else { Snake.initialize({
editor: document.getElementById("useEditor").checked,
rows: parseInt(document.getElementById("rows").value),
cols: parseInt(document.getElementById("cols").value),
fps: parseInt(document.getElementById("fps").value)}); } };
2014-12-08 19:49:28 -06:00
</script>
</body>
</html>