Hello forum hope you're all having a sweet day, Im new to C++ and am trying to make a text based game in the console (I know the argument already, I know what I'm getting into.)
Also the title of this posts pretty iffy but didn't know what to call it, any suggestions on that are welcome.
I want to make a class, or classes? (Any input welcome)
That stores a template for an NPC, say in a header file I make a class called NPC1, in a separate source file Ill have have a declaration for it to output its name and health when a condition is met. But I want to store separate data for multiple different NPC's and have NPC1 (or NPC2 or NPC3 for having multiples up at once) call the data from elsewhere so I don't have to write code for 1000 different creatures. If I wanted to change the level or health or stats of an NPC it would be as easy as going into a file and changing a number, not having to dig through multiple functions of the same source code.
This code is just a general outline of what Im trying to do, I dont think it even compiles.
I know how the basics of functions, classes, headers, and the very basic data types (int, string, bool)
Any advice at all on this subject is greatly appreciated, just keep in mind I'm new I most likely will not understand things if you try to explain it too complicated or with no explanation.
As always thank you all!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
//Main Source
#inlcude <iostream>
#include <string>
#include "Npc.h"
using namespace std;
int main
{
cout << "Welcome player"
cout << "An enemy has appeared!"
G_Npc::G_NPC;
G_NPC::G_Npc1();
return 0;
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
// NPC.cpp
#include "Npc.h"
#include <iostream>
using namespace std;
G_Npc::G_Npc1
{
string name;
int Level; //(Needs values from a different file)
int Health; //(Needs values from a different file)
cout << name << " has approached\n" << Level << Health
return 0;
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
//NPC.h
#ifndef NPC_H
#define NPC_H
#include <iostream>
#include <string>
class G_Npc
{
public:
void G_Npc1();
};
#endif
|
1 2 3 4 5
|
// File to store data for variables
?
?
?
|