// 練習!英単語用JS // 問題 var questionSrc; var questionAry; var nowNo, nowQuestion, nowJapanese, nowAnswer; var mode, count; $(function(){ // 初期設定 initGame(); $.ajax({ type: "POST", url: "/practice/doGetPractice/", data: {mode: "ajax", user_id:userId}, success: function(data2){ tmp = $.parseJSON(data2); questionAry = tmp.questions.split(''); // ゲーム画面へ setMode(11); } }); // キーボードイベント取得 $("body").keypress(function(e){ if(mode == 12){ // ゲーム中のとき var answer = String.fromCharCode(e.which); $(".choice" + answer).addClass("choiced"); checkAnswer(answer); }else if(mode == 13){ // 回答表示状態のとき goNextQuestion(); } }); $(document).on("mouseover", "#choices li", function(){ $(this).addClass("choiced"); }); $(document).on("mouseout", "#choices li", function(){ $(this).removeClass("choiced"); }); $(document).on("click", "#choices li", function(){ if(mode == 12){ // ゲーム中のとき var answer = $(this).data("no"); checkAnswer(answer); } }); $("body").click(function(e){ if(mode == 13){ // 回答表示状態のとき goNextQuestion(); } }); }); // 初期設定 function initGame(){ gs = $("#gameScreen"); setMode(1); } // モードごとの初期設定 function setMode(pMode){ mode = pMode; count = 0; switch(mode){ case 11: // ゲーム画面準備 drawGameScreen(); nowNo = 0; setQuestionPractice(); setMode(12); break; case 12: // ゲーム中 break; case 13: // 回答表示状態 break; } } // ■■■ 以後、練習モード用 ■■■ function setQuestionPractice(){ var tmpAry = questionAry[nowNo].split(':'); var markAry = {0:"①", 1:"②", 2:"③", 3:"④", 4:"⑤"}; nowQuestion = tmpAry[0]; nowChoiceAry = tmpAry[1].split('<,>'); nowAnswer = tmpAry[2]; $("#question").html(nowQuestion); $("#answer").html(""); $("#choices").html(''); for(var i = 1; i <= nowChoiceAry.length; i++){ $("#choices").append("
  • " + markAry[i - 1] + "" + nowChoiceAry[i - 1] + "
  • "); } } // 正解したことをサーバーに送信 function sendCollect(english, japanese){ $.ajax({ type: "POST", url: "/index/doRegisterCollect/", data: { mode: "ajax", user_id:userId, english:english, japanese:japanese }, success: function(result){ } }); } // 間違えた問題をサーバーに送信 function sendWrongList(english, japanese){ $.ajax({ type: "POST", url: "/index/doRegisterWrong/", data: { mode: "ajax", user_id:userId, english:english, japanese:japanese }, success: function(result){ } }); } // ゲーム画面 function drawGameScreen(){ gs.children().remove(); gs.append('

    '); gs.append('

    '); gs.append('

    '); gs.append(''); gs.append('

    '); gs.append('

    '); gs.append('

    PUSH ANY KEY

    '); } // 回答のチェック function checkAnswer(answer){ if(answer == nowAnswer){ // 正解のとき $("#resultCorrect").text("正解!"); sendCollect(nowQuestion, nowChoiceAry[nowAnswer - 1]); }else{ if(answer != 5){ // 「分からない」じゃないとき $("#resultIncorrect").text("不正解"); } sendWrongList(nowQuestion, nowChoiceAry[nowAnswer - 1]); } $(".choice" + nowAnswer).addClass("answer"); $("#pushAnyKey").css("display", "block"); setMode(13); } // 次の問題へ function goNextQuestion(){ $("#resultCorrect").text(""); $("#resultIncorrect").text(""); $("#pushAnyKey").css("display", "none"); // 次の問題へ if(nowNo < 100){ nowNo++; setQuestionPractice(); } setMode(12); }