Hello, somewhat new here, but Ill skip the introductions and get on with my problem.
I am creating a text-based rpg (yea I know, not another one), but I am having a few problems.
I have a job class, which holds all my spells and hit die and attack bonuses and such. I can create one of those on its own fine using my own constructor.
job_info.h
#ifndef job_info_H
#define job_info_H
#include <string>
#include <vector>
class job_ability {
public:
std::string name; //the name of our spell
//when using an ability deal direct damage(melee or a spell) then do the damage boost
//directDamage + damageBoost = totalDamage; ???
int directDamage; //the dice it will roll for damage (xd4-xd20)
int damageBoost; //my damage boost
double multiplier; //incase we need to do 2 or more dice
int manaCost; //mana consumed upon using
int levelReq; //level required before gaining it
std::string preReq; //pre-requisites?
//skills with buffs/debuffs/and round-lasting effects (like bleeding/poison)
int myAttackMod; //if the ability boosts my attack mod
int myDefenseMod; //if the ability boosts my defense mod
int enemyAttackMod; //if the ability lowers enemy attack mod
int enemyDefenseMod; //if the ability lowers enemy defense mod
int rounds; //the number of rounds an ability will last (0 is forever, like an Aura)
int actions; //number of actions this will take
int mpDrain; //for use with mpDrain skills
int hpDrain; //for use with hpDrain skills
//Auras
int on; //1 yes || 0 no
//Stealth/Jump Stealth can be seen through (Theif/Ninja), Jump you cannot be hit (Dragoon)
int stealthMod; // 100 is cannot be hit
};
class job_info {
public:
job_info(int choice); //this will allow us to choose our class via a prompt.
std::string name;
int hitDie;
int manaDie;
int attackBonus;
int spellDefense;
//store all of our abilities in this vector for use
//they will be filled by the becomeClass functions
std::vector<job_ability> myAbilities;
//functions
//void Berserker();
//void BlackKnight();
void BlackMage();
//void BlueMage();
//void Dragoon();
//void Engineer();
//void Fighter();
//void Marksman();
//void Monk();
//void Ninja();
//void Summoner();
//void Thief();
//void WhiteKnight();
//void WhiteMage();
};
#endif
job_info.cpp
#include "job_info.h"
#include <string>
#include <vector>
#include <iostream>
using std::string;
using std::vector;
job_info::job_info(int choice)
{
switch (choice) {
case 0: job_info::BlackMage(); break;
//more classes later
};
}
void job_info::BlackMage()
{
name = "Black Mage";
hitDie = 4;
manaDie = 12;
attackBonus = 0;
spellDefense = 0;
//Fire spell
job_ability Fire;
Fire.name = "Fire";
Fire.directDamage = 8;
Fire.multiplier = 1;
Fire.manaCost = 4;
Fire.levelReq = 1;
Fire.actions = 1;
//Start filling our container
myAbilities.push_back(Fire);
/*note to Gamedev, i took out the other 20+ skills to save space :O */
}
As you can see I can ask for a choice of input, but only 1 option is available at the moment. The important part is that it works.
If I try to create a character though, similary named 'character_info' with a member of type job_info, called 'myJob'. I cannot figure out how to be able to instantiate (that the right word?) a job_info inside my character_info's constructor.
Sorry for the mess of comments inside the following code, im trying to figure out how to get it to work, its an uphill battle, my latest attempt was to return a value with a function and use it to create 'myJob'.
character_info.cpp
#include <string>
#include <iostream>
#include <vector>
#include "job_info.h"
#include "character_info.h"
//#include "weapon_info.h"
//#include "race_info.h"
using std::cout;
using std::cin;
using std::string;
using std::endl;
using std::vector;
int character_info::selectJob() {
cout << "\nPlease choose a class by selecting its corresponding number:\n0. Black Mage" << endl;
int choice;
cin >> choice;
//job_info myJob(choice);
//cout << "\nCongratulations, you are a: " << myJob.name << endl;
//cout << "You have these abilities: \n";
//for (vector<job_ability>::const_iterator it = myJob.myAbilities.begin();
// it != myJob.myAbilities.end(); ++it)
//{
// cout << (*it).name << endl;
//};
return choice;
}
void character_info::setAttributes() {
//we need to set all our attributes here as well as change the modfier accordingly
while (attributePoints > 0) {
cout << "\nPlease spend your attribute points. You have " << attributePoints << " to spend." << endl;
cout << "\nPlease choose an attribute to add points to: "
<< "\n1: Strength" << "\n2: Dexterity" << "\n3: Vitality" << "\n: Energy" << "\n: Spirit";
int choice;
switch (choice) {
case 1: ++strength, --attributePoints; break;
case 2: ++dexterity, --attributePoints; break;
case 3: ++vitality, --attributePoints; break;
case 4: ++energy, --attributePoints; break;
case 5: ++spirit, --attributePoints; break;
default: cout << "\nThat is not a valid option please choose again." << endl; break;
};
};
cout << " You have " << attributePoints << " to spend" << endl;
}
void character_info::selectRace() {
//choose our race and change the attribute the racial bonus gives
}
void character_info::selectAbilities() {
//show the a list of available abilties by level = 1 and pre-requisite == none
}
character_info::character_info() {
//ask for name
cout << "Please enter your characters name: " << endl;
cin >> name;
//set all defaults
strength = 10;
dexterity = 10;
vitality = 10;
energy = 10;
spirit = 10;
luck = 10;
currentExp = 0;
nextExp = 1000;
level = 1;
actions = 1;
attributePoints = 15;
abilityPoints = 3;
isPoisoned = false;
isBleeding = false;
//ask to choose a job
myJob(selectJob());
//ask to plug in attribute points
setAttributes();
//ask for a race
//setRace();
//ask for abilities
//selectAbilities();
}
character_info.h
#ifndef character_info_H
#define character_info_H
#include <string>
#include "job_info.h"
//#include "weapon_info.h"
//#include "race_info.h"
class character_info {
public:
//Our default constructor will handle the name entry as well as set all the defaults for our character
character_info();
std::string name;
job_info myJob;
//weapon_info myWeapon;
//race_info myRace;
int level;
double currentExp, nextExp;
int currentHealth, maxHealth, currentMana, maxMana;
int strength, dexterity, vitality, energy, spirit, luck, strMod, dexMod, vitMod, engMod, sprMod;
int actions, attributePoints, abilityPoints;
bool isPoisoned, isBleeding; //Will allow us to perform DoT() checks
//We need to select a job
int selectJob();
//We need to spend our attribute points first
void setAttributes();
//We then need a race
void selectRace();
//Lastly, choose our abilities
void selectAbilities();
};
#endif
main
#include <iostream>
#include <vector>
#include "job_info.h"
#include "character_info.h"
using namespace std;
int main()
{
character_info myInfo; //give us a character
system("PAUSE");
return 0;
}
Anyway, if someone could hint at what im doing wrong, that would be swell.
For reference I am using MinGW Studio and DEV C++, fully updated. (I like them both :D)
*Edit: The reason I know its with the job_info stuff is from the compiler. I can also make a jobless character with ease by commenting out the job stuff, but no one likes a plain character*