From 67e3a57f9b90b9c7a1d13d2ec62dc231ba3cd966 Mon Sep 17 00:00:00 2001 From: amakuchi Date: Fri, 26 Jun 2020 20:55:03 +0900 Subject: [PATCH] count score --- web/src/components/Scene.js | 18 ++++++++++++++++-- web/src/components/Typing.js | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/web/src/components/Scene.js b/web/src/components/Scene.js index 3e333a9..a868832 100644 --- a/web/src/components/Scene.js +++ b/web/src/components/Scene.js @@ -8,9 +8,11 @@ export class Scene extends React.Component { pressKey: null, keystroke: 0, scene: 0, + score: 0, }; this.handleKeyPress = this.handleKeyPress.bind(this); this.next = this.next.bind(this); + this.addScore = this.addScore.bind(this); } handleKeyPress(e) { @@ -20,6 +22,12 @@ export class Scene extends React.Component { }); } + addScore(point) { + this.setState((state) => ({ + score: state.score + point, + })); + } + next() { this.setState((state) => ({ scene: state.scene + 1, @@ -42,11 +50,12 @@ export class Scene extends React.Component { ); default: - return ; + return ; } } } @@ -64,5 +73,10 @@ class Start extends React.Component { } function End(props) { - return
{'End'}
; + return ( +
+
{props.score}
+ {'End'} +
+ ); } diff --git a/web/src/components/Typing.js b/web/src/components/Typing.js index b8e6f5e..e6adfa1 100644 --- a/web/src/components/Typing.js +++ b/web/src/components/Typing.js @@ -61,6 +61,7 @@ export class Typing extends React.Component { const new_pos = this.state.pos + 1; if (new_pos === this.state.words[0].length) { this.nextWord(); + this.props.addScore(new_pos); } else { this.setState({ uncorrect: '',