#include <cmath>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
enum ItemType {
Weapon,
Shield,
Consumable,
Necklance,
Ring,
Robe,
Shirt,
Pants,
Helmet,
Chestplate,
Pauldron,
Gauntlet,
Greaves,
Boots,
};
class Item
{
private:
std::string Name;
std::string material;
int dataBaseID;
int itemVal;
std::string itemDesc;
int maxItemCharges;
ItemType type;
int weaponDmg;
int healBase;
int armorRating;
int enchantVal;
int stack;
int maxStack;
bool stackable;
public:
std::string displayName = Name + " " + material;
Item();
Item(std::string Name, std::string material,
std::string ItemDesc, int DatabaseID, int ItemType,
int Attack, int Defense, int GoldValue, int Stack,
int MaxStack, bool Stackable);
std::string GetItem() {return Name;}
std::string GetItemDesc() {return itemDesc;}
std::string GetDispName() {return displayName;}
int GetDatabaseID() {return dataBaseID;}
int GetItemType() {return type;}
int GetDmg() {return weaponDmg;}
int GetArmorRating() {return armorRating;}
int GetItemVal() {return itemVal;}
int GetStack() {return stack;}
int GetMaxStack() {return maxStack;}
bool GetStackable() {return stackable;}
};
std::vector<std::string> inventory;
void printVec(std::vector<std::string> vec) {
for (int i = 0; i < vec.size(); i++) {
std::cout << vec[i] << " \n";
}
}
Item copperLongsword("Longsword", "Copper",
"A longblade made of dull copper", 1, Weapon, 1, 0, 1, 1, 1, false);
int Die(int sides, int minVal) {
srand((unsigned int) time(NULL));
int roll = (rand() % sides) + minVal;
return roll;
}
class Character {
public:
Character();
virtual ~Character();
void initialize();
void levelUp();
void statMods();
void statDisplay();
void getName();
double xPos;
double yPos;
private:
std::string name;
int warriorLvl, rogueLvl, magicUserLvl;
int level;
int exp;
int expReq;
int strength;
int dexterity;
int constitution;
int intelligence;
int wisdom;
int charisma;
int strMod;
int dexMod;
int conMod;
int intMod;
int wisMod;
int chaMod;
int skillPoints;
int statPoints;
int hp;
int hpMax;
int stamina;
int staminaMax;
int damageMin;
int damageMax;
int armor, shield;
int armorClass;
};
Character player;
Character::Character() {
this->xPos = 0.0;
this->yPos = 0.0;
this->name = "";
this->warriorLvl, this->rogueLvl, this->magicUserLvl = 0;
this->level = 1;
this->exp = 0;
this->expReq = 0;
this->strength = 0;
this->dexterity = 0;
this->constitution = 0;
this->intelligence = 0;
this->wisdom = 0;
this->charisma = 0;
this->strMod = 0;
this->dexMod = 0;
this->conMod = 0;
this->intMod = 0;
this->wisMod = 0;
this->chaMod = 0;
this->skillPoints = 0;
this->statPoints = 0;
this->hp = 0;
this->hpMax = 0;
this->stamina = 0;
this->staminaMax = 0;
this->damageMin = 0;
this->damageMax = 0;
this->armor, this->shield = 0;
this->armorClass = 0;
}
Character::~Character() {
}
void Character::initialize() {
this->xPos = 0.0;
this->yPos = 0.0;
this->name = name;
this->warriorLvl = 0;
this->rogueLvl = 0;
this->magicUserLvl = 0;
this->level = this->warriorLvl + this->rogueLvl + this->magicUserLvl;
this->exp = 0;
this->expReq = (50/3)*(pow(level, 3) -
6*pow(level, 3) + (17*level) - 11);
this->strength = Die(1, 15);
this->dexterity = Die(1, 15);
this->constitution = Die(1, 15);
this->intelligence = Die(1, 15);
this->wisdom = Die(1, 15);
this->charisma = Die(1, 15);
this->strMod = floor((strength - 10) / 2);
this->dexMod = floor((dexterity - 10) / 2);
this->conMod = floor((constitution - 10) / 2);
this->wisMod = floor((wisdom - 10) / 2);
this->intMod = floor((intelligence - 10) / 2);
this->chaMod = floor((charisma - 10) / 2);
this->skillPoints = 0;
this->statPoints = 0;
this->hpMax = 5 + conMod;
this->hp = hpMax;
this->staminaMax = 5 + strMod;
this->stamina = staminaMax;
this->damageMin = level + dexMod;
this->damageMax = level + strMod;
this->armor, shield = 0;
this->armorClass = 10 + armor + shield;
}
void Character::statMods() {
this->strMod = floor((strength - 10) / 2);
this->dexMod = floor((dexterity - 10) / 2);
this->conMod = floor((constitution - 10) / 2);
this->wisMod = floor((wisdom - 10) / 2);
this->intMod = floor((intelligence - 10) / 2);
this->chaMod = floor((charisma - 10) / 2);
this->hpMax = 5 + conMod;
this->hp = hpMax;
this->staminaMax = 5 + strMod;
this->stamina = staminaMax;
this->damageMin = level + dexMod;
this->damageMax = level + strMod;
this->armor, shield = 0;
this->armorClass = 10 + armor + shield;
}
void Character::getName() {
std::cout << "Enter you name:\n>";
getline(std::cin, name);
}
void Character::statDisplay() {
std::cout << "= Character Sheet =" << std::endl;
std::cout << "= Name: " << this->name << std::endl;
std::cout << "= Level: " << this->level<< std::endl;
std::cout << "= Exp: " << this->exp << std::endl;
std::cout << "= Exp to next level: "
<< this->expReq << std::endl;
std::cout << std::endl;
std::cout << "= Strength: "<< this->strength <<
" - " <<this->strMod << std::endl;
std::cout << "= Dexterity: " << this->dexterity
<< " - " << this->dexMod << std::endl;
std::cout << "= Constitution: " << this->constitution
<< " - " << this->conMod << std::endl;
std::cout << "= Intelligence: " << this->intelligence
<< " - " << this->intMod << std::endl;
std::cout << "= Wisdom: " << this->wisdom
<< " - " << this->wisMod << std::endl;
std::cout << "= Charisma: " << this->charisma <<
" - " << this->chaMod << std::endl;
std::cout << std::endl;
std::cout << "= HP: "<< this->hp <<
"/" << this->hpMax << std::endl;
std::cout << "= Stamina: " << this->stamina
<< "/" << this->staminaMax << std::endl;
std::cout << "= Damage: " << this->damageMin
<< " - " << this->damageMax << std::endl;
std::cout << "= Armor Rating: " << this->armorClass << std::endl;
std::cout << std::endl;
}
void Character::levelUp() {
this->exp = 0;
int levelChoice;
std::cout << "Pick a level:\n1: Warrior\n2: Rogue\n3: Magic User\n>";
std::cin >> levelChoice;
switch(levelChoice) {
case 1:
this->warriorLvl++;
this->strength += 2;
this->constitution++;
this->dexterity -= 2;
this->intelligence--;
inventory.push_back(copperLongsword.GetDispName());
break;
case 2:
this->rogueLvl++;
this->dexterity += 2;
this->charisma++;
this->strength -= 2;
this->constitution--;
break;
case 3:
this->magicUserLvl++;
this->intelligence += 2;
this->wisdom++;
this->constitution -= 2;
this->charisma--;
break;
}
std::cout << "Pick a stat to increase:\n1:
Strength\n2: Dexterity\n3: Constitution\n4: Intelligence\n5:
Wisdom\n6: Charisma\n>";
std::cin >> levelChoice;
switch(levelChoice) {
case 1:
this->strength++;
break;
case 2:
this->dexterity++;
break;
case 3:
this->constitution++;
break;
case 4:
this->intelligence++;
break;
case 5:
this->wisdom++;
break;
case 6:
this->charisma++;
break;
}
std::cout << "Would you like to increase a second stat?
\n*Warning you must also decrease a stat*\n1: Yes\n2: No\n>";
std::cin >> levelChoice;
switch(levelChoice) {
case 1:
std::cout << "Pick a second stat to
increase:\n1: Strength\n2: Dexterity\n3:
Constitution\n4: Intelligence\n5: Wisdom\n6: Charisma\n>";
std::cin >> levelChoice;
switch(levelChoice) {
case 1:
this->strength++;
break;
case 2:
this->dexterity++;
break;
case 3:
this->constitution++;
break;
case 4:
this->intelligence++;
break;
case 5:
this->wisdom++;
break;
case 6:
this->charisma++;
break;
}
std::cout << "Pick a stat to decrease:\n1:
Strength\n2: Dexterity\n3: Constitution\n4:
Intelligence\n5: Wisdom\n6: Charisma\n>";
std::cin >> levelChoice;
switch(levelChoice) {
case 1:
this->strength--;
break;
case 2:
this->dexterity--;
break;
case 3:
this->constitution--;
break;
case 4:
this->intelligence--;
break;
case 5:
this->wisdom--;
break;
case 6:
this->charisma--;
break;
}
break;
case 2:
break;
}
this->level = warriorLvl + rogueLvl + magicUserLvl;
this->expReq = (50/3)*(pow(level, 3) -
6*pow(level, 3) + (17*level) - 11);
player.statMods();
}
class Room {
public:
std::string roomName, roomNorth, roomEast, roomWest, roomSouth;
void roomFunction();
};
class Game {
public:
Game();
virtual ~Game();
void mainMenu();
void travel();
inline bool getPlaying() const { return this->playing; }
private:
int choice;
bool playing;
};
Game::Game() {
choice = 0;
playing = true;
}
Game::~Game() {
}
void Game::mainMenu() {
std::cout << "0: QUIT\n1: North\n2: East\n3:
South\n4: West\n5: Stats\n6: Inventory\n>";
std::cin >> choice;
switch(choice) {
case 0:
this->playing = false;
break;
case 1:
player.yPos += 0.1;
break;
case 2:
player.xPos += 0.1;
break;
case 3:
player.xPos -= 0.1;
break;
case 4:
player.yPos -= 0.1;
break;
case 5:
player.statDisplay();
break;
case 6:
printVec(inventory);
break;
}
}
void Game::travel() {
}
The code above is for my MUD game, but when I run it, I get:
cd "/usercode/" && g++ main.cpp -o main &&
"/usercode/"main
/usr/bin/ld: /tmp/ccaICDEk.o: in function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x1642): undefined reference to `Item::Item(std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >,
int, int, int, int, int, int, int, bool)'
collect2: error: ld returned 1 exit status
It seems to be a undefined reference error, but I don't know how to fix it. Any help would be appreciated.
What I have tried:
Google-ing, tome of C++ knowledge. I already looked through the albeit limited sites I have at my disposal.