ID:30 ブラウザで遊べるタイピングゲームの作り方
by 名無し 2009/05/24(Sun) 01:05:19
| ブラウザで遊べるタイピングゲームを作ろう! 使用言語 PHP JavaScriptとか |
ID:31 名無しさんからのお返事です
by 名無し 2009/05/24(Sun) 01:08:18
| //************************************************************************************************* // 受け渡されたパラメータ表示 //************************************************************************************************* ok_cnt = $ok; ng_cnt = $ng; hp_cnt = $hp; fc_cnt = $fc; if(!nowcnt){ var nowcnt = 0; //ターゲット文字位置 } //************************************************************************************************* // タイピングシステム //************************************************************************************************* function init() { //●BODYによりページ読み込みで再生される label.innerHTML = next(); exit; } function keyDown() { //●BODYによりキー入力で再生される var text = label.innerText; //◆グローバル変数の宣言 text2 = text.toUpperCase(); //大文字変換 var code = text2.charCodeAt(nowcnt); //text2の一文字目 if(event.keyCode == code) { //◇キー入力が正解のとき //●空白(32),ピリオド(46),カンマ(44),アポストロフィ(39) の場合スキップ txtsouce = text.substring((nowcnt + 1),(nowcnt + 2)); //alert(txtsouce + " / " + txtsouce.charCodeAt(0)); //★デバッグ用 if(txtsouce.charCodeAt(0) == 32 || txtsouce.charCodeAt(0) == 46 || txtsouce.charCodeAt(0) == 44 || txtsouce.charCodeAt(0) == 39){ nowcnt++; } //●↑空白など回避文字が続いた場合の処理(2つ以上続くなら改善の余地アリ) if(txtsouce.charCodeAt(0) == 32 || txtsouce.charCodeAt(0) == 46 || txtsouce.charCodeAt(0) == 44 || txtsouce.charCodeAt(0) == 39){ nowcnt++; } nowcnt++; //文字位置移動 text5 = text.substring(0, nowcnt); text7 = text.substring(nowcnt, (nowcnt + 1)); text = text.substring((nowcnt + 1), text.length); label.innerHTML = "<font color='#cccccc' style='font-size:1em;'>" + text5 + "</font>" + "<font style='color:#000000;font-size:1.3em;'>" + text7 + "</font>" + text; ok_cnt++; hp_cnt++; fc_cnt++; }else{ //◇キー入力が失敗のとき ng_cnt++; hp_cnt--; fc_cnt--; } total_ok.innerHTML = ok_cnt; //◆リアルタイムのパラメータ表示 total_ng.innerHTML = ng_cnt; // total_hp.innerHTML = hp_cnt; // total_fc.innerHTML = fc_cnt; // document.next.ok.value = ok_cnt; //◆ネクストフォームに現在値を格納 document.next.ng.value = ng_cnt; document.next.hp.value = hp_cnt; document.next.fc.value = fc_cnt; //●クリア if ((text7.length == 0) && text5){ //◇ターゲット文字をクリアしたとき //text5を置くことで初回ミスによるターゲット変更を回避 nowcnt = 0; //リセット text5 = ""; // label.innerHTML = next(); //◆次のターゲットを表示(暫定) } } //●BODYによりキー入力で再生される END function next() { //●次回のターゲット選定 //●クォーテーションやカンマによる不具合回避 get = typtgt.split("|"); var cnt = Math.round(Math.random()*(get.length-1)); text00 = get[cnt]; text00 = text00.replace(/&#039;/, "'"); //アポストロフィの変換(危険!) //alert(text00); var str = text00; var re = str.match(/#/i); text00 = RegExp.leftContext; //マッチした部分の左側の文字列を得る var meaning = RegExp.rightContext; mean.innerHTML = meaning; //text00 = get[cnt]; text01 = text00.substring(0,1); text02 = text00.substring(1,text00.length); return "<font color='blue' style='font-size:1.3em;'>" + text01 + "</font>" + text02; } ロジック書いてみた |






