Adds Scoreboard.
This commit is contained in:
		| @@ -182,6 +182,7 @@ | ||||
|     <ClInclude Include="src\iAllocator.h" /> | ||||
|     <ClInclude Include="src\LinearAllocator.h" /> | ||||
|     <ClInclude Include="src\Frame.h" /> | ||||
|     <ClInclude Include="src\Scoreboard.h" /> | ||||
|     <ClInclude Include="src\StackAllocator.h" /> | ||||
|     <ClInclude Include="src\SystemClock.h" /> | ||||
|     <ClInclude Include="src\Text.h" /> | ||||
|   | ||||
| @@ -170,6 +170,9 @@ | ||||
|     <ClInclude Include="src\InputWindowElementFactory.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="src\Scoreboard.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <Library Include="thirdparty\lua5.1.lib" /> | ||||
|   | ||||
| @@ -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<iInputMatcher>  matcher; | ||||
|     UniqPtr<iElementDriver> 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<iInputMatcher>  matcher_; | ||||
|   UniqPtr<iElementDriver> drv_; | ||||
|  | ||||
|   Scoreboard* sb_; | ||||
|  | ||||
|   Text text_; | ||||
|   Text guide_; | ||||
|  | ||||
|   | ||||
| @@ -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<iElement> Create(Param&& param) override { | ||||
| @@ -29,16 +29,18 @@ class InputWindowElementFactory : public iElementFactory { | ||||
|     const std::string kana = std::get<std::string>(param.custom[1]); | ||||
|  | ||||
|     InputWindowElement::Param p; | ||||
|     p.period  = param.period; | ||||
|     p.driver  = std::move(param.driver); | ||||
|     p.matcher = alloc_->MakeUniq<iInputMatcher, HiraganaMatcher>(ConvertStrToWstr(kana)); | ||||
|     p.text    = ConvertStrToWstr(text); | ||||
|     p.period     = param.period; | ||||
|     p.scoreboard = sb_; | ||||
|     p.driver     = std::move(param.driver); | ||||
|     p.matcher    = alloc_->MakeUniq<iInputMatcher, HiraganaMatcher>(ConvertStrToWstr(kana)); | ||||
|     p.text       = ConvertStrToWstr(text); | ||||
|  | ||||
|     return alloc_->MakeUniq<iElement, InputWindowElement>(std::move(p)); | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   iAllocator* alloc_; | ||||
|   Scoreboard* sb_; | ||||
| }; | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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> lua_; | ||||
| }; | ||||
|   | ||||
							
								
								
									
										20
									
								
								src/Scoreboard.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								src/Scoreboard.h
									
									
									
									
									
										Normal 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; | ||||
| }; | ||||
|  | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user