![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2005
Posts: 25
Rep Power: 0
![]() |
local function definitions are illegal
Got these errors:
d:\projektet\game\game\player.h(19) : error C2061: syntax error : identifier 'monster' player.cpp and... D:\PROJEKTET\game\game\player.cpp(442) : error C2601: 'fight' : local function definitions are illegal. Code is here: #include <iostream>
#include "player.h"
#include <time.h>
#include "monster.h"
using namespace std;
#define COLOR_OFF 8
#define COLOR_RED 12
#define COLOR_YELLOW 14
#define COLOR_WHITE 15
#define COLOR_GREEN 10
#define COLOR_CYAN 11
HANDLE Color;
player::player()
{
this->strength = 0;
this->agility = 0;
this->constitution = 0;
this->gold = 0;
this->exp = 0;
this->armor = 0;
this->bonus_damage = 0;
this->item_bonus_damage = 0;
this->item_bonus_armor = 0;
this->item_bonus_max_health = 0;
this->health = 0;
this->max_health = 0;
}
player::~player()
{
}
void player::set_strength (unsigned int strength)
{
this->strength = strength;
this->update_stats();
}
void player::set_agility (unsigned int agility)
{
this->agility = agility;
this->update_stats();
}
void player::set_constitution (unsigned int constitution)
{
this->constitution = constitution;
this->update_stats();
}
void player::set_gold (unsigned int gold)
{
this->gold = gold;
}
void player::set_exp (unsigned int exp)
{
this->exp = exp;
}
void player::set_name (string name)
{
this->name = name;
}
void player::set_bonus_damage (int bonus_damage)
{
this->bonus_damage = bonus_damage;
}
void player::set_item_bonus_damage (int item_bonus_damage)
{
this->item_bonus_damage = item_bonus_damage;
}
void player::set_item_bonus_armor (int item_bonus_armor)
{
this->item_bonus_armor = item_bonus_armor;
}
void player::set_item_bonus_max_health (int item_bonus_max_health)
{
this->item_bonus_max_health = item_bonus_max_health;
}
void player::set_health (int health)
{
this->health = health;
}
unsigned int player::get_strength ()
{
return this->strength;
}
unsigned int player::get_agility ()
{
return this->agility;
}
unsigned int player::get_constitution ()
{
return this->constitution;
}
unsigned int player::get_gold ()
{
return this->gold;
}
unsigned int player::get_exp ()
{
return this->exp;
}
unsigned int player::get_armor ()
{
return this->armor;
}
unsigned int player::get_health ()
{
return this->health;
}
unsigned int player::get_bonus_damage ()
{
return this->bonus_damage;
}
unsigned int player::get_item_bonus_damage ()
{
return this->item_bonus_damage;
}
unsigned int player::get_item_bonus_armor ()
{
return this->item_bonus_armor;
}
unsigned int player::get_item_bonus_max_health ()
{
return this->item_bonus_max_health;
}
unsigned int player::get_max_health ()
{
return this->max_health;
}
string player::get_name ()
{
return this->name;
}
void player::set_stats (int base, int max_rnd, int points)
{
int c;
srand(time(NULL));
c = (rand() % max_rnd) + 1;
if(c > points)
c = points;
this->strength = base + c;
points = points - c;
c = (rand() % max_rnd) + 1;
if(c > points)
c = points;
this->agility = base + c;
points = points - c;
c = (rand() % max_rnd) + 1;
if(c > points)
c = points;
this->constitution = base + c;
points = points - c;
this->gold = 24 + ((rand() % 26) + 1);
this->update_stats();
this->health = this->max_health;
}
void player::text_dump ()
{
cout << endl;
cout << "Statistics:" << endl;
cout << "Strength = " << this->strength << endl;
cout << "Agility = " << this->agility << endl;
cout << "Constitution = " << this->constitution << endl;
cout << "Health = " << this->health << "/" << this->max_health << endl;
cout << "Armor = " << this->armor << endl;
cout << "Bonus damage = " << this->bonus_damage << endl;
cout << "Gold = " << this->gold << endl;
cout << "Experience = " << this->exp << endl;
}
void player::update_stats()
{
this->max_health = this->constitution * 3 + this->strength * 1 + this->item_bonus_max_health;
this->armor = this->agility / 8 + this->constitution / 12 + this->item_bonus_armor;
this->bonus_damage = this->strength / 8 + this->agility / 12 + this->item_bonus_damage;
}
int player::roll(int dice, int size)
{
srand(time(NULL));
int n = 0;
int i;
for(i = 0; i < dice; i++){
n = n + ((rand() % size) + 1);
}
return n;
}
void player::temple()
{
int pre_health = this->health;
cout << "\nWelcome my child, take a while and rest, and I'll take care of your scars." << endl;
Sleep(1000);
this->health = this->max_health;
int post_health = this->health;
int heal = post_health - pre_health;
cout << "\nYou have been healed by the Cleric for " << heal << " health!" << endl;
}
void player::shop()
{
string shop;
Color = GetStdHandle(STD_OUTPUT_HANDLE);
Sleep(1000);
cout << "\nYarrr, matey! Welcome to the Arena General Store." << endl;
cout << "Here you can purchase all the items you need for a wee price, have a look: " << endl;
for( ; ; ){
cout << endl;
cout << "\t(";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "W";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << ")eapon Upgrade - 50 gold" << endl;
cout << "\t(";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "A";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << ")rmor Upgrade - 50 gold" << endl;
cout << endl;
cout << "\tPotion: (";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "E";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << ")ase Wounds [";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "Max Health";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << "] - 35 gold" << endl;
cout << "\tPotion: (";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "T";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << ")iger Balm [";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "Agility";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << "] - 35 gold" << endl;
cout << "\tPotion: (";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "M";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << ")uscle Stimulator [";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "Strength";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << "] - 35 gold" << endl;
cout << "\tPotion: (";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "H";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << ")arden Skin [";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "Constitution";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << "] - 35 gold" << endl;
cout << endl;
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "\tYour gold: " << this->gold << endl;
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << endl;
cout << "Enter the letter within the parenthesis' of the item of your desire to buy it." << endl;
cout << "Type 'leave' to exit the store." << endl;
cout << endl;
SetConsoleTextAttribute(Color, COLOR_RED);
cout << this->get_health() << "hp> ";
SetConsoleTextAttribute(Color, COLOR_WHITE);
cin >> shop;
SetConsoleTextAttribute(Color, COLOR_OFF);
if(shop == "A" || shop == "a"){
if(this->gold >= 50){
this->gold = this->gold - 50;
this->item_bonus_armor = this->item_bonus_armor + 1;
cout << "\nYou have purchased an Armor Upgrade for 50 gold!" << endl;
}
else{
cout << "\nYou don't have enough gold for that, matey!" << endl;
}
}
if(shop == "W" || shop == "w"){
if(this->gold >= 50){
this->gold = this->gold - 50;
this->item_bonus_damage = this->item_bonus_damage + 1;
cout << "\nYou have purchased a Weapon Upgrade for 50 gold!" << endl;
}
else{
cout << "\nYou don't have enough gold for that, matey!" << endl;
}
}
if(shop == "M" || shop == "m"){
if(this->gold >= 35){
this->gold = this->gold - 35;
this->strength = this->strength + 3;
cout << "\nYou have purchased a Muscle Stimulator for 35 gold!" << endl;
}
else{
cout << "\nYou don't have enough gold for that, matey!" << endl;
}
}
if(shop == "H" || shop == "h"){
if(this->gold >= 35){
this->gold = this->gold - 35;
this->constitution = this->constitution + 3;
cout << "\nYou have purchased a Potion: Harden Skin for 35 gold!" << endl;
}
else{
cout << "\nYou don't have enough gold for that, matey!" << endl;
}
}
if(shop == "T" || shop == "t"){
if(this->gold >= 35){
this->gold = this->gold - 35;
this->agility = this->agility + 2;
cout << "\nYou have purchased a Potion: Tiger Balm for 35 gold!" << endl;
}
else{
cout << "\nYou don't have enough gold for that, matey!" << endl;
}
}
if(shop == "E" || shop == "e"){
if(this->gold >= 35){
this->gold = this->gold - 35;
this->item_bonus_max_health = this->item_bonus_max_health + 15 ;
cout << "\nYou have purchased a Potion: Ease Wounds for 35 gold!" << endl;
}
else{
cout << "\nYou don't have enough gold for that, matey!" << endl;
}
}
if(shop == "leave" || shop == "Leave"){
break;
cout << endl;
}
this->update_stats();
}
int player::fight(monster *m){
int ph_chance;
int mh_chance;
int md_chance;
int pd_chance;
int p_damage;
int m_damage;
int roll;
int f_damage;
for( ; ; ){
Sleep(1000);
ph_chance = this->agility * 3;
pd_chance = this->agility;
p_damage = this->roll(1, 6);
p_damage = p_damage + this->bonus_damage;
mh_chance = m->agility * 3;
md_chance = m->agility;
m_damage = m->roll(1, 6);
m_damage = m_damage + m->bonus_damage;
roll = roll(1, 100);
if(roll <= ph_chance){
roll = roll(1, 100);
if(roll <= md_chance){
cout << "The " << m->get_name() << " dodges your attack. " << endl;
}
else{
f_damage = p_damage - m->get_armor();
cout << "You hit the " << m->get_name() << " for " << f_damage << " damage." << endl;
m->set_health(m->get_health() - f_damage);
if(m->get_health() <= 0){
cout << "You have perished the " << m->get_name() << "." << endl;
cout << "You gain " << m->get_exp() << " experience points." << endl;
cout << "You gain " << m->get_gold() << " gold." << endl;
this->gold = this->gold + m->get_gold();
this->exp = this->exp + m->get_exp();
delete m;
return 1;
}
}
}
else {
cout << "You miss the " << m->get_name << "." << endl;
}
roll = roll(1, 100);
if(roll <= mh_chance){
roll = roll(1, 100);
if(roll <= pd_chance){
cout << "You dodge the " << m->get_name() << "'s attack." << endl;
}
else{
f_damage = m_damage - this->get_armor();
cout << "The " << m->get_name() << " hits you for " << f_damage << " damage." << endl;
this->health = this->health - f_damage;
if(this->health <= 0){
cout << "You have been slain by the " << m->get_name() << "." << endl;
return 0;
]
}
}
}
else{
cout << "The " << m->get_name << " misses you." << endl;
}
cout << "[" << this->name << " HP: " << this->health << "\t" << m->get_name() << " HP: " << m->get_health() << "]" << endl;
}
}
}and it's header-file: #ifndef __PLAYER_H__
#define __PLAYER_H__
#include <string>
#include <iostream>
#include "monster.h"
#include <windows.h>
using namespace std;
class player {
public:
player();
~player();
static int roll(int dice, int size);
int fight(monster *m);
void set_strength (unsigned int strength);
void set_agility (unsigned int agility);
void set_constitution (unsigned int constitution);
void set_exp (unsigned int exp);
void set_gold (unsigned int gold);
void set_name (string name);
void set_bonus_damage (int bonus_damage);
void set_health (int health);
void set_item_bonus_damage (int item_bonus_damage);
void set_item_bonus_armor (int item_bonus_armor);
void set_item_bonus_max_health (int item_bonus_max_health);
void shop();
void temple();
unsigned int get_strength ();
unsigned int get_agility ();
unsigned int get_constitution ();
unsigned int get_gold ();
unsigned int get_exp ();
unsigned int get_armor ();
unsigned int get_health ();
unsigned int get_max_health ();
unsigned int get_bonus_damage ();
unsigned int get_item_bonus_damage ();
unsigned int get_item_bonus_armor ();
unsigned int get_item_bonus_max_health ();
string get_name ();
void set_stats (int base, int max_rnd, int points);
void text_dump();
private:
void update_stats();
string name;
unsigned int strength;
unsigned int agility;
unsigned int constitution;
unsigned int armor;
int bonus_damage;
int health;
int max_health;
int item_bonus_damage;
int item_bonus_armor;
int item_bonus_max_health;
unsigned int gold;
unsigned int exp;
};
#endifLast edited by Siphon; Feb 7th, 2005 at 5:16 PM. |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Feb 2005
Posts: 25
Rep Power: 0
![]() |
Oh and what is the Windows equivalent to "unistd.h" in linux/unix ?
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jan 2005
Posts: 20
Rep Power: 0
![]() |
Must be something in monster.h
Can you post the monster.h code? There is no replacement for unistd.h. Some of it is defined in io.h or sys/types.h but not all of it. Last edited by Monster; Feb 7th, 2005 at 5:32 PM. |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Feb 2005
Posts: 25
Rep Power: 0
![]() |
#ifndef __MONSTER_H__
#define __MONSTER_H__
#include <string>
#include <iostream>
#include <windows.h>
#include "player.h"
using namespace std;
class monster {
public:
monster();
~monster();
static int roll (int dice, int size);
void set_strength (unsigned int strength);
void set_agility (unsigned int agility);
void set_constitution (unsigned int constitution);
void set_monster1_stats ();
void set_exp (unsigned int exp);
void set_gold (unsigned int gold);
void set_id (unsigned int id);
void set_name (string name);
void set_desc (string desc);
void set_health (int health);
string get_name();
string get_desc();
unsigned int get_strength ();
unsigned int get_agility ();
unsigned int get_constitution ();
unsigned int get_gold ();
unsigned int get_exp ();
unsigned int get_id ();
unsigned int get_armor ();
unsigned int get_health ();
int get_max_health();
void text_dump();
private:
void update_stats();
string name;
string desc;
unsigned int id;
unsigned int strength;
unsigned int agility;
unsigned int constitution;
unsigned int armor;
int bonus_damage;
int health;
int max_health;
unsigned int gold;
unsigned int exp;
};
#endif |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Jan 2005
Posts: 20
Rep Power: 0
![]() |
void player::shop() needs an extra closing bracked (the for loop).
b.t.w. I don't get the first error on monster Last edited by Monster; Feb 7th, 2005 at 5:40 PM. |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Feb 2005
Posts: 25
Rep Power: 0
![]() |
that aint it..
almost everything in their is supposed to be in the for-loop... so it starts over and over until you type "leave"... that is, leave the shop. Last edited by Siphon; Feb 7th, 2005 at 5:42 PM. |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Jan 2005
Posts: 20
Rep Power: 0
![]() |
Are you sure, because that's exactly what the compiler tells you: local function definitions are illegal
I have added and extra } just before the int player::fight(monster *m) function and it doesn't complain anymore. |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Feb 2005
Posts: 25
Rep Power: 0
![]() |
both errors are supposed to be in the player.cpp and player.h
here are the two other files in the program: #include <iostream>
#include "monster.h"
#include <time.h>
#include "player.h"
using namespace std;
monster::monster()
{
this->strength = 0;
this->agility = 0;
this->constitution = 0;
this->gold = 0;
this->exp = 0;
this->bonus_damage = 0;
this->armor = 0;
this->health = 0;
this->max_health = 0;
}
monster::~monster()
{
}
void monster::set_strength (unsigned int strength)
{
this->strength = strength;
this->update_stats();
}
void monster::set_agility (unsigned int agility)
{
this->agility = agility;
this->update_stats();
}
void monster::set_constitution (unsigned int constitution)
{
this->constitution = constitution;
this->update_stats();
}
void monster::set_gold (unsigned int gold)
{
this->gold = gold;
}
void monster::set_exp (unsigned int exp)
{
this->exp = exp;
}
unsigned int monster::get_strength ()
{
return this->strength;
}
unsigned int monster::get_agility ()
{
return this->agility;
}
unsigned int monster::get_constitution ()
{
return this->constitution;
}
unsigned int monster::get_gold ()
{
return this->gold;
}
unsigned int monster::get_exp ()
{
return this->exp;
}
unsigned int monster::get_health ()
{
return this->health;
}
string monster::get_name ()
{
return this->name;
}
void monster::text_dump ()
{
cout << this->get_name() << endl;
cout << "Strength = " << this->strength << endl;
cout << "Agility = " << this->agility << endl;
cout << "Constitution = " << this->constitution << endl;
cout << "Health = " << this->health << "/" << this->max_health << endl;
cout << "Armor = " << this->armor << endl;
cout << "Bonus damage = " << this->bonus_damage << endl;
cout << "Gold = " << this->gold << endl;
cout << "Experience = " << this->exp << endl;
}
void monster::update_stats()
{
this->max_health = this->constitution * 3 + this->strength * 1;
this->armor = this->agility / 8 + this->constitution / 12;
this->bonus_damage = this->strength / 8 + this->agility / 12;
}
int monster::roll(int dice, int size)
{
srand(time(NULL));
int n = 0;
int i;
for(i = 0; i < dice; i++){
n = n + ((rand() % size) + 1);
}
return n;
}
void monster::set_monster1_stats()
{
this->name = "Goblin";
this->desc = "A scrawny little green monster.";
this->strength = 10;
this->agility = 15;
this->constitution = 10;
this->gold = 20;
this->exp = 25;
this->bonus_damage = this->strength / 8 + this->agility / 12;
this->armor = this->agility / 8 + this->constitution / 12;
this->max_health = this->constitution * 3 + this->strength * 1;
this->health = this->max_health;
}that was monster.cpp, here comes game.cpp: #include <iostream>
#include "player.h"
#include "monster.h"
#include <stdlib.h>
using namespace std;
#define COLOR_OFF 8
#define COLOR_RED 12
#define COLOR_YELLOW 14
#define COLOR_WHITE 15
#define COLOR_GREEN 10
#define COLOR_CYAN 11
int main()
{
int u;
HANDLE Color;
string name;
string confirm;
string action;
player *p;
monster *m;
p = new player();
m = new monster();
m->set_monster1_stats();
Color = GetStdHandle(STD_OUTPUT_HANDLE);
for( ; ; ){
system("cls");
SetConsoleTextAttribute(Color, COLOR_RED);
cout << "Welcome to SiSUD" << endl;
SetConsoleTextAttribute(Color, COLOR_OFF);
p->set_stats(10, 10, 15);
p->text_dump();
cout << "\nRe-roll? (Y/N): ";
SetConsoleTextAttribute(Color, COLOR_WHITE);
cin >> confirm;
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << endl;
if(confirm == "n" || confirm == "N") break;
}
cout << "Welcome to the Arena! " << endl << endl;
cout << "What is your name, gladiator?: ";
SetConsoleTextAttribute(Color, COLOR_WHITE);
cin >> name;
SetConsoleTextAttribute(Color, COLOR_OFF);
p->set_name(name);
u = ((rand() % 3) + 1);
if(u == 1){
cout << endl;
cout << p->get_name() << "? I think I had a pet hamster once with that name. \nBut he's dead now." << endl;
}
if(u == 2){
cout << endl;
cout << "I know a dwarf called " << p->get_name() << ". You look alot like him." << endl;
}
if(u == 3){
cout << endl;
cout << "Hahah... What a soft name " << p->get_name() << " is. But I guess it suits you, peasant." << endl;
}
Sleep(1500);
/* Loading game (Fun thing, doesn't work).
cout << "\nLoading game";
for(u = 0; u < 5; u++){
cout << ".";
Sleep(500);
cout << endl;
}
*/
for( ; ; ){
cout << endl;
cout << "To enter the gauntlet, type 'go'." << endl;
cout << "If you're hurt, try going to the 'temple'. " << endl;
cout << "Or if you want to buy some goods, go to the 'shop'. " << endl;
cout << "To check your statistics, type 'stats'." << endl;
cout << "Want to quit? Then 'quit' is your way out of this hole." << endl;
cout << endl;
SetConsoleTextAttribute(Color, COLOR_RED);
cout << p->get_health() << "hp> ";
SetConsoleTextAttribute(Color, COLOR_OFF);
SetConsoleTextAttribute(Color, COLOR_WHITE);
cin >> action;
SetConsoleTextAttribute(Color, COLOR_OFF);
if(action == "shop" || action == "Shop"){
p->shop();
}
if(action == "temple" || action == "Temple"){
p->temple();
}
if(action == "stats" || action == "Stats"){
p->text_dump();
}
if(action == "q" || action == "quit" || action == "Quit"){
cout << "\nThanks for playing!\n";
exit(0);
}
if(action == "go" || action == "Go"){
if(p->fight(m) == 0) exit(0);
}
}
delete p;
return 0;
} |
|
|
|
|
|
#9 |
|
Newbie
Join Date: Feb 2005
Posts: 25
Rep Power: 0
![]() |
that's probably because you haven't included these other 2 files... I get 12-13 more errors like these when I do that:
D:\PROJEKTET\game\game\player.cpp(501) : error C2064: term does not evaluate to a function D:\PROJEKTET\game\game\player.cpp(513) : error C2143: syntax error : missing ';' before ']' and D:\PROJEKTET\game\game\player.cpp(468) : error C2248: 'bonus_damage' : cannot access private member declared in class 'monster' d:\projektet\game\game\monster.h(63) : see declaration of 'bonus_damage' I've counted the brackets and they should be correct. |
|
|
|
|
|
#10 |
|
Newbie
Join Date: Jan 2005
Posts: 20
Rep Power: 0
![]() |
I'm still missing a closing bracked in the shop function.
The } just after this->update_stats(); is the closing bracked of the for loop. You need an extra to close your function. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|