I'm trying to write a simple text based RPG. This is the pertinent code:
Code:
//=========================================
//PitII- Text based RPG
//01-20-07 to __-__-__
//=========================================
//INCLUDES
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
//USING
using namespace std;
//FUNCTIONS
void clear();
string begin_game();
int new_room();
struct weapon create_new_weapon(int char_lvl, int mon_lvl);
//THE SAD, LONELY, choice
char choice;
int main()
{
//Classes for use throughout the ENTIRE GAME
struct weapon
{
string name;
int min;
int max;
int bonus;
};
struct armor
{
string name;
int def;
int block;
};
class Monster
{
public:
string name;
int lvl;
int hp;
int hp_max;
int mind;
int maxd;
int armor;
int block;
};
class Hero
{
public:
string name;
int hp;
int hp_max;
string weapon_name;
int mind;
int maxd;
string armor_name;
int armor;
int block;
int lvl;
int exp;
int exp_need;
void show_stats()
{
cout<<name<<":\n"
<<"\tHealth: "<<hp<<"/"<<hp_max<<"\n"
<<"\tLevel: "<<lvl<<"\n"
<<"\tExp/Need:"<<exp<<"/"<<exp_need<<"\n"
<<weapon_name<<":\n"
<<"\tDamage: "<<mind<<"-"<<maxd<<"\n"
<<armor_name<<":\n"
<<"\tArmor: "<<armor<<"\n"
<<"\tBlock%: "<<block<<"%\n";
cout<<"Press any key to continue.\n>:";
cin>>choice;
};
};
//Begin Game:
Hero player;
player.hp = 50;
player.hp_max = 50;
player.weapon_name = "Rusty Dagger";
player.mind = 1;
player.maxd = 3;
player.armor_name = "Cloth Armor";
player.armor = 15;
player.block = 5;
player.exp = 0;
player.exp_need = 100;
player.lvl = 1;
player.name = begin_game();
cout<<player.name<<" has entered the pit.\n>:";
clear();
//Display stats, setup and display items
player.show_stats();
//Begin of Game Loop
srand(time(NULL));
do
{
clear();
create_new_weapon(2, 7);
cin>>choice;
}while(player.hp >= 1);
return 0;
}
struct weapon create_new_weapon(int char_lvl, int mon_lvl)
{
cout<<"A blacksmith forged you a weapon!"<<"\n"
<<"Sword, level "<<char_lvl + mon_lvl<<"\n";
weapon new_weapon;
new_weapon.name = "Sword";
new_weapon.min = 52;
new_weapon.max = 67;
new_weapon.bonus = 5;
return new_weapon;
}
What it is supposed to do is create a new weapon based on character and monster level, but it returns a miriad of errors-
C2027: use of undefined type 'weapon'
C2079: 'create_new_weapon' uses undefined struct 'weapon'
C2079: 'new_weapon' uses undefined struct 'weapon'
C2228: left of '.name' must have class/struct/union (for all of the things)
What's wrong?