diff --git a/LESSONS.md b/LESSONS.md index dcb63a4..2018468 100644 --- a/LESSONS.md +++ b/LESSONS.md @@ -44,4 +44,26 @@ Every little snake needs to eat. And no snake will appear without food, which is Once you're ready, you can _git merge lesson03_. +--- + +## Lesson 03 + +#### Prequisites +- Loops + +#### Files +- _components/Point.cpp_ +- _components/Point.h_ +- _main.cpp_ + +#### Task + +This Task will be a little on the short side. We plan to implement our Snake as a collection of points on the screen and for that, each point should be able to move by itself. This is the objective of this lesson. + +1) Some new functions have appeared in _components/Point.*_ which you should inspect and try to implement. +2) Go to _main.cpp_ and see the new __mainL03__ which will use the movement functions now implemented to make one point move across the screen diagonally. Try it out! +3) As you can see, we use a for-loop for this but C++ has some other types of loop which you should familiarize yourself with. Try and play around with the commented-out loops and get the same result by using while and do-while loops. + +Once you're ready, you can _git merge lesson04_. + --- \ No newline at end of file diff --git a/components/Point.cpp b/components/Point.cpp index 254d3cb..61e5072 100755 --- a/components/Point.cpp +++ b/components/Point.cpp @@ -22,6 +22,22 @@ uint32_t Point::getY() const { // TODO: implement this getter } +void Point::moveUp() { + // TODO: implement me +} + +void Point::moveDown() { + // TODO: implement me +} + +void Point::moveLeft() { + // TODO: implement me +} + +void Point::moveRight() { + // TODO: implement me +} + int Point::getImg() const { return img_; } diff --git a/components/Point.h b/components/Point.h index 5ee0976..63e1d0e 100755 --- a/components/Point.h +++ b/components/Point.h @@ -16,6 +16,11 @@ public: uint32_t getX() const; uint32_t getY() const; + void moveUp(); + void moveDown(); + void moveLeft(); + void moveRight(); + int getImg() const; void setImg(int image); diff --git a/main.cpp b/main.cpp index 8cb828a..9ace381 100755 --- a/main.cpp +++ b/main.cpp @@ -32,7 +32,36 @@ void mainL02() { std::cout << "Helper QUIT" << std::endl; } +void mainL03() { + Graphics::get().init("Learners Helper 02"); + + Point p(10,10); + + for (uint32_t i = 0; i < 100; i++) { + p.moveDown(); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + p.moveRight(); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + + /* + while(...) { + // TODO: play with this + } + */ + + /* + do { + // TODO: play with this + } while (...) + */ + + Graphics::get().finalize(); + + std::cout << "Helper QUIT" << std::endl; +} + int main() { - mainL02(); + mainL03(); return 0; } \ No newline at end of file