Ok, so currently I've been trying to recreate missile command, an old atari game. While I've had help from a group in creating the graphics for the game i.e menu, plotter class, etc. I've basically been flying solo as of the game's logic i.e missile detection, health, missiles spawning and all that good stuff.
The problem I've come accross is that while I have a what I think is a good basis for what classes to have, and how different tasks should be seperated; I'm not quite sure how the classes located in different files should be "communicating" with each other. The main area where this is a problem is comes in the form of two arrays.
The way my program is set up is I have a "Missile.cpp" that basically contains all the code for my Missile Class. This consists of:
class Missile
{
private:
int radius,speed,score;
double xLocation,yLocation,xDestination,yDestination;
bool hitMissile, hitCity;
public:
Missile();
void setRadius(int);
void setSpeed(int);
void setXLocation(double);
void setYLocation(double);
void setDestination(double xloc,double yloc);
double getX();
double getY();
int getRadius();
//missile detection
bool hasHitCity();//tells city to check health/blow/do some animation depending on health
bool hasHitMissile();//tells missile to be destroyed ( enemyMissileList[index].destroy();)
//(this uses a huge if statement to check if the friendmissilearray
//and it's radius come into contact w/ the enemies
//destruction
void destroy();
};
Originally I planned to have two arrays, one located in a class designated to spawning the offensive missiles and the other dedicated to the "cannon" or where the defensive missiles would come from.
Hence the two arrays: friendlyMissileArray[AMMO] (where ammo is the set ammount of missiles you have to fire)
and enemyMissileArray[NUM_MISSILES_ONSCREEN]
(where num_missiles_onscreen is the potential amount of missiles able to be on the screen at one time) void destroy();
will basically reassign blown up enemy missiles to new x,y starting positions and have new x,y destinations (until some score is reached).
The problem I'm having is that my missile detection run in "Missile.cpp" depends on having information passed from what was originally two, but now i'm handling both offensive and defensive arrays in "Cannon.cpp" a seperate file. HOW DO I PASS THESE ARRAYS TO OTHER FILES FOR MANIPULATION??
THANK YOU FOR YOUR TIME,
You have no idea how much I would appreciate a reply! :) Happy Holidays btw!
SIDENOTE i tried to use the 'code' snippet but it keeps saying i entered the code wrong even though i read the guidelines... anybody tell me what i'm doing wrong? :P