diff options
author | sanine-a <sanine.not@pm.me> | 2021-04-13 15:22:37 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2021-04-13 15:22:37 -0500 |
commit | cd797721f07e3368f56d2f293d49e1ad37029cbb (patch) | |
tree | 68d02dfd54113bcabdfdeabd651f60083a38d242 | |
parent | 8f9cefc98e25d9e0f931dfe6dc2acced818700ee (diff) |
add score display
-rw-r--r-- | App.js | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -34,6 +34,8 @@ let state = { pinyin: 'ni3', guessHistory: [], + numGuesses: 0, + correctGuesses: 0, hintLevel: 0, @@ -56,8 +58,10 @@ function setState(update) const App = function() { const { + levelCharacters, level, gameMode, character, pinyin, + numGuesses, correctGuesses, hintLevel, inputValue, inputShaking } = state; @@ -65,6 +69,14 @@ const App = function() return h( 'div', {}, [ + h(ScoreView, + { level: level, + numCharacters: levelCharacters.length, + guesses: numGuesses, + correctGuesses, + time: 0, + }), + h('h1', {}, character), h(InputBox, @@ -218,6 +230,8 @@ function reset() { pinyin, guessHistory: [], + numGuesses: 0, + correctGuesses: 0, hintLevel: 0, @@ -225,3 +239,26 @@ function reset() { inputShaking: false, }); } + + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +function ScoreView({ level, numCharacters, guesses, correctGuesses, time }) +{ + const minutes = Math.floor(time/60); + const seconds = time % 60; + + + const levelName = `Level ${level + 1}`; + const percentage = + guesses === 0 ? '100.0' : String(0.1 * Math.floor(1000 * correctGuesses / guesses)); + const score = `${correctGuesses}/${numCharacters} (${percentage}%)`; + + return h( + 'div', {}, + [ + h('h1', {}, levelName), + h('h1', {}, score), + ] + ); +} |