Created
June 9, 2012 18:45
-
-
Save meru-akimbo/2902170 to your computer and use it in GitHub Desktop.
タイピングゲーム
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> | |
<link href="./css/index.css" rel="stylesheet" type="text/css" /> | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
$("#start").click( function() { | |
var tango = new Array(10); //単語の配列 | |
var tango_end = new Array(10); //使用済みの単語の配列 | |
tango[0]="windows"; | |
tango[1]="linux"; | |
tango[2]="mac"; | |
tango[3]="computer"; | |
tango[4]="blog"; | |
tango[5]="android"; | |
tango[6]="ios"; | |
tango[7]="javascript"; | |
tango[8]="twitter"; | |
tango[9]="facebook"; | |
var check = 0; | |
var word; | |
var word_trg; | |
var enter_word; | |
var echo_word=""; | |
var clear_word = 0; | |
var rand = Math.floor(Math.random()*1000); | |
rand = rand % 10; | |
word_trg = tango[rand]; | |
$("#word_word_trg").html("<font size='4'><b>"+word_trg+"</b></font>"); | |
var le = word_trg.length; | |
$("body").keypress( function( event ) { | |
word = word_trg.charAt(check); | |
enter_word = String.fromCharCode(event.which); | |
if(word == enter_word) //入力が正しい場合 | |
{ | |
echo_word += enter_word; | |
$("#word").html("<font size='4'><b>"+echo_word+"</b></font>"); | |
check = check + 1; | |
if(le == check) | |
{ | |
tango_end[clear_word] = tango[rand]; | |
clear_word = clear_word + 1; | |
if(clear_word >= tango.length) //すべての単語をクリアしている場合。アラートを表示して終わり | |
{ | |
alert("Clear"); | |
$("#word_word_trg").html(""); | |
$("#word").html(""); | |
} | |
else | |
{ | |
check = 0; | |
rand = Math.floor(Math.random()*1000); | |
rand = rand % 10; | |
var i = 0; | |
while(i < clear_word) //クリア済の単語を避ける | |
{ | |
if(tango_end[i] == tango[rand]) | |
{ | |
rand = Math.floor(Math.random()*1000); | |
rand = rand % 10; | |
i = 0; | |
} | |
else | |
{ | |
i++; | |
} | |
} | |
word_trg = tango[rand]; | |
le = word_trg.length; | |
echo_word = ""; | |
$("#word_word_trg").html("<font size='4'><b>"+word_trg+"</b></font>"); | |
$("#word").html("<font size='4'><b>"+echo_word+"</b></font>"); | |
} | |
} | |
} | |
}); | |
}); | |
}); | |
</script> | |
<title>タイピングゲー</title> | |
</head> | |
<body> | |
<table border="5"> | |
<tr> | |
<td><font size="5"><b>タイピングゲー</b></font></td> | |
</tr> | |
<tr> | |
<td>単語:<span id="word_word_trg" /></td> | |
</tr> | |
<tr> | |
<td>入力:<span id="word" /></td> | |
</tr> | |
<tr> | |
<td><button id="start" />スタート</button></td> | |
</tr> | |
<tr> | |
<td><span id="kekka" /></td> | |
</tr> | |
</table> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment