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.

183 lines
7.6 KiB

  1. ## Lesson 01
  2. #### Prequisites
  3. - Classes
  4. - Functions
  5. #### Files
  6. - _components/Point.cpp_
  7. - _components/Point.h_
  8. - _main.cpp_
  9. #### Task
  10. 1) With the point-class we represent a single dot on screen, giving it a position and character as "image". Begin by inspecting _components/Point.h_ and _components/Point.cpp_ and figure out what a header (.h) and code (.cpp) file contain and how they differ.
  11. 2) When an instance of a class in C++ is created, its constructor is used to initialize values. At some point, the created instance will get destroyed which uses the destructor. Read about these two and implement them in _components/Point.cpp_.
  12. 3) Select to call __mainL01__ in __main__ of _main.cpp_ and think or read about the purpose of this function as the applications entry point.
  13. 4) See what happens when you run the application now and play around with the point or maybe create multiple. You can also modify the destructor to do something special (like print to the command line).
  14. 5) Go to _components/Point.*_ again and look at the member variables x,y and img. Notice that they are defined in a "private" region. Try to modify these directly in the main function __mainL01__. If that does not work, you can implement the getters and setters marked with TODO in _components/Point.cpp_
  15. 6) Continue exploring around with the point and see what happens.
  16. Once you're ready, you can _git merge lesson02_.
  17. ---
  18. ## Lesson 02
  19. #### Prequisites
  20. - Random Numbers
  21. - Functions
  22. - Pointers/References
  23. #### Files
  24. - _components/Snack.cpp_
  25. - _components/Snack.h_
  26. - _main.cpp_
  27. #### Task
  28. Every little snake needs to eat. And no snake will appear without food, which is why we begin by providing this essential item.
  29. 1) We want to implement the _Snack_ as an instance of the Point-Class from the previous Task. Therefore we will write a function that turns an ordinary Point into a delicious Snack. This will be called _generateSnack_ and we will implement it in _components/Snack.*_ where you can see the skeleton for the function.
  30. 2) A Snack must be placed at a random point when generating, so set its x and y value to a random value that fits on the playing field (see the comment in the function skeleton for a hint).
  31. 3) A Snack must also look enticing, so set its image to the one defined as SNACK_CHAR and then display the delicious snack.
  32. 4) Experiment and use __mainL02__ to test if your code works.
  33. 5) Notice anything interesting with how we pass the Point to the generateSnack-function? The function requests a pointer which is the address of an object instance. To get the address of an existing object, we use operator&. Read up on pointers and references.
  34. Once you're ready, you can _git merge lesson03_.
  35. ---
  36. ## Lesson 03
  37. #### Prequisites
  38. - Loops
  39. #### Files
  40. - _components/Point.cpp_
  41. - _components/Point.h_
  42. - _main.cpp_
  43. #### Task
  44. 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.
  45. 1) Some new functions have appeared in _components/Point.*_ which you should inspect and try to implement.
  46. 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!
  47. 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.
  48. Once you're ready, you can _git merge lesson04_.
  49. ---
  50. ## Lesson 04
  51. #### Prequisites
  52. - Arrays
  53. - Switch-Statement
  54. #### Files
  55. - _components/Snake.cpp_
  56. - _components/Snake.h_
  57. - _main.cpp_
  58. #### Task
  59. Now things are getting serious! The snake has smelled our delicous food and is appearing - beware its poisonous fangs.
  60. 1) You will notice the new component _components/Snake.*_ which you should inspect closely.
  61. 2) C++ has whats called a switch-statement which acts like many if-else-if-else chained. Look at _Snake::updateHead_ and play around with it to figure out how a switch works.
  62. 3) Even though our snake is far from complete, we want to see it! As we decided the snake to be made up of a list of points, use a modern for-each loop to call _print()_ on all points of the snakes body.
  63. 4) You have already interacted with std::vector by now. Look at the documentation for it and figure out its purpose and what else you can do with it. Play around!
  64. Once you're ready, you can _git merge lesson05_.
  65. ---
  66. ## Lesson 05
  67. #### Prequisites
  68. - Iterators/Iterating over Elements of Container
  69. #### Files
  70. - _components/Snake.cpp_
  71. - _components/Snake.h_
  72. - _main.cpp_
  73. #### Task
  74. The snake showed up but something is wrong. Its growing constantly without even having food. Lets fix that as we want to be super biologically accurate: no growth without energy. And as our snake can't eat yet, it should not grow at all.
  75. This one is quite difficult. Don't worry if it takes a lot of time and if you're really stuck, try the master branch with its solution.
  76. 1) The culprit is our snakes _Snake::move()_ function which we must fix in order for the snake to stop growing endlessly.
  77. 2) There are some hints written as todos but these leave a lot of room for the implementation. If you need some help, search for iterators (over std::vector) or use a for-loop over all indices from the back. These are just suggestions - try to come up with your own solution!
  78. 3) Try this out in main where you can still use the __mainL04__ from the previous task.
  79. Once you're ready, you can _git merge lesson06_.
  80. ---
  81. ## Lesson 06
  82. #### Prequisites
  83. None
  84. #### Files
  85. - _components/Snake.cpp_
  86. - _components/Snake.h_
  87. - _main.cpp_
  88. #### Task
  89. Our snake seems invincible for now and can't eat. Run into a wall - nothing will happen. Bite yourself - no injury. Try to eat the snack - you will just slither over it. Sad Snake :(
  90. 1) See the changes to _components/Snake.*_ and try to implement the test functions which we will use later on.
  91. 2) After implementing them, move to _main.cpp_ where __mainL06__ will allow you to test the newly written functions.
  92. 3) Figure out how you can test the bit-itself and bit-snack by yourself.
  93. Once you're ready, you can _git merge lesson07_.
  94. ---
  95. ## Lesson 07
  96. #### Prequisites
  97. None
  98. #### Files
  99. - _components/Snake.cpp_
  100. - _components/Snake.h_
  101. - _main.cpp_
  102. #### Task
  103. The snake just learned to grow by itself! How?
  104. 1) See the changes to _components/Snake.*_ and try to understand the new code which allows the snake to grow.
  105. 2) Play around with this in _main.cpp_.
  106. Once you're ready, you can _git merge lesson08_.
  107. ---
  108. ## Lesson 08
  109. #### Prequisites
  110. None
  111. #### Files
  112. - _game/Controller.cpp_
  113. - _game/Controller.h_
  114. - _main.cpp_
  115. #### Task
  116. Even though our snake and snack are ready, we a re still not at the point where we can play. This is where the game controller comes in.
  117. 1) Inspect the new files in _game/Controller.*_ and try to figure out their purpose.
  118. 2) In the main game-function called _Controller::act()_ there are still some unimplemented sections. Fix that!
  119. 3) There is a rudimentary game loop implemented for your use in _main.cpp_ as __mainL08__ with which you can test out what you have achieved.
  120. ---
  121. ## Improvements
  122. If youre still hungy for more learning, check out the master branch which does things a little differently. Try to understand everything and maybe fix the weird speed difference between vertical and horizontal snake travel (Graphics has the set-vertical which you could use). You could also implement a highscore system and allow the game state to be written to a file in order to keep high scores. Good luck and thanks for working through this!