25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

46 lines
968 B

  1. #include "world.h"
  2. World::World()
  3. : m_height(WORLD_HEIGHT), m_width(WORLD_WIDTH),
  4. m_c(WORLD_HEIGHT, std::vector<char>(WORLD_WIDTH, DEFAULT_CHAR)) {
  5. init();
  6. }
  7. void World::init() {}
  8. Object &World::createObject(Object &&o) {
  9. m_objects.push_front(o);
  10. return m_objects.front();
  11. }
  12. void World::draw(Object &o) {
  13. double x = o.getPosition().X, y = o.getPosition().Y;
  14. int sz = o.getSize();
  15. char c = o.getSymbol();
  16. for (int i = -(sz + 1) / 2 + 1; i <= sz / 2; ++i)
  17. for (int j = -(sz + 1) / 2 + 1; j <= sz / 2; ++j)
  18. m_c[y + i][x + j] = c;
  19. }
  20. void World::update() {
  21. for (auto &i : m_c)
  22. for (auto &j : i)
  23. j = DEFAULT_CHAR;
  24. for (auto &it : m_objects) {
  25. draw(it);
  26. }
  27. }
  28. void World::print(std::ostream &out) {
  29. for (const auto &i : m_c) {
  30. for (const auto &j : i)
  31. out << j;
  32. out << '\n';
  33. }
  34. }
  35. void World::destroy() {}
  36. World::~World() { destroy(); }