Adds Scoreboard.

This commit is contained in:
falsycat 2021-08-26 16:16:26 +09:00
parent bc56befc8e
commit 5d667f2894
7 changed files with 49 additions and 8 deletions

View File

@ -182,6 +182,7 @@
<ClInclude Include="src\iAllocator.h" /> <ClInclude Include="src\iAllocator.h" />
<ClInclude Include="src\LinearAllocator.h" /> <ClInclude Include="src\LinearAllocator.h" />
<ClInclude Include="src\Frame.h" /> <ClInclude Include="src\Frame.h" />
<ClInclude Include="src\Scoreboard.h" />
<ClInclude Include="src\StackAllocator.h" /> <ClInclude Include="src\StackAllocator.h" />
<ClInclude Include="src\SystemClock.h" /> <ClInclude Include="src\SystemClock.h" />
<ClInclude Include="src\Text.h" /> <ClInclude Include="src\Text.h" />

View File

@ -170,6 +170,9 @@
<ClInclude Include="src\InputWindowElementFactory.h"> <ClInclude Include="src\InputWindowElementFactory.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\Scoreboard.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Library Include="thirdparty\lua5.1.lib" /> <Library Include="thirdparty\lua5.1.lib" />

View File

@ -6,6 +6,7 @@
#include "iElement.h" #include "iElement.h"
#include "iElementDriver.h" #include "iElementDriver.h"
#include "iInputMatcher.h" #include "iInputMatcher.h"
#include "Scoreboard.h"
#include "Text.h" #include "Text.h"
namespace gj { namespace gj {
@ -17,6 +18,8 @@ class InputWindowElement : public iElement {
UniqPtr<iInputMatcher> matcher; UniqPtr<iInputMatcher> matcher;
UniqPtr<iElementDriver> driver; UniqPtr<iElementDriver> driver;
Scoreboard* scoreboard;
Period period; Period period;
std::wstring text; std::wstring text;
@ -31,7 +34,7 @@ class InputWindowElement : public iElement {
InputWindowElement(Param&& p) : InputWindowElement(Param&& p) :
iElement(p.period), 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)) { text_(p.text), guide_(matcher_->expects()), width_(CountWstrBytes(p.text)) {
param_["posX"] = 0.; param_["posX"] = 0.;
param_["posY"] = 0.; param_["posY"] = 0.;
@ -43,7 +46,11 @@ class InputWindowElement : public iElement {
if (matcher_->done()) break; if (matcher_->done()) break;
if (matcher_->Input(c)) { if (matcher_->Input(c)) {
guide_ = Text(matcher_->expects()); guide_ = Text(matcher_->expects());
++sb_->correct;
} else {
++sb_->miss;
} }
++sb_->input;
} }
drv_->Update(param_, t); drv_->Update(param_, t);
@ -62,13 +69,18 @@ class InputWindowElement : public iElement {
} }
void Finalize() override { void Finalize() override {
/* TODO score calculation */ ++sb_->lines;
if (matcher_->done()) {
++sb_->completeLines;
}
} }
private: private:
UniqPtr<iInputMatcher> matcher_; UniqPtr<iInputMatcher> matcher_;
UniqPtr<iElementDriver> drv_; UniqPtr<iElementDriver> drv_;
Scoreboard* sb_;
Text text_; Text text_;
Text guide_; Text guide_;

View File

@ -19,7 +19,7 @@ class InputWindowElementFactory : public iElementFactory {
InputWindowElementFactory& operator=(InputWindowElementFactory&&) = delete; InputWindowElementFactory& operator=(InputWindowElementFactory&&) = delete;
InputWindowElementFactory& operator=(const InputWindowElementFactory&) = delete; InputWindowElementFactory& operator=(const InputWindowElementFactory&) = delete;
InputWindowElementFactory(iAllocator* alloc) : alloc_(alloc) { InputWindowElementFactory(iAllocator* alloc, Scoreboard* sb) : alloc_(alloc), sb_(sb) {
} }
UniqPtr<iElement> Create(Param&& param) override { UniqPtr<iElement> Create(Param&& param) override {
@ -30,6 +30,7 @@ class InputWindowElementFactory : public iElementFactory {
InputWindowElement::Param p; InputWindowElement::Param p;
p.period = param.period; p.period = param.period;
p.scoreboard = sb_;
p.driver = std::move(param.driver); p.driver = std::move(param.driver);
p.matcher = alloc_->MakeUniq<iInputMatcher, HiraganaMatcher>(ConvertStrToWstr(kana)); p.matcher = alloc_->MakeUniq<iInputMatcher, HiraganaMatcher>(ConvertStrToWstr(kana));
p.text = ConvertStrToWstr(text); p.text = ConvertStrToWstr(text);
@ -39,6 +40,7 @@ class InputWindowElementFactory : public iElementFactory {
private: private:
iAllocator* alloc_; iAllocator* alloc_;
Scoreboard* sb_;
}; };

View File

@ -7,8 +7,9 @@
gj::PlayScene::PlayScene(Param&& p) : gj::PlayScene::PlayScene(Param&& p) :
alloc_(p.alloc), logger_(p.logger), w_(p.w), h_(p.h), alloc_(p.alloc), logger_(p.logger), w_(p.w), h_(p.h),
clock_(p.clock), store_(&clock_, 256) { clock_(p.clock), store_(&clock_, 256) {
GlyphElementFactory glyph(alloc_); GlyphElementFactory glyph(alloc_);
InputWindowElementFactory inputWin(alloc_); InputWindowElementFactory inputWin(alloc_, &sb_);
Lua::FactoryMap map; Lua::FactoryMap map;
map["Glyph"] = &glyph; map["Glyph"] = &glyph;

View File

@ -8,6 +8,7 @@
#include "iScene.h" #include "iScene.h"
#include "Lua.h" #include "Lua.h"
#include "OffsetClock.h" #include "OffsetClock.h"
#include "Scoreboard.h"
namespace gj { namespace gj {
@ -50,6 +51,7 @@ class PlayScene : public iScene {
OffsetClock clock_; OffsetClock clock_;
Scoreboard sb_;
ElementStore store_; ElementStore store_;
UniqPtr<Lua> lua_; UniqPtr<Lua> lua_;
}; };

20
src/Scoreboard.h Normal file
View File

@ -0,0 +1,20 @@
#pragma once
#include <cstdint>
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;
};
}