Skip to content

Commit 8ffa6fe

Browse files
committed
add info
1 parent 2be7f95 commit 8ffa6fe

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

Diff for: assets/js/game.js

+34-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ var player;
66
var getProblemFlag = false;
77
var myScore = 0;
88
var otherScore = 0;
9+
var q_ques = [];
10+
var q_ans = [];
11+
var q_det = [];
12+
var info_now = 0;
13+
var info_max = 0;
914
//答對變色
1015
function changeColor(who, correct) {
1116
var scoreDiv = $(`#${who}_score_div`);
@@ -51,6 +56,17 @@ function finish_show() {
5156
$(".q_box").hide();
5257
$("#mainend").show();
5358
}
59+
function set_info_q(){
60+
if (info_now == info_max){
61+
$("#mainend").show();
62+
$(".info").hide();
63+
} else {
64+
$("#info_question").text(q_ques[info_now]);
65+
$("#info_answer").text(q_ans[info_now]);
66+
$("#info_detail").text(q_det[info_now]);
67+
info_now += 1;
68+
}
69+
}
5470

5571
sock.on("connect", () => {
5672

@@ -68,8 +84,10 @@ sock.on("break", data => {
6884
if (!data.ok){
6985
alertify.error("抱歉遊戲爆炸了<br>on break ok return false");
7086
}
87+
q_ans.push(data.answer)
88+
q_det.push(data.detail)
7189
setTimeout(getnext(), 5000);
72-
$(".problem").fadeOut(500);
90+
$(".problem").hide();
7391
$(".correct_answer_text").text(data.answer); //答案這裡要更新
7492
$(".correct_answer").fadeIn(500);
7593
$(".progress-bar").css( "width", "0%" );
@@ -105,10 +123,11 @@ sock.on("getProblem", data => {
105123
alertify.error(`取得題目失敗<br>${data.mesg}`);
106124
} else {
107125
getProblemFlag = true
126+
q_ques.push(data.question)
108127
timmer_start();
109128
$(".q_box").show();
110129
$("#question_h1").text(data.question);
111-
$(".correct_answer").fadeOut(500);
130+
$(".correct_answer").hide();
112131
$(".problem").fadeIn(500);
113132
$(".problem").each((i, e) => {
114133
$(e).text(data.answers[i]);
@@ -150,7 +169,7 @@ sock.on("answer", data => {
150169
alertify.error("答錯了");
151170
changeColor("self", "error");
152171
}
153-
$(".problem").fadeOut(500);
172+
$(".problem").hide();
154173
$(".correct_answer_text").text(data.answer);
155174
$(".correct_answer").fadeIn(500);
156175
})
@@ -195,4 +214,16 @@ $(() => {
195214
});
196215
}
197216
});
217+
$("#info").on("click", function() {
218+
$("#mainend").hide();
219+
$(".info").show();
220+
info_max = q_ques.length;
221+
info_now = 0;
222+
set_info_q();
223+
});
224+
$("#info_next").on("click", function() {
225+
set_info_q();
226+
});
227+
228+
198229
})

Diff for: game.html

+16
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,29 @@ <h1 id="halt">Server error</h1>
9999
<h1>Rank</h1>
100100
<h1 id="haltrank">Server error</h1>
101101
</header>
102+
<ul class="actions special">
103+
<li><button id="info" class="button">查看詳解</button></li>
104+
</ul>
102105
<ul class="actions special">
103106
<li><a href="game.html" class="button">再來一局</a></li>
104107
</ul>
105108
<ul class="actions special">
106109
<li><a href="/" class="button">回首頁</a></li>
107110
</ul>
108111
</section>
112+
<!--詳細答案-->
113+
<section style="display:none" class="info" id="main">
114+
<header>
115+
<h1 id="info_question"></h1>
116+
<hr />
117+
<h1 id="info_answer"></h1>
118+
<hr />
119+
<h1 id="info_detail"></h1>
120+
</header>
121+
<ul class="actions special">
122+
<li><button id="info_next" class="button">下一題</button></li>
123+
</ul>
124+
</section>
109125
<!-- Footer -->
110126
<footer id="footer">
111127
<ul class="copyright">

0 commit comments

Comments
 (0)