I am wondering about the best way to save on RAM/memory when there are many required arrays (I plan to have many more NPCs and various other arrays with text and items). And I am wondering what I can improve on so far.
#include <iostream>
#include <cstring>
#define NUM_NPC 10 // Number of NPC players
#define DETAILS_HEARTS 0 // Heart Position
#define DETAILS_BDMON 1 // Birthday Month Position
#define DETAILS_BDDAY 2 // Birthday Day Position
#define DETAILS_GENDER 3 // NPC Gender
using namespace std;
class npcPlayers {
public:
int getHearts(int playerID);
int getItem(int playerID, int itemID);
int getBirthdayMonth(int playerID);
int getBirthdayDay(int playerID);
char *getName(int playerID);
npcPlayers();
private:
int npcDetails[NUM_NPC][10];
char npcNames[NUM_NPC][20];
int updateHearts(int PlayerID,int value);
};
npcPlayers::npcPlayers() {
npcNames = {"Ace","Amber","Benny","Ethan","Michael","Jay","William","Mia","Chloe","Emily"};
npcDetails = {
{0,3,5,0}, // Ace
{0,9,20,1}, // Amber
{0,1,10,0}, // Bennny
{0,12,30,0}, // Ethan
{0,2,17,0}, // Michael
{0,6,10,0}, // Jay
{0,8,9,0}, // William
{0,4,1,1}, // Mia
{0,5,13,1}, // Chloe
{0,8,5,1} // Emily
};
}
int npcPlayers::getHearts(int playerID) {
return npcDetails[playerID][DETAILS_HEARTS];
}
int npcPlayers::getItem(int playerID, int itemID) {
}
int npcPlayers::getBirthdayDay(int playerID) {
return npcDetails[playerID][DETAILS_BDDAY];
}
int npcPlayers::getBirthdayMonth(int playerID) {
return npcDetails[playerID][DETAILS_BDMON];
}
char *npcPlayers::getName(int playerID) {
return npcNames[playerID];
}
int main() {
npcPlayers npc;
cout << "Player 1 Details:" << endl;
cout << "Name: " << npc.getName(1) << endl;
cout << "Hearts: " << npc.getHearts(1) << endl;
cout << "Birthday: " << npc.getBirthdayMonth(1) << "/" << npc.getBirthdayDay(1) << endl;
return 0;
}