From 011db14f382b492ffc5073d23c6eb89a8bb84e7a Mon Sep 17 00:00:00 2001 From: Antti Pilto Date: Fri, 5 Aug 2016 00:48:07 +0300 Subject: [PATCH] stage progress --- src/components/App/App.scss | 4 +++ src/components/Game/Game.jsx | 2 +- src/components/Game/Question.jsx | 57 +++++++++++++++++++++++-------- src/components/Game/Question.scss | 42 ++++++++++++++++------- src/components/Navbar/Navbar.jsx | 3 +- src/components/Navbar/Navbar.scss | 5 +++ src/data/kanaDictionary.js | 56 +----------------------------- src/data/quizSettings.js | 8 +++++ 8 files changed, 93 insertions(+), 84 deletions(-) create mode 100644 src/data/quizSettings.js diff --git a/src/components/App/App.scss b/src/components/App/App.scss index 0aeb350..d957c78 100644 --- a/src/components/App/App.scss +++ b/src/components/App/App.scss @@ -31,4 +31,8 @@ body { } .game { padding-top: 70px; +} +.glyphicon-none:before { + content: "\2122"; + color: transparent !important; } \ No newline at end of file diff --git a/src/components/Game/Game.jsx b/src/components/Game/Game.jsx index f14d685..a81ab34 100644 --- a/src/components/Game/Game.jsx +++ b/src/components/Game/Game.jsx @@ -8,7 +8,7 @@ class Game extends Component { constructor(props) { super(props); this.state = { - stage:0, + stage:1, showScreen: '' } this.showQuestion = this.showQuestion.bind(this); diff --git a/src/components/Game/Question.jsx b/src/components/Game/Question.jsx index d11ae74..6eeccbd 100644 --- a/src/components/Game/Question.jsx +++ b/src/components/Game/Question.jsx @@ -1,5 +1,6 @@ import React, { Component } from 'react'; import { kanaDictionary } from '../../data/kanaDictionary'; +import { quizSettings } from '../../data/quizSettings'; import { findRomajisAtKanaKey, removeFromArray, arrayContains, shuffle } from '../../data/helperFuncs'; import './Question.scss'; @@ -10,7 +11,8 @@ class Question extends Component { previousQuestion: [], previousAnswer: '', currentQuestion: [], - answerOptions: [] + answerOptions: [], + stageProgress: 0 } this.setNewQuestion = this.setNewQuestion.bind(this); this.handleAnswer = this.handleAnswer.bind(this); @@ -64,6 +66,10 @@ class Question extends Component { this.previousAnswer = answer; this.setState({previousAnswer: this.previousAnswer}); this.previousAllowedAnswers = this.allowedAnswers; + if(this.isInAllowedAnswers(this.previousAnswer)) + this.setState({stageProgress: this.state.stageProgress+1}); + else + this.setState({stageProgress: this.state.stageProgress > 0 ? this.state.stageProgress-1 : 0}); this.setNewQuestion(); } @@ -104,18 +110,24 @@ class Question extends Component { } getPreviousResult() { - let resultString; + let resultString=''; // console.log(this.previousAnswer); - if(this.previousQuestion=='' || this.previousAnswer=='') + if(this.previousQuestion=='') resultString =
Let's go! Which character is this?
- else if(this.isInAllowedAnswers(this.previousAnswer)) - resultString =
Correct!
- else - resultString =
Wrong!
- + else { + let rightAnswer = (this.props.stage==2?findRomajisAtKanaKey(this.previousQuestion)[0]:this.previousQuestion)+' = '+ + this.previousAllowedAnswers[0]; + if(this.isInAllowedAnswers(this.previousAnswer)) + resultString =
{rightAnswer}
+ else + resultString =
{rightAnswer}
+ } return resultString; } + getStageProgress() { + } + isInAllowedAnswers(previousAnswer) { // console.log(previousAnswer); // console.log(this.allowedAnswers); @@ -136,17 +148,32 @@ class Question extends Component { let btnClass = "btn btn-default answer-button"; if ('ontouchstart' in window) btnClass += " no-hover"; // disables hover effect on touch screens + let stageProgressPercentage = Math.round((this.state.stageProgress/quizSettings.stageLength[this.props.stage])*100)+'%'; + let stageProgressPercentageStyle = { width: stageProgressPercentage } return (
{this.getPreviousResult()}
{this.getShowableQuestion()}
- {this.state.answerOptions.map(function(answer, idx) { - return - }, this)} +
+ {this.state.answerOptions.map(function(answer, idx) { + return + }, this)} +
+
+
+ Stage {this.props.stage} +
+
); } diff --git a/src/components/Game/Question.scss b/src/components/Game/Question.scss index ebd0bb8..7cfbf0e 100644 --- a/src/components/Game/Question.scss +++ b/src/components/Game/Question.scss @@ -1,23 +1,40 @@ .question { + .progress { + position: relative; + background-color: #ddd; + height: 30px; + @media (max-width: 768px) { + max-width: 360px; + margin: 0 auto; + } + } + .progress span { + position: absolute; + top: 5px; + color: #444; + display: block; + width: 100%; + } .previous-result{ - max-width: 340px; + max-width: 360px; padding: 8px; - margin: 50px auto 30px; + margin: 30px auto 28px; + border-radius: 3px; } .none { - background-color: #888; + background-color: #aaa; color: #f5f5f5; } .correct { color: #f5f5f5; - background-color: #080; + background-color: #5cb85c; } .wrong { color: #f5f5f5; - background-color: #800; + background-color: #d9534f; } .previous-result-none { - max-width: 340px; + max-width: 360px; padding: 6px; margin: 30px auto; color: #f5f5f5; @@ -25,15 +42,16 @@ .big-character { font-size: 5em; } + .answer-container { + max-width: 360px; + margin: 0 auto; + display: flex; + justify-content: space-between; + } .answer-button { min-width: 90px; font-size: 2em; - @media (min-width: 768px) { - margin: 30px 15px 10px; - } - @media (max-width: 768px) { - margin: 30px 5px 10px; - } + margin: 30px 0 60px; } .no-hover { /* disables hover effect on touch screens */ diff --git a/src/components/Navbar/Navbar.jsx b/src/components/Navbar/Navbar.jsx index ac6936f..68e19b8 100644 --- a/src/components/Navbar/Navbar.jsx +++ b/src/components/Navbar/Navbar.jsx @@ -23,7 +23,6 @@ class Navbar extends Component { {leftLink} @@ -32,6 +31,8 @@ class Navbar extends Component { ) } } + // + //
{this.props.profile.hasOwnProperty('user_id')?this.props.profile.name+' is logged in':'not logged in'}
//