Add keyboard controls
This commit is contained in:
parent
238567e5a2
commit
eae2282340
@ -70,7 +70,12 @@ body {
|
|||||||
margin-bottom: 2px;
|
margin-bottom: 2px;
|
||||||
border: 1px solid lightgray;
|
border: 1px solid lightgray;
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
text-align: left; }
|
text-align: left;
|
||||||
|
counter-increment: answer; }
|
||||||
|
.ingame-screen .question .question-answers .answer::before {
|
||||||
|
content: counter(answer);
|
||||||
|
color: lightgray;
|
||||||
|
padding: 0.5em; }
|
||||||
.ingame-screen .question .question-estimate {
|
.ingame-screen .question .question-estimate {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 7fr 3fr; }
|
grid-template-columns: 7fr 3fr; }
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"version": 3,
|
"version": 3,
|
||||||
"mappings": "AAAA,IAAI;EACF,UAAU,EAAE,KAAK;EACjB,OAAO,EAAE,IAAI;EACb,WAAW,EAAE,MAAM;EACnB,eAAe,EAAE,MAAM;EACvB,WAAW,EAAE,MAAM;EACnB,gBAAgB,EAAE,0BAA0B;EAC5C,eAAe,EAAE,KAAK;EAEtB,YAAO;IACL,KAAK,EAAE,KAAK;IACZ,SAAS,EAAE,IAAI;IACf,UAAU,EAAE,IAAI;IAChB,gBAAgB,EAAE,wBAAuB;EAE3C,OAAE;IACA,WAAW,EAAE,gBAAgB;IAC7B,SAAS,EAAE,IAAI;EAEjB,OAAE;IACA,WAAW,EAAE,MAAM;EAErB,iBAAY;IACV,gBAAgB,EAAE,IAAI;;AAE1B,0BAA0B;EACxB,OAAO,EAAE,IAAI;EACb,WAAW,EAAE,MAAM;EACnB,eAAe,EAAE,MAAM;EACvB,cAAc,EAAE,MAAM;EAEtB,sCAAK;IACH,SAAS,EAAE,KAAK;EAElB,gDAAU;IACR,OAAO,EAAE,MAAK;IACd,MAAM,EAAE,mBAAmB;IAC3B,aAAa,EAAE,CAAC;IAChB,KAAK,EAA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f,gBAAgB,EAAE,yBAAyB;QAC3C,eAAe,EAAE,OAAO;EAE9B,4BAAa;IACX,OAAO,EAAE,KAAK;IACd,UAAU,EAAE,IAAI;IAChB,KAAK,EAAE,IAAI;IACX,aAAa,EAAE,CAAC;IAChB,MAAM,EAAE,mBAAmB;IAC3B,OAAO,EAAE,MAAK;;;;IAId,SAAS,EAAE,QAAQ;;IAEnB,SAAS,EAAE,UAAU;;IAErB,SAAS,EAAE,UAAS;;IAEpB,SAAS,EAAE,UAAU;;IAErB,SAAS,EAAE,QAAQ",
|
||||||
"sources": ["style.sass"],
|
"sources": ["style.sass"],
|
||||||
"names": [],
|
"names": [],
|
||||||
"file": "style.css"
|
"file": "style.css"
|
||||||
|
|||||||
@ -91,6 +91,12 @@ body
|
|||||||
border: 1px solid lightgray
|
border: 1px solid lightgray
|
||||||
border-radius: 0
|
border-radius: 0
|
||||||
text-align: left
|
text-align: left
|
||||||
|
counter-increment: answer
|
||||||
|
|
||||||
|
&::before
|
||||||
|
content: counter(answer)
|
||||||
|
color: lightgray
|
||||||
|
padding: .5em
|
||||||
|
|
||||||
.question-estimate
|
.question-estimate
|
||||||
display: grid
|
display: grid
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
<section v-if="mode === STARTSCREEN" class="start-screen screen">
|
<section v-if="mode === STARTSCREEN" class="start-screen screen">
|
||||||
<img class="logo" src="img/wiai-logo.png" alt="Logo der Fachschaft WIAI"/>
|
<img class="logo" src="img/wiai-logo.png" alt="Logo der Fachschaft WIAI"/>
|
||||||
<h1 class="headline">Willkommen zum WIAI-Weihnachtsquiz!</h1>
|
<h1 class="headline">Willkommen zum WIAI-Weihnachtsquiz!</h1>
|
||||||
<button v-on:click="enterGame" class="btn-start" tabindex="0" v-on:keyup.enter="enterGame">Starten</button>
|
<button v-on:click="enterGame" class="btn-start" v-focus v-on:keyup.enter="enterGame">Starten</button>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section v-if="mode === INGAME" class="ingame-screen screen">
|
<section v-if="mode === INGAME" class="ingame-screen screen">
|
||||||
@ -33,6 +33,7 @@
|
|||||||
<div class="question-answers">
|
<div class="question-answers">
|
||||||
<button
|
<button
|
||||||
v-for="answer in currentQuestion.answers"
|
v-for="answer in currentQuestion.answers"
|
||||||
|
v-bind:disabled="currentQuestionAnswered"
|
||||||
@click="evaluateChoice(answer.id)"
|
@click="evaluateChoice(answer.id)"
|
||||||
v-bind:class="{ correct: isCorrectAnswer(answer.id), answer: true, chosen: isUserChoice(answer.id) }">
|
v-bind:class="{ correct: isCorrectAnswer(answer.id), answer: true, chosen: isUserChoice(answer.id) }">
|
||||||
{{answer.text}}
|
{{answer.text}}
|
||||||
@ -43,8 +44,8 @@
|
|||||||
<article v-if="isEstimate" class="question estimate" v-bind:class="{revealed: currentQuestionAnswered}">
|
<article v-if="isEstimate" class="question estimate" v-bind:class="{revealed: currentQuestionAnswered}">
|
||||||
<h2 class="question-text">{{currentQuestion.text}}</h2>
|
<h2 class="question-text">{{currentQuestion.text}}</h2>
|
||||||
<div class="question-estimate">
|
<div class="question-estimate">
|
||||||
<input v-bind:value="currentEstimate" id="input-estimate" type="number"
|
<input value="" id="input-estimate" type="number"
|
||||||
min="0" class="input-estimate" @v-keyup.enter="evaluateEstimate" v-bind:disabled="currentQuestionAnswered"/>
|
min="0" class="input-estimate" @v-on:keyup.enter="evaluateEstimate" v-bind:disabled="currentQuestionAnswered" v-focus/>
|
||||||
<input type="submit" @click="evaluateEstimate" class="btn-submit-estimate" v-bind:disabled="currentQuestionAnswered" value="Auswerten"/>
|
<input type="submit" @click="evaluateEstimate" class="btn-submit-estimate" v-bind:disabled="currentQuestionAnswered" value="Auswerten"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
43
js/app.js
43
js/app.js
@ -1,3 +1,9 @@
|
|||||||
|
Vue.directive('focus', {
|
||||||
|
inserted: function (el) {
|
||||||
|
el.focus()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const app = new Vue({
|
const app = new Vue({
|
||||||
el: '#app',
|
el: '#app',
|
||||||
data: {
|
data: {
|
||||||
@ -27,12 +33,36 @@ const app = new Vue({
|
|||||||
beforeMount () {
|
beforeMount () {
|
||||||
this.questions = []
|
this.questions = []
|
||||||
const questionCandidates = questionCatalog.slice()
|
const questionCandidates = questionCatalog.slice()
|
||||||
for (let i = 0; i < Math.min(20, questionCatalog.length); i++) {
|
for (let i = 0; i < Math.min(9, questionCatalog.length); i++) {
|
||||||
const index = Math.floor(Math.random() * questionCandidates.length)
|
const index = Math.floor(Math.random() * questionCandidates.length)
|
||||||
this.questions.push(questionCandidates[index])
|
this.questions.push(questionCandidates[index])
|
||||||
questionCandidates.splice(index, 1)
|
questionCandidates.splice(index, 1)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
mounted: function () {
|
||||||
|
window.addEventListener('keypress', e => {
|
||||||
|
switch (e.key) {
|
||||||
|
case '1':
|
||||||
|
this.isChoice && !this.currentQuestionAnswered && this.evaluateChoice(0)
|
||||||
|
return
|
||||||
|
case '2':
|
||||||
|
this.isChoice && !this.currentQuestionAnswered && this.evaluateChoice(1)
|
||||||
|
return
|
||||||
|
case '3':
|
||||||
|
this.isChoice && !this.currentQuestionAnswered && this.evaluateChoice(2)
|
||||||
|
return
|
||||||
|
case 'Enter':
|
||||||
|
if (this.currentQuestionAnswered) {
|
||||||
|
this.showNextQuestion()
|
||||||
|
} else if (this.isEstimate && document.querySelector('#input-estimate').value !== '') {
|
||||||
|
this.evaluateEstimate()
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
console.log(e.key)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
enterGame: function (event) {
|
enterGame: function (event) {
|
||||||
this.mode = this.INGAME
|
this.mode = this.INGAME
|
||||||
@ -52,7 +82,7 @@ const app = new Vue({
|
|||||||
this.currentQuestionAnswerID = answerID
|
this.currentQuestionAnswerID = answerID
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
evaluateEstimate: function (value) {
|
evaluateEstimate: function () {
|
||||||
if (!this.currentQuestionAnswered) {
|
if (!this.currentQuestionAnswered) {
|
||||||
const estimateInput = document.querySelector('#input-estimate')
|
const estimateInput = document.querySelector('#input-estimate')
|
||||||
|
|
||||||
@ -95,17 +125,22 @@ const app = new Vue({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
showNextQuestion: function (event) {
|
showNextQuestion: function () {
|
||||||
if (this.currentQuestionAnswered) {
|
if (this.currentQuestionAnswered) {
|
||||||
|
if (this.currentQuestion.type === 'estimate') {
|
||||||
|
document.querySelector('#input-estimate').value = ''
|
||||||
|
}
|
||||||
|
|
||||||
this.currentQuestionAnswered = false
|
this.currentQuestionAnswered = false
|
||||||
this.currentQuestionAnswerID = null
|
this.currentQuestionAnswerID = null
|
||||||
|
|
||||||
if (this.currentQuestionID + 1 < this.questions.length) {
|
if (this.currentQuestionID + 1 < this.questions.length) {
|
||||||
this.currentQuestionID++
|
this.currentQuestionID++
|
||||||
|
this.$forceUpdate
|
||||||
} else {
|
} else {
|
||||||
this.mode = this.ENDSCREEN
|
this.mode = this.ENDSCREEN
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
event.stopPropagation()
|
|
||||||
},
|
},
|
||||||
isCorrectAnswer: function (answerID) {
|
isCorrectAnswer: function (answerID) {
|
||||||
return this.currentQuestion.correctAnswerID === answerID
|
return this.currentQuestion.correctAnswerID === answerID
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user