You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.3 KiB
88 lines
2.3 KiB
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
|
// Use of this source code is governed by the MIT license that can be found in
|
|
// the LICENSE file.
|
|
#include <chrono> // for operator""s, chrono_literals
|
|
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
|
#include <iostream> // for cout, ostream
|
|
#include <memory> // for allocator, shared_ptr
|
|
#include <string> // for string, operator<<
|
|
#include <thread> // for sleep_for
|
|
|
|
#include <ftxui/dom/elements.hpp> // for hflow, paragraph, separator, hbox, vbox, filler, operator|, border, Element
|
|
#include <ftxui/dom/node.hpp> // for Render
|
|
#include <ftxui/screen/box.hpp> // for ftxui
|
|
#include <ftxui/component/component.hpp>
|
|
#include <fmt/core.h>
|
|
#include "map.hpp"
|
|
#include "dbc.hpp"
|
|
|
|
using std::string;
|
|
using namespace std::chrono_literals;
|
|
|
|
Matrix input = {
|
|
{1,1,1,1,1,1,1,1,1,1,1,1},
|
|
{1,1,1,1,1,1,1,1,1,1,1,1},
|
|
{1,1,1,0,1,1,1,1,1,1,1,1},
|
|
{1,1,1,1,1,1,1,1,1,1,1,1},
|
|
{1,1,1,1,1,1,1,1,1,1,1,1},
|
|
};
|
|
|
|
Matrix walls = {
|
|
{1,1,1,1,1,1,1,1,1,1,1,1},
|
|
{1,0,0,0,0,1,1,0,0,0,0,1},
|
|
{1,0,0,0,0,0,0,0,0,1,0,1},
|
|
{1,0,0,0,0,1,1,0,0,1,0,1},
|
|
{1,1,1,1,1,1,1,1,1,1,1,1},
|
|
};
|
|
|
|
int main() {
|
|
using namespace ftxui;
|
|
std::string reset_position;
|
|
|
|
auto c = Canvas(150, 100);
|
|
|
|
Map game_map = Map(input, walls, 1000);
|
|
|
|
auto map = Renderer([&] {
|
|
game_map.make_paths();
|
|
Matrix &result = game_map.paths();
|
|
|
|
for(size_t x = 0; x < result[0].size(); ++x) {
|
|
for(size_t y = 0; y < result.size(); ++y) {
|
|
auto val = result[y][x];
|
|
const string tile = val == 1000 ? "#" : fmt::format("{}", result[y][x]);
|
|
|
|
|
|
c.DrawText(x*2, y*4, tile);
|
|
}
|
|
}
|
|
|
|
c.DrawText(4*2, 3*4, "@", Color::Blue);
|
|
|
|
return canvas(c) | border;
|
|
});
|
|
|
|
while (true) {
|
|
auto document = hbox({
|
|
hflow(
|
|
vbox(
|
|
gauge(0.5) | border,
|
|
text("STATUS") | border
|
|
) | xflex_grow
|
|
),
|
|
separator(),
|
|
hbox(map->Render()),
|
|
}) | border;
|
|
|
|
auto screen = Screen::Create(Dimension::Full());
|
|
Render(screen, document);
|
|
|
|
std::cout << reset_position;
|
|
screen.Print();
|
|
reset_position = screen.ResetPosition();
|
|
|
|
std::this_thread::sleep_for(0.01s);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|