I have five files right now: main.cpp, food.cpp, food.h, apple.cpp and apple.h. I want to make food an abstract class and create a food array in the main.cpp. It seems also to have problems with the #include statements because they get included several times and it causes redefinition errors. The #include statements of the five files are as follow:
// main.cpp
#include "Food/Food.h"
#include "Food/Apple.h"
// Food.cpp
#include "Food.h"
void Food::draw(uint8_t positionX, uint8_t positionY, uint8_t state) { }
// Food.h
#include <stdint.h>
#include "Pokitto.h"
class Food
{
public:
// Public member variables
uint8_t saturationPoints;
uint8_t weightPoints;
uint8_t happinessPoints;
// Public member functions
virtual void draw(uint8_t positionX, uint8_t positionY, uint8_t state) = 0;
};
// Apple.cpp
#include "Apple.h"
#include "../Graphic.h"
extern Pokitto::Core game;
Apple::Apple()
{
Food::saturationPoints = 5;
Food::weightPoints = 5;
Food::happinessPoints = 5;
}
void Apple::draw(uint8_t positionX, uint8_t positionY, uint8_t state)
{
switch (state)
{
case 1:
game.display.drawBitmap(positionY, positionY, apple_1);
break;
case 2:
game.display.drawBitmap(positionY, positionY, apple_2);
break;
case 3:
game.display.drawBitmap(positionY, positionY, apple_3);
break;
}
}
// Apple.h
#include "Food.h"
class Apple : Food
{
public:
// Public member functions
Apple();
void draw(uint8_t positionX, uint8_t positionY, uint8_t state);
};
In the main class I want to make a food array as global variable and add (for example an instance of the Apple class) or modify array elements.