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.
 
 
 

2.7 KiB

Lesson 01

Prequisites

  • Classes
  • Functions

Files

  • components/Point.cpp
  • components/Point.h
  • main.cpp

Task

  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.
  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.
  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.
  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).
  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
  6. Continue exploring around with the point and see what happens.

Once you're ready, you can git merge lesson02.


Lesson 02

Prequisites

  • Random Numbers
  • Functions
  • Pointers/References

Files

  • components/Snack.cpp
  • components/Snack.h
  • main.cpp

Task

Every little snake needs to eat. And no snake will appear without food, which is why we begin by providing this essential item.

  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.
  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).
  3. A Snack must also look enticing, so set its image to the one defined as SNACK_CHAR and then display the delicious snack.
  4. Experiment and use mainL02 to test if your code works.
  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.

Once you're ready, you can git merge lesson03.