Noob Question
Posted: Mon Oct 26, 2015 4:10 pm
Hi guys,
Just a quick question concerning C++. I have been writing some code. However I have just realised that as I am writing several classes, it will probably make more sense to have my code organised into Header files.
Can someone please give me some guidance here as I am unsure what I should be including where.
Also do I need to have my class implementations all on the same source file? Or can I code the implementations separately on a different .cpp file for each class?
If it make any difference I am using VC++ 11.
I just feel that my code is a mess and not organised properly at the moment. Plus as far as testing classes goes, I just want to include the specific class I want to test in main.cpp for now.
Cheers in advance.
Just a quick question concerning C++. I have been writing some code. However I have just realised that as I am writing several classes, it will probably make more sense to have my code organised into Header files.
Can someone please give me some guidance here as I am unsure what I should be including where.
Also do I need to have my class implementations all on the same source file? Or can I code the implementations separately on a different .cpp file for each class?
If it make any difference I am using VC++ 11.
I just feel that my code is a mess and not organised properly at the moment. Plus as far as testing classes goes, I just want to include the specific class I want to test in main.cpp for now.
Cheers in advance.
Code: Select all
#include <iostream>
#include <stdlib.h>
#include <string>
#include <time.h>
using namespace std;
class textParse
{
public:
void playerInput(string);
};
class Combat
{
};
class MonsterSpawn
{
};
class PlayScreen
{
};
class PlayWorld
{
public:
void PrintPage();
void PrintMonsters();
void PrintItems();
};
class Player_char
{
int intCombatSkill;
int intWillPower;
int intEndurance;
bool Is_alive;
string strName;
//Use Boolean Values for classes of magic
bool hasSorcery;
bool hasEnchantment;
bool hasElementalism;
bool hasAlchemy;
bool hasProphecy;
bool hasPsychomancy;
bool hasEvocation;
//Inventory locations
string Backpack[7];
string Pouch[4];
string weapons[2];
int Nobles; //Currency
public:
void generateChar(); //In Progress, need to learn liked lists
int check_alive(); //complete
int attack();
void takeDamage (int); //complete
void print_stats();
};
void Player_char::generateChar()
{
Is_alive = 1; // Player is alive, always a good start
Nobles = 0; //Start off with no money
cout << endl;
cout << "Please enter name for Hero: ";
getline(cin, strName) ;
cout << endl << "Greetings " << strName << endl;
cout << endl << "Generating Statistics" << endl;
// Generate Combat Skill,, Will Power and Endurance. Use randomm number generator. Then use Lone Wolf Character Generation rules.
srand (time(NULL));
intCombatSkill = rand() % 9 + 10;
intWillPower = rand() % 9 + 20;
intEndurance = rand() % 9 + 20;
cout << endl << strName << " Please see your stats below: " << endl;
cout << "Combat Skill: " << intCombatSkill << endl;
cout << "Will Power: " << intWillPower << endl;
cout << "Endurance: " << intEndurance << endl;
}
int Player_char::check_alive ()
{
if (intEndurance > 0)
{
Is_alive = 1;
return (1);
}
else
{
Is_alive = 0;
return(0);
}
}
int Player_char::attack()
{
}
void Player_char::takeDamage (int x)
{
intEndurance = intEndurance - x;
}
int main()
{
}