Compare commits
No commits in common. '89598f3cc88a9947c339cc439683b7df8922aba8' and 'cc27b166e1f677752039e1cfc3f0ec359df3ea09' have entirely different histories.
89598f3cc8
...
cc27b166e1
20 changed files with 20 additions and 266 deletions
@ -1,28 +0,0 @@ |
|||||||
#include "Coin.h" |
|
||||||
#include "Game.h" |
|
||||||
|
|
||||||
void Coin::draw(QPainter &painter) const { |
|
||||||
painter.save(); |
|
||||||
|
|
||||||
painter.translate(pos); |
|
||||||
painter.setBrush(QBrush(Qt::yellow, Qt::SolidPattern)); |
|
||||||
painter.drawEllipse(QPoint(), radius, radius); |
|
||||||
|
|
||||||
painter.drawText(QRect(-radius, -radius, radius * 2, radius * 2), Qt::AlignCenter, QString::fromStdString(std::to_string(value))); |
|
||||||
|
|
||||||
painter.restore(); |
|
||||||
} |
|
||||||
|
|
||||||
bool Coin::isLost() const { |
|
||||||
return pos.x() < -100; |
|
||||||
} |
|
||||||
|
|
||||||
Coin::Coin() { |
|
||||||
int y = int(Game::Random(SPEC_Y, GROUND_Y)); |
|
||||||
pos = {WIDTH, y}; |
|
||||||
value = int(Game::Random(30, 37)); |
|
||||||
} |
|
||||||
|
|
||||||
void Coin::update(float dTime) { |
|
||||||
pos.setX(float(pos.x()) - velocity * dTime); |
|
||||||
} |
|
@ -1,16 +0,0 @@ |
|||||||
#pragma once |
|
||||||
|
|
||||||
#include <QPainter> |
|
||||||
|
|
||||||
class Coin { |
|
||||||
public: |
|
||||||
explicit Coin(); |
|
||||||
bool collected = false; |
|
||||||
QPoint pos; |
|
||||||
float velocity = 150; |
|
||||||
int value; |
|
||||||
int radius = 15; |
|
||||||
bool isLost() const; |
|
||||||
void draw(QPainter &painter) const; |
|
||||||
void update(float dTime); |
|
||||||
}; |
|
@ -1,23 +0,0 @@ |
|||||||
#include "Logger.h" |
|
||||||
#include "FileManager.h" |
|
||||||
|
|
||||||
#define MAX_STRING 100 |
|
||||||
constexpr int eventStringMax = 6; |
|
||||||
|
|
||||||
void Logger::OnCoinCollected(CoinCollectEvent *event) { |
|
||||||
char buffer[MAX_STRING]; |
|
||||||
sprintf(buffer, "Game event: %*s | time: %6.2f | value: %d\n", eventStringMax, "Coin", event->time, event->value); |
|
||||||
FileManager::instance->writeFile("log.txt", buffer, true); |
|
||||||
} |
|
||||||
|
|
||||||
void Logger::OnWallJumped(WallJumpEvent *event) { |
|
||||||
char buffer[MAX_STRING]; |
|
||||||
sprintf(buffer, "Game event: %*s | time: %6.2f | wall_height: %6.2f\n", eventStringMax, "Jump", event->time, event->wallHeight); |
|
||||||
FileManager::instance->writeFile("log.txt", buffer, true); |
|
||||||
} |
|
||||||
|
|
||||||
void Logger::OnWallCrashed(WallCrashEvent *event) { |
|
||||||
char buffer[MAX_STRING]; |
|
||||||
sprintf(buffer, "Game event: %*s | time: %6.2f | wall_height: %6.2f\n", eventStringMax, "Crash", event->time, event->wallHeight); |
|
||||||
FileManager::instance->writeFile("log.txt", buffer, true); |
|
||||||
} |
|
@ -1,10 +0,0 @@ |
|||||||
#pragma once |
|
||||||
|
|
||||||
#include "Listener.h" |
|
||||||
|
|
||||||
class Logger : public GameListener{ |
|
||||||
protected: |
|
||||||
void OnCoinCollected(CoinCollectEvent * event) override; |
|
||||||
void OnWallJumped(WallJumpEvent * event) override; |
|
||||||
void OnWallCrashed(WallCrashEvent * event) override; |
|
||||||
}; |
|
@ -1,26 +0,0 @@ |
|||||||
#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)); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
@ -1,11 +0,0 @@ |
|||||||
#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