|
|
@ -23,6 +23,7 @@ using std::string; |
|
|
|
using namespace fmt; |
|
|
|
using namespace fmt; |
|
|
|
using namespace std::chrono_literals; |
|
|
|
using namespace std::chrono_literals; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main() { |
|
|
|
int main() { |
|
|
|
using namespace ftxui; |
|
|
|
using namespace ftxui; |
|
|
|
std::string reset_position; |
|
|
|
std::string reset_position; |
|
|
@ -33,17 +34,38 @@ int main() { |
|
|
|
game_map.generate(); |
|
|
|
game_map.generate(); |
|
|
|
Matrix &walls = game_map.walls(); |
|
|
|
Matrix &walls = game_map.walls(); |
|
|
|
Room &start = game_map.room(0); |
|
|
|
Room &start = game_map.room(0); |
|
|
|
|
|
|
|
Room &bad_room = game_map.room(1); |
|
|
|
|
|
|
|
Room &gold_room = game_map.room(game_map.room_count() - 1); |
|
|
|
|
|
|
|
|
|
|
|
Point me = {.x=start.x+1, .y=start.y+1}; |
|
|
|
Point me = {.x=start.x+1, .y=start.y+1}; |
|
|
|
|
|
|
|
Point enemy = {.x=bad_room.x+1, .y=bad_room.y+1}; |
|
|
|
|
|
|
|
Point goal = {.x=gold_room.x+1, .y=gold_room.y+1}; |
|
|
|
|
|
|
|
string dead_yet = "NOT DEAD"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool show_paths = false; |
|
|
|
|
|
|
|
|
|
|
|
auto map = Renderer([&] { |
|
|
|
auto map = Renderer([&] { |
|
|
|
|
|
|
|
game_map.set_target(me); |
|
|
|
|
|
|
|
game_map.make_paths(); |
|
|
|
|
|
|
|
Matrix &paths = game_map.paths(); |
|
|
|
|
|
|
|
|
|
|
|
for(size_t x = 0; x < walls[0].size(); ++x) { |
|
|
|
for(size_t x = 0; x < walls[0].size(); ++x) { |
|
|
|
for(size_t y = 0; y < walls.size(); ++y) { |
|
|
|
for(size_t y = 0; y < walls.size(); ++y) { |
|
|
|
const string tile = walls[y][x] == 1 ? "#" : "."; |
|
|
|
string tile = walls[y][x] == 1 ? "#" : format("{}", paths[y][x]); |
|
|
|
c.DrawText(x*2, y*4, tile, Color::GrayDark); |
|
|
|
if(tile == "#") { |
|
|
|
|
|
|
|
c.DrawText(x*2, y*4, tile, Color::GrayDark); |
|
|
|
|
|
|
|
} else if(show_paths) { |
|
|
|
|
|
|
|
int pnum = paths[y][x]; |
|
|
|
|
|
|
|
c.DrawText(x*2, y*4, tile, Color::Palette16(pnum % 7 + 1)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
c.DrawText(x*2, y*4, ".", Color::GrayDark); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c.DrawText(enemy.x*2, enemy.y*4, "!", Color::Red); |
|
|
|
c.DrawText(me.x*2, me.y*4, "@", Color::Blue); |
|
|
|
c.DrawText(me.x*2, me.y*4, "@", Color::Blue); |
|
|
|
|
|
|
|
c.DrawText(goal.x*2, goal.y*4, "$", Color::Yellow); |
|
|
|
|
|
|
|
|
|
|
|
return canvas(c); |
|
|
|
return canvas(c); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -53,7 +75,7 @@ int main() { |
|
|
|
hflow( |
|
|
|
hflow( |
|
|
|
vbox( |
|
|
|
vbox( |
|
|
|
gauge(0.5) | border, |
|
|
|
gauge(0.5) | border, |
|
|
|
text("STATUS") | border |
|
|
|
text(dead_yet) | border |
|
|
|
) | xflex_grow |
|
|
|
) | xflex_grow |
|
|
|
), |
|
|
|
), |
|
|
|
separator(), |
|
|
|
separator(), |
|
|
@ -78,9 +100,20 @@ int main() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(game_map.inmap(x,y) && !game_map.iswall(x,y)) { |
|
|
|
if(game_map.inmap(x,y) && !game_map.iswall(x,y)) { |
|
|
|
|
|
|
|
game_map.clear_target(me); |
|
|
|
me.x = x; |
|
|
|
me.x = x; |
|
|
|
me.y = y; |
|
|
|
me.y = y; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// move enemy here
|
|
|
|
|
|
|
|
bool found = game_map.neighbors(enemy, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(enemy.x == me.x && enemy.y == me.y) { |
|
|
|
|
|
|
|
dead_yet = "YOU DIED!"; |
|
|
|
|
|
|
|
} else if(goal.x == me.x && goal.y == me.y) { |
|
|
|
|
|
|
|
dead_yet = "YOU WIN!"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|