Game now keeps track of deaths, rounds, streaks and other fun stuff. You can also die finally.
This commit is contained in:
parent
a13704fe33
commit
9a012813ae
5 changed files with 100 additions and 68 deletions
|
@ -107,11 +107,20 @@ void Builder::run(const char *git_path, const char *build_cmd) {
|
|||
fileWatcher->watch();
|
||||
|
||||
if(listener->changes) {
|
||||
gui.output("############# START ############");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
gui.output(format("CHANGES! Running build {}", build_cmd));
|
||||
run_build(game, build_cmd);
|
||||
|
||||
if(game.is_dead()) {
|
||||
gui.output("!!!! YOU DIED! !!!! Learn to code luser.");
|
||||
game.reset();
|
||||
}
|
||||
|
||||
listener->reset_state();
|
||||
gui.output("^^^^^^^^^^^ END ^^^^^^^^^^^");
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
|
|
|
@ -10,6 +10,58 @@ const auto ERROR = fmt::emphasis::bold | fg(fmt::color::red);
|
|||
using namespace fmt;
|
||||
using namespace std;
|
||||
|
||||
GameEngine::GameEngine(int hp) : starting_hp(hp) {
|
||||
hit_points = starting_hp;
|
||||
};
|
||||
|
||||
int GameEngine::determine_damage(string &type) {
|
||||
try {
|
||||
return damage_types.at(type);
|
||||
} catch(std::out_of_range &err) {
|
||||
print(ERROR, "BAD DAMAGE TYPE {}\n", type);
|
||||
return 1000;
|
||||
}
|
||||
}
|
||||
|
||||
void GameEngine::start_round() {
|
||||
hits_taken = 0;
|
||||
}
|
||||
|
||||
void GameEngine::end_round() {
|
||||
++rounds;
|
||||
if(hits_taken == 0) {
|
||||
++streak;
|
||||
heal();
|
||||
}
|
||||
}
|
||||
|
||||
void GameEngine::reset() {
|
||||
rounds = 0;
|
||||
streak = 0;
|
||||
hit_points = starting_hp;
|
||||
hits_taken = 0;
|
||||
}
|
||||
|
||||
bool GameEngine::hit(string &type) {
|
||||
int damage = determine_damage(type);
|
||||
hit_points -= damage;
|
||||
++hits_taken;
|
||||
streak = 0;
|
||||
|
||||
return is_dead();
|
||||
}
|
||||
|
||||
void GameEngine::heal() {
|
||||
hit_points = hit_points * 1.10;
|
||||
if(hit_points > 100) hit_points = 100;
|
||||
}
|
||||
|
||||
bool GameEngine::is_dead() {
|
||||
return hit_points <= 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Brainfucker::Brainfucker() {
|
||||
}
|
||||
|
||||
|
@ -124,42 +176,3 @@ void Brainfucker::reset() {
|
|||
string Brainfucker::to_string() {
|
||||
return out.str();
|
||||
}
|
||||
|
||||
GameEngine::GameEngine(int hp) : hit_points(hp) {};
|
||||
|
||||
int GameEngine::determine_damage(string &type) {
|
||||
try {
|
||||
return damage_types.at(type);
|
||||
} catch(std::out_of_range &err) {
|
||||
print(ERROR, "BAD DAMAGE TYPE {}\n", type);
|
||||
return 1000;
|
||||
}
|
||||
}
|
||||
|
||||
void GameEngine::start_round() {
|
||||
hits_taken = 0;
|
||||
}
|
||||
|
||||
void GameEngine::end_round() {
|
||||
if(hits_taken == 0) {
|
||||
heal();
|
||||
}
|
||||
}
|
||||
|
||||
bool GameEngine::hit(string &type) {
|
||||
int damage = determine_damage(type);
|
||||
hit_points -= damage;
|
||||
++hits_taken;
|
||||
|
||||
// super dumb but I'll clean it up later
|
||||
return is_dead();
|
||||
}
|
||||
|
||||
void GameEngine::heal() {
|
||||
hit_points = hit_points * 1.10;
|
||||
if(hit_points > 100) hit_points = 100;
|
||||
}
|
||||
|
||||
bool GameEngine::is_dead() {
|
||||
return hit_points <= 0;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,38 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
|
||||
class GameEngine {
|
||||
map<string, int> damage_types{
|
||||
{"error", 4},
|
||||
{"warning", 1},
|
||||
{"note", 1},
|
||||
};
|
||||
|
||||
public:
|
||||
int starting_hp = 0;
|
||||
int hit_points = 0;
|
||||
int hits_taken = 0;
|
||||
int rounds = 0;
|
||||
int streak = 0;
|
||||
|
||||
GameEngine(int hp);
|
||||
|
||||
int determine_damage(string &type);
|
||||
|
||||
void start_round();
|
||||
|
||||
void end_round();
|
||||
|
||||
bool hit(string &type);
|
||||
|
||||
bool is_dead();
|
||||
|
||||
void heal();
|
||||
|
||||
void reset();
|
||||
};
|
||||
|
||||
class Brainfucker {
|
||||
|
||||
public:
|
||||
|
@ -26,29 +58,3 @@ class Brainfucker {
|
|||
void jump_forward();
|
||||
string to_string();
|
||||
};
|
||||
|
||||
class GameEngine {
|
||||
map<string, int> damage_types{
|
||||
{"error", 4},
|
||||
{"warning", 1},
|
||||
{"note", 1},
|
||||
};
|
||||
|
||||
public:
|
||||
int hit_points = 0;
|
||||
int hits_taken = 0;
|
||||
|
||||
GameEngine(int hp);
|
||||
|
||||
int determine_damage(string &type);
|
||||
|
||||
void start_round();
|
||||
|
||||
void end_round();
|
||||
|
||||
bool hit(string &type);
|
||||
|
||||
bool is_dead();
|
||||
|
||||
void heal();
|
||||
};
|
||||
|
|
6
gui.cpp
6
gui.cpp
|
@ -33,7 +33,7 @@ int GUI::main_loop(GameEngine &game, std::function<bool()> runner) {
|
|||
|
||||
auto status = Renderer([&] {
|
||||
return vbox({
|
||||
text(fmt::format("HP {}", game.hit_points)),
|
||||
text(fmt::format("HP {} | Hits Taken {} | Round {} | Streak {}", game.hit_points, game.hits_taken, game.rounds, game.streak)),
|
||||
separator(),
|
||||
hbox({
|
||||
text("HP "),
|
||||
|
@ -73,9 +73,9 @@ int GUI::main_loop(GameEngine &game, std::function<bool()> runner) {
|
|||
|
||||
auto component = Renderer(build_log, [&] {
|
||||
return vbox({
|
||||
game_stuff->Render() | flex,
|
||||
game_stuff->Render() | flex | size(HEIGHT, GREATER_THAN, 20),
|
||||
separator(),
|
||||
build_log->Render() | vscroll_indicator | yframe | flex,
|
||||
build_log->Render() | vscroll_indicator | yframe | yflex_grow,
|
||||
separator(),
|
||||
status->Render()
|
||||
}) | border;
|
||||
|
|
|
@ -61,11 +61,15 @@ TEST_CASE("", "[game_engine]") {
|
|||
game.end_round();
|
||||
|
||||
REQUIRE(game.hit_points < 100);
|
||||
REQUIRE(game.rounds == 1);
|
||||
REQUIRE(game.streak == 0);
|
||||
REQUIRE(game.is_dead() == false);
|
||||
|
||||
game.start_round();
|
||||
game.end_round();
|
||||
|
||||
REQUIRE(game.hit_points == 100);
|
||||
REQUIRE(game.rounds == 2);
|
||||
REQUIRE(game.streak == 1);
|
||||
REQUIRE(game.is_dead() == false);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue