parent
75af403e27
commit
89598f3cc8
2 changed files with 37 additions and 0 deletions
@ -0,0 +1,26 @@ |
||||
#include "RecordTracker.h" |
||||
#include "FileManager.h" |
||||
|
||||
void RecordTracker::OnWallJumped(WallJumpEvent *event) { |
||||
jumped++; |
||||
} |
||||
|
||||
void RecordTracker::OnWallCrashed(WallCrashEvent *event) { |
||||
checkJumpRecord(); |
||||
jumped = 0; |
||||
} |
||||
|
||||
void RecordTracker::checkJumpRecord() const { |
||||
const uint64_t newRecord = jumped; |
||||
FileManager::instance->readFile("record_jump.txt", [newRecord](const std::string& content){ |
||||
if (content.empty()){ |
||||
FileManager::instance->writeFile("record_jump.txt", std::to_string(newRecord)); |
||||
return; |
||||
} |
||||
uint64_t oldRecord = std::stoull(content); |
||||
if (newRecord > oldRecord){ |
||||
std::cout << "New jump record!" << std::endl; |
||||
FileManager::instance->writeFile("record_jump.txt", std::to_string(newRecord)); |
||||
} |
||||
}); |
||||
} |
@ -0,0 +1,11 @@ |
||||
#pragma once |
||||
|
||||
#include "Listener.h" |
||||
|
||||
class RecordTracker : public GameListener { |
||||
uint64_t jumped = 0; |
||||
void checkJumpRecord() const; |
||||
protected: |
||||
void OnWallJumped(WallJumpEvent * event) override; |
||||
void OnWallCrashed(WallCrashEvent * event) override; |
||||
}; |
Loading…
Reference in new issue