Hi, I'm making a small game to test out and build upon my C++ knowledge, but i've hit a road block. I'm familiar with classes however I have never really learned how to use objects from one class in another without inheritance. I know about friend but I was wondering if there was a way to use functions and variables without friend. I dont think inheritance is applicable here so what else can I do? For instance, in this program, I have the DrawMap() Function, in that function I need to set the player start position but since the player is not part of game class, I cannot use the function from the player class in the game class functions. I'm having an extraordinarily difficult time figuring this out. I've been messing with it and researching stuff for a few hours now and I cannot seem to get it to work. I feel so close to a solution but cant get there, it's like trying to put together two negative sides of a powerful magnet.


main.cpp


Code:
#include <iostream>
#include <string>


#include "Game.h"
#include "Player.h"


using namespace std;


//I wrote the entire working program in main just to make sure it //works right, now im trying to break it up into smaller chunks.
int main()
{
    /*
    int mapColSize = 10;
    int mapRowSize = 22;


    char mapArray[mapColSize][mapRowSize];


    char mapGrid = 'o';
    char playerChar = '*';
    char rockObstacle = '#';


    int playerXPos = 3;
    int playerYPos = 3;


    int choice = 0;


    while(choice != -1)
    {
        for(int col = 0; col < mapColSize; col++)
        {
            for(int row = 0; row < mapRowSize; row++)
            {
               mapArray[col][row] = mapGrid;
               mapArray[playerYPos][playerXPos] = playerChar;


               cout << mapArray[col][row];
            }
            cout << endl;
        }


        cout << "\nWhat direction would you like to move?\n" << endl;


        cout << "1) UP" << endl;
        cout << "2) DOWN" << endl;
        cout << "3) LEFT" << endl;
        cout << "4) RIGHT" << endl;
        cout << ">";
        cin >> choice;


        switch(choice)
        {
            case 1:
                if(playerYPos > 0)
                {
                    playerYPos -= 1;
                    cout << "Player Y Pos: " << playerYPos << endl;
                }
                else if(playerYPos == 0)
                {
                    playerYPos -= 0;
                    cout << "You cannot go any further North!\n" << endl;
                }
                break;
            case 2:
                if(playerYPos < mapColSize -1)
                {
                    playerYPos += 1;
                    cout << "Player Y Pos: " << playerYPos << endl;
                }
                else if(playerYPos == mapColSize -1)
                {
                    playerYPos += 0;
                    cout << "You cannot go any further South!" << endl;
                }
                break;
            case 3:
                if(playerXPos > 0)
                {
                    playerXPos -= 1;
                    cout << "Player X Pos: " << playerXPos << endl;
                }
                else if(playerXPos == 0)
                {
                    playerXPos -= 0;
                    cout << "You cannot go any further West!" << endl;
                }
                break;
            case 4:
                if(playerXPos < mapRowSize -1)
                {
                    playerXPos += 1;
                }
                else if(playerXPos == mapRowSize -1)
                {
                    playerXPos += 0;
                    cout << "You cannot go any further East!" << endl;
                }
                break;
            default:
                cout << "Not a valid option" << endl;
        }
    }


    */


    return 0;
}



Game.h


Code:
#ifndef GAME_H
#define GAME_H




class Game
{
    public:
        Game() = default;
        ~Game() = default;


        void DrawMap();
        void DrawObstacles();
        void GameLoop();


    private:
        int mapColSize = 10;
        int mapRowSize = 22;


        char mapArray[0][0];


        char mapGrid = 'o';
        char rockObstacle = '#';
};


#endif // GAME_H



Game.cpp


Code:
#include "Game.h"
#include "Player.h"


#include <iostream>


using std::cout;
using std::endl;
using std::cin;


void Game::GameLoop()
{
    int choice = 0;


    while(choice != -1)
    {
        cout << "\nWhat direction would you like to move?\n" << endl;


        cout << "1) UP" << endl;
        cout << "2) DOWN" << endl;
        cout << "3) LEFT" << endl;
        cout << "4) RIGHT" << endl;
        cout << ">";


        cin >> choice;


        /*Call CheckPlayerScreenBounds()*/
    }
}


void Game::DrawMap()
{
        for(int col = 0; col < mapColSize; col++)
        {
            for(int row = 0; row < mapRowSize; row++)
            {
                mapArray[col][row] = mapGrid;
                /*Call DrawPlayer() function*/
                cout << mapArray[col][row];
            }
            cout << endl;
        }
}



Player.h


Code:
#ifndef PLAYER_H
#define PLAYER_H




class Player
{
    public:
        Player() = default;
        ~Player() = default;


        void SetPlayerOnMap();
        int GetPlayerXYPosition() const;
        void CheckScreenBounds(int choice);
        void CheckObstacleBounds();
        int GetPlayerInput();
        inline int MoveUp();
        inline int MoveDown();
        inline int MoveLeft();
        inline int MoveRight();




    private:
        char playerChar = '*';
        int playerXPos = 3;
        int playerYPos = 3;
        int playerMovement = 1;
};


#endif // PLAYER_H

Player.cpp


Code:
#include "Player.h"


#include <iostream>


using std::cout;
using std::endl;


inline int Player::MoveUp()
{
    playerYPos -= playerMovement;


    return playerYPos;
}


inline int Player::MoveDown()
{
    playerYPos += playerMovement;


    return playerYPos;
}


inline int Player::MoveLeft()
{
    playerXPos -= playerMovement;


    return playerXPos;
}


inline int Player::MoveRight()
{
    playerXPos += playerMovement;


    return playerXPos;
}




void Player::CheckScreenBounds(int choice)
{
    switch(choice)
    {
        case 1: //Move Up
            if(playerYPos > 0)
            {
                MoveUp();
                cout << "Player Y Pos: " << playerYPos << endl;
            }
            else if(playerYPos == 0)
            {
                MoveDown();
                cout << "You cannot go any further North!\n" << endl;
            }
            break;
        case 2: //Move Down
            if(playerYPos < mapColSize -1)
            {
                MoveDown();
                cout << "Player Y Pos: " << playerYPos << endl;
            }
            else if(playerYPos == mapColSize -1)
            {
                MoveUp();
                cout << "You cannot go any further South!" << endl;
            }
            break;
        case 3: //Move Left
            if(playerXPos > 0)
            {
                MoveLeft();
                cout << "Player X Pos: " << playerXPos << endl;
            }
            else if(playerXPos == 0)
            {
                MoveRight();
                cout << "You cannot go any further West!" << endl;
            }
            break;
        case 4: //Move Right
            if(playerXPos < mapRowSize -1)
            {
                MoveRight();
            }
            else if(playerXPos == mapRowSize -1)
            {
                MoveLeft();
                cout << "You cannot go any further East!" << endl;
            }
            break;
        default:
            cout << "Not a valid option" << endl;
    }
    Game::DrawMap();
}


inline void Player::SetPlayerOnMap()
{
    mapArray[playerYPos][playerXPos] = playerChar;
}