From 5d667f2894b94e299881aa70ab8a6451dc27baa6 Mon Sep 17 00:00:00 2001 From: falsycat Date: Thu, 26 Aug 2021 16:16:26 +0900 Subject: [PATCH] Adds Scoreboard. --- GlyphsJuke.vcxproj | 1 + GlyphsJuke.vcxproj.filters | 3 +++ src/InputWindowElement.h | 16 ++++++++++++++-- src/InputWindowElementFactory.h | 12 +++++++----- src/PlayScene.cc | 3 ++- src/PlayScene.h | 2 ++ src/Scoreboard.h | 20 ++++++++++++++++++++ 7 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 src/Scoreboard.h diff --git a/GlyphsJuke.vcxproj b/GlyphsJuke.vcxproj index 62b1492..80bb1e2 100644 --- a/GlyphsJuke.vcxproj +++ b/GlyphsJuke.vcxproj @@ -182,6 +182,7 @@ + diff --git a/GlyphsJuke.vcxproj.filters b/GlyphsJuke.vcxproj.filters index faa7d5c..d9e576d 100644 --- a/GlyphsJuke.vcxproj.filters +++ b/GlyphsJuke.vcxproj.filters @@ -170,6 +170,9 @@ Header Files + + Header Files + diff --git a/src/InputWindowElement.h b/src/InputWindowElement.h index 792a3ec..45a5524 100644 --- a/src/InputWindowElement.h +++ b/src/InputWindowElement.h @@ -6,6 +6,7 @@ #include "iElement.h" #include "iElementDriver.h" #include "iInputMatcher.h" +#include "Scoreboard.h" #include "Text.h" namespace gj { @@ -17,6 +18,8 @@ class InputWindowElement : public iElement { UniqPtr matcher; UniqPtr driver; + Scoreboard* scoreboard; + Period period; std::wstring text; @@ -31,7 +34,7 @@ class InputWindowElement : public iElement { InputWindowElement(Param&& p) : iElement(p.period), - matcher_(std::move(p.matcher)), drv_(std::move(p.driver)), + matcher_(std::move(p.matcher)), drv_(std::move(p.driver)), sb_(p.scoreboard), text_(p.text), guide_(matcher_->expects()), width_(CountWstrBytes(p.text)) { param_["posX"] = 0.; param_["posY"] = 0.; @@ -43,7 +46,11 @@ class InputWindowElement : public iElement { if (matcher_->done()) break; if (matcher_->Input(c)) { guide_ = Text(matcher_->expects()); + ++sb_->correct; + } else { + ++sb_->miss; } + ++sb_->input; } drv_->Update(param_, t); @@ -62,13 +69,18 @@ class InputWindowElement : public iElement { } void Finalize() override { - /* TODO score calculation */ + ++sb_->lines; + if (matcher_->done()) { + ++sb_->completeLines; + } } private: UniqPtr matcher_; UniqPtr drv_; + Scoreboard* sb_; + Text text_; Text guide_; diff --git a/src/InputWindowElementFactory.h b/src/InputWindowElementFactory.h index 7f84aa5..93ab970 100644 --- a/src/InputWindowElementFactory.h +++ b/src/InputWindowElementFactory.h @@ -19,7 +19,7 @@ class InputWindowElementFactory : public iElementFactory { InputWindowElementFactory& operator=(InputWindowElementFactory&&) = delete; InputWindowElementFactory& operator=(const InputWindowElementFactory&) = delete; - InputWindowElementFactory(iAllocator* alloc) : alloc_(alloc) { + InputWindowElementFactory(iAllocator* alloc, Scoreboard* sb) : alloc_(alloc), sb_(sb) { } UniqPtr Create(Param&& param) override { @@ -29,16 +29,18 @@ class InputWindowElementFactory : public iElementFactory { const std::string kana = std::get(param.custom[1]); InputWindowElement::Param p; - p.period = param.period; - p.driver = std::move(param.driver); - p.matcher = alloc_->MakeUniq(ConvertStrToWstr(kana)); - p.text = ConvertStrToWstr(text); + p.period = param.period; + p.scoreboard = sb_; + p.driver = std::move(param.driver); + p.matcher = alloc_->MakeUniq(ConvertStrToWstr(kana)); + p.text = ConvertStrToWstr(text); return alloc_->MakeUniq(std::move(p)); } private: iAllocator* alloc_; + Scoreboard* sb_; }; diff --git a/src/PlayScene.cc b/src/PlayScene.cc index e75c898..326c0ca 100644 --- a/src/PlayScene.cc +++ b/src/PlayScene.cc @@ -7,8 +7,9 @@ gj::PlayScene::PlayScene(Param&& p) : alloc_(p.alloc), logger_(p.logger), w_(p.w), h_(p.h), clock_(p.clock), store_(&clock_, 256) { + GlyphElementFactory glyph(alloc_); - InputWindowElementFactory inputWin(alloc_); + InputWindowElementFactory inputWin(alloc_, &sb_); Lua::FactoryMap map; map["Glyph"] = &glyph; diff --git a/src/PlayScene.h b/src/PlayScene.h index 8903bae..ad5815c 100644 --- a/src/PlayScene.h +++ b/src/PlayScene.h @@ -8,6 +8,7 @@ #include "iScene.h" #include "Lua.h" #include "OffsetClock.h" +#include "Scoreboard.h" namespace gj { @@ -50,6 +51,7 @@ class PlayScene : public iScene { OffsetClock clock_; + Scoreboard sb_; ElementStore store_; UniqPtr lua_; }; diff --git a/src/Scoreboard.h b/src/Scoreboard.h new file mode 100644 index 0000000..a99a355 --- /dev/null +++ b/src/Scoreboard.h @@ -0,0 +1,20 @@ +#pragma once + +#include + + +namespace gj { + + +struct Scoreboard { + public: + size_t input = 0; + size_t correct = 0; + size_t miss = 0; + + size_t lines = 0; + size_t completeLines = 0; +}; + + +} \ No newline at end of file