I am just trying to learn C++ OOP by making a game where I have an Entity class and a Board class, both included in main. How do i write a method in Entity class that can access the Board private member, specifically the tiles near it?
I want to write the function feed()
that gives energy
to an instance of Entity depending on how many tiles near it are free.
Entity.h
class Entity{
int x;
int y;
char type;
double energy;
public:
void eat();
... * it has all the constructoros and other stuff but its not relevant
}
Board.h
#include "Entity.h"
class Board{
Entity matrix[20][70];
public:
void printBoard();
Entity getEntity(int i, int j);
... * other functions and contructors. not relevant
}
main.cpp
#include <iostream>
#include "Entity.h"
#include "Board.h"
int main(){
Board* board = new Board();
// here I initialize the board with random entities
}
How do I write a function in Entity
that can get the tiles near it and check them? I can't figure out a way to interact with other classes from Entity.
Note: It can take arguments. its not mandatory to be exactly void feed();