113 lines
3.2 KiB
HTML
113 lines
3.2 KiB
HTML
|
<!doctype html>
|
||
|
<html>
|
||
|
<!--
|
||
|
/_ ... _ /_
|
||
|
/_//_/ ////_//_//_//\
|
||
|
_/ _//
|
||
|
-->
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||
|
<title>hgman</title>
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||
|
<style type="text/css">
|
||
|
body {
|
||
|
font-size: 24px;
|
||
|
}
|
||
|
|
||
|
.wrap {
|
||
|
max-width: 400px;
|
||
|
margin: 10px auto;
|
||
|
}
|
||
|
|
||
|
div.word, div.lives {
|
||
|
text-align: center;
|
||
|
}
|
||
|
|
||
|
div.keyboard {
|
||
|
text-align: center;
|
||
|
}
|
||
|
|
||
|
div.keyboard button {
|
||
|
padding: 8px;
|
||
|
border: 1px solid #999;
|
||
|
box-sizing: border-box;
|
||
|
margin: 2px;
|
||
|
}
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
<div class="wrap">
|
||
|
<div id="WORD" class="word">
|
||
|
LOADING
|
||
|
</div>
|
||
|
|
||
|
<div id="lives" class="lives">
|
||
|
...
|
||
|
</div>
|
||
|
|
||
|
<div class="keyboard">
|
||
|
<button onclick="offChar('A')">A</button><button onclick="offChar('B')">B</button><button onclick="offChar('C')">C</button><button onclick="offChar('D')">D</button><button onclick="offChar('E')">E</button><button onclick="offChar('F')">F</button><button onclick="offChar('G')">G</button><button onclick="offChar('H')">H</button><button onclick="offChar('I')">I</button><button onclick="offChar('J')">J</button><button onclick="offChar('K')">K</button><button onclick="offChar('L')">L</button><button onclick="offChar('M')">M</button><button onclick="offChar('N')">N</button><button onclick="offChar('O')">O</button><button onclick="offChar('P')">P</button><button onclick="offChar('Q')">Q</button><button onclick="offChar('R')">R</button><button onclick="offChar('S')">S</button><button onclick="offChar('T')">T</button><button onclick="offChar('U')">U</button><button onclick="offChar('V')">V</button><button onclick="offChar('W')">W</button><button onclick="offChar('X')">X</button><button onclick="offChar('Y')">Y</button><button onclick="offChar('Z')">Z</button>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<script type="text/javascript">
|
||
|
var words = ['wood', 'speed'];
|
||
|
|
||
|
var lives = 6;
|
||
|
var gameWord = words[Math.floor(Math.random() * words.length)].toUpperCase();
|
||
|
var gameAnswered = new Array(gameWord.length + 1).join('-')
|
||
|
|
||
|
window.onload = function()
|
||
|
{
|
||
|
console.log(gameWord)
|
||
|
document.getElementById("WORD").innerHTML = gameAnswered;
|
||
|
document.getElementById("lives").innerHTML = lives;
|
||
|
}
|
||
|
|
||
|
function wrong()
|
||
|
{
|
||
|
lives -= 1;
|
||
|
document.getElementById("lives").innerHTML = lives;
|
||
|
}
|
||
|
|
||
|
function offChar(char)
|
||
|
{
|
||
|
if (gameAnswered.split('').indexOf('-') == -1)
|
||
|
{
|
||
|
alert('You Win');
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (lives == 0) {
|
||
|
alert('You dead');
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var indices = [];
|
||
|
var idx = gameWord.split('').indexOf(char)
|
||
|
if (idx == -1)
|
||
|
{
|
||
|
wrong();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
while (idx != -1)
|
||
|
{
|
||
|
indices.push(idx);
|
||
|
idx = gameWord.split('').indexOf(char, idx + 1);
|
||
|
}
|
||
|
console.log(indices)
|
||
|
|
||
|
indices.forEach(function(item, indices)
|
||
|
{
|
||
|
var wordArray = gameAnswered.split('')
|
||
|
wordArray[item] = char;
|
||
|
gameAnswered = wordArray.join('');
|
||
|
document.getElementById("WORD").innerHTML = gameAnswered;
|
||
|
})
|
||
|
}
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|