diff --git a/src/Waterline.cpp b/src/Waterline.cpp index 1dfa44a..f0648af 100644 --- a/src/Waterline.cpp +++ b/src/Waterline.cpp @@ -5,25 +5,21 @@ #include #include -Waterline::Waterline() { - std::vector baseShape = { +Waterline::Waterline() : x(0), y(5) { + shape = { "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", "^^^^ ^^^ ^^^ ^^^ ^^^^ ", "^^^^ ^^^^ ^^^ ^^ ", "^^ ^^^^ ^^^ ^^^^^^ "}; - int seg_len = baseShape[0].size(); - int repeat = Aquarium::getInstance().getWidth() / seg_len + 1; - - for (auto &line : baseShape) { - std::string original = line; - while (line.size() < Aquarium::getInstance().getWidth()) { + const size_t width = Aquarium::getInstance().getWidth(); + for (auto &line : shape) { + const std::string original = line; + while (line.size() < width) { line += original; } } - shape = std::move(baseShape); - y = 5; } -void Waterline::draw() { +void Waterline::draw() const { for (size_t i = 0; i < shape.size(); ++i) { Aquarium::getInstance().drawToBackBuffer(i + y, x, 0, shape[i], std::string(shape[i].size(), 'c')); @@ -42,9 +38,6 @@ void Waterline::update() { } void Waterline::shiftString(std::string &str, int direction) { - if (str.empty() || (direction != 1 && direction != -1)) - return; - if (direction == 1) { std::rotate(str.rbegin(), str.rbegin() + 1, str.rend()); } else { diff --git a/src/Waterline.h b/src/Waterline.h index 997651f..c05d9c5 100644 --- a/src/Waterline.h +++ b/src/Waterline.h @@ -1,13 +1,14 @@ #pragma once #include "Entity.h" -class Waterline : public Entity { +class Waterline { private: + size_t x, y; std::vector shape; void shiftString(std::string &, int direction); public: Waterline(); - void draw(); + void draw() const; void update(); };