load questions, initialize scoreboard
This commit is contained in:
parent
772a0a9625
commit
daccb1d5c4
|
@ -0,0 +1,18 @@
|
|||
[
|
||||
{ "question": "Как овас?",
|
||||
"tier": 1000,
|
||||
"answers": [ { "text": "Орчин хорошо",
|
||||
"right": true },
|
||||
{ "text": "Хорошо" },
|
||||
{ "text": "Не хорошо" },
|
||||
{ "text": "Исвинизие?" }
|
||||
] },
|
||||
{ "question": "где выхад?",
|
||||
"tier": 2000,
|
||||
"answers": [ { "text": "Я вы́йду о вас" },
|
||||
{ "text": "Я не снаю" },
|
||||
{ "text": "слева",
|
||||
"right": true },
|
||||
{ "text": "справа" }
|
||||
] }
|
||||
]
|
26
index.html
26
index.html
|
@ -23,12 +23,9 @@
|
|||
|
||||
<div id="game">
|
||||
<ul id="players">
|
||||
<li><span class="name">Fnord</span><span class="score">£ 35,000</span></li>
|
||||
<li><span class="name">Eris</span><span class="score">£ 5,000</span></li>
|
||||
<li><span class="name active">Hagbard C.</span><span class="score">£ 67,000</span></li>
|
||||
</ul>
|
||||
<p id="tier">
|
||||
£30,000
|
||||
30,000
|
||||
</p>
|
||||
<div id="question">
|
||||
<p>Welches Land erlaubt Filesharing für private Zwecke straffrei?</p>
|
||||
|
@ -47,30 +44,9 @@
|
|||
|
||||
<div id="scoreboard">
|
||||
<ul id="tiers">
|
||||
<li>£ 1,000</li>
|
||||
<li>£ 2,000</li>
|
||||
<li>£ 3,000</li>
|
||||
<li>£ 4,000</li>
|
||||
<li>£ 5,000</li>
|
||||
<li>£ 6,000</li>
|
||||
<li>£ 7,000</li>
|
||||
<li>£ 8,000</li>
|
||||
<li>£ 9,000</li>
|
||||
<li>£ 0,000,000</li>
|
||||
<li>£ 1,000,000</li>
|
||||
<li>£ 2,000,000</li>
|
||||
<li>£ 3,000,000</li>
|
||||
<li>£ 4,000,000</li>
|
||||
<li>£ 5,000,000</li>
|
||||
</ul>
|
||||
|
||||
<dl>
|
||||
<dt>Fnord</dt>
|
||||
<dd>£ 35,000</dd>
|
||||
<dt>Eris</dt>
|
||||
<dd>£ 5,000</dd>
|
||||
<dt>Hagbard C.</dt>
|
||||
<dd>£ 67,000</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
[
|
||||
{ question: "Как овас?",
|
||||
answers: [ { text: "Орчин хорошо",
|
||||
right: true },
|
||||
{ text: "Хорошо" },
|
||||
{ text: "Не хорошо" },
|
||||
{ text: "Исвинизие?" }
|
||||
] },
|
||||
|
||||
{ question: "где выхад?",
|
||||
answers: [ { text: "Я вы́йду о вас" },
|
||||
{ text: "Я не снаю" },
|
||||
{ text: "слева",
|
||||
right: true },
|
||||
{ text: "справа" }
|
||||
] }
|
||||
]
|
63
quiz.js
63
quiz.js
|
@ -2,19 +2,70 @@ $(window).bind('load', function() {
|
|||
$('#game').hide();
|
||||
$('#scoreboard').hide();
|
||||
|
||||
$('#setup').show();
|
||||
$('#start').bind('click', startQuiz);
|
||||
loadQuizData(function() {
|
||||
// Quiz data has initialized
|
||||
$('#setup').show();
|
||||
$('#start').bind('click', function() {
|
||||
try {
|
||||
startQuiz();
|
||||
} catch (e) {
|
||||
console.error(e.stack);
|
||||
}
|
||||
return false; // don't submit <form>
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var questions;
|
||||
var currentQuestion = 0;
|
||||
|
||||
function loadQuizData(done) {
|
||||
$.ajax({ url: 'data/questions.json',
|
||||
contentType: 'json',
|
||||
success: function(data, status) {
|
||||
if (typeof data === 'string')
|
||||
data = JSON.parse(data);
|
||||
|
||||
console.log(status);
|
||||
questions = data;
|
||||
done();
|
||||
},
|
||||
error: function(req, status, e) {
|
||||
console.error(status);
|
||||
console.log(e.stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var playerNames = [];
|
||||
|
||||
function startQuiz() {
|
||||
var i;
|
||||
console.log('startQuiz');
|
||||
for(i = 0; i < 5; i++)
|
||||
playerNames[i] = $('#playername' + i).val();
|
||||
|
||||
console.log(JSON.stringify(playerNames));
|
||||
questions.forEach(function(q) {
|
||||
$('#tiers').append('<li></li>');
|
||||
$('#tiers li').last().text(q.tier);
|
||||
});
|
||||
|
||||
return false; // don't submit <form>
|
||||
for(i = 0; i < 5; i++) {
|
||||
var name = $('#playername' + i).val();
|
||||
if (!name)
|
||||
continue; // skip empty players
|
||||
|
||||
playerNames[i] = name;
|
||||
$('#scoreboard dl').append('<dt></dt><dd>0</dd>');
|
||||
$('#scoreboard dl dt').last().text(name);
|
||||
$('#players').append('<li class="player'+i+'"><span class="name"></span><span class="score">0</span></li>');
|
||||
$('#players li.player'+i+' span.name').text(name);
|
||||
}
|
||||
|
||||
$('#setup').fadeOut(100, function() {
|
||||
switchToScoreboard();
|
||||
});
|
||||
}
|
||||
|
||||
function switchToScoreboard() {
|
||||
$('#scoreboard').fadeIn(300, function() {
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue