Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Merc22

Why won't this code run??????????

This topic is 6386 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

sorry to bother u all but this is my question i have this code and its causing me extreme grief it compiles good but when i run the .exe file it dont work i made the code output one word so it would be easier to find bugs here is the code(divided into 4 source files): first source file: class BPlayer { private: BRoom* currentroom; public: BPlayer(BRoom* start) { *currentroom=*start; } void Explore() { currentroom->Print(); } }; second source file: #include class BRoom { public: virtual void Print() { cout <<"Hi\n"; } }; third source file: #include class CRoom : public BRoom { public: void Print() { cout <<"Blah\n"; } }; fourth source file: #include "BRoom.hpp" #include "CRoom.hpp" #include "BPlayer.hpp" int main() { BRoom* rom=new CRoom; BPlayer* player=new BPlayer(rom); player->Explore(); delete rom; delete player; return 0; }

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
BPlayer(BRoom* start)
{
*currentroom=*start;
}

leave out those stars so it becomes

BPlayer(BRoom* start)
{
currentroom=start;
}

and it should work.

-ector

Share this post


Link to post
Share on other sites
sorry i got another problem
this time i have 1 bug plaguing my direction finding function
these are the errors:
c:\rpg\BPlayer.hpp: In method `void BPlayer::Explore()'':

no matching function for call to `BRoom::ChooseDirection ()''


once again the code is cut up into 4 source files
here is the code:

source file 1:


//this is the class that will be the player
class BPlayer
{
//this part will be private
private:

//this is the variable that holds the current room player is in
BRoom* currentroom;

//this is the variable that holds next room user will be in
BRoom* nextroom;

//this part will be public
public:

//this is the constructor
BPlayer(BRoom* start)
{
currentroom=start;
}

//this is the function that explores the current room
void Explore()
{
currentroom->PrintDescription();
nextroom=currentroom->ChooseDirection();
if(nextroom!=NULL)
currentroom=nextroom;
}
};


source file 2:


//this is the class that will be the basis for all rooms
class BRoom
{
//this part will be protected
protected:

//these will be the directions in each room(some will not be viable in some rooms)
BRoom* northexit;
BRoom* southexit;
BRoom* eastexit;
BRoom* westexit;

//this part will be public
public:

//this is the function that prints the room description
virtual void PrintDescription();

//this is the function that prints the directions available\
virtual BRoom* ChooseDirection();

};


source file 3:


#include
#include

//this is the class for the room that the player will start in
class room1 : public BRoom
{
//this part is public
public:

//this is the constructor
room1()
{}

//this is the destructor
~room1()
{}

//this function will print the description of this room
void PrintDescription()
{
cout <<"You are standing in a small room that reeks of decay. As you look \n";
cout <<"around you notice a small hole in the ceiling. Thats probally how \n";
cout <<"you got here. As you reach out to touch the walls a sudden cold comes\n";
cout <<"you. The wall feels cold and slimy to the touch.\n";
//if there is a way to go north, say it
if(northexit)
cout <<"\nThere is a opening to the north\n";

//if there is a way to go south, say it
if(southexit)
cout <<"There is a opening to the south\n";

//if there is a way to go east, say it
if(eastexit)
cout <<"There is a opening to the east\n";

//if there is a way to go west, say it
if(westexit)
cout <<"There is a opening to the west\n";

system("PAUSE");
}

//this function lets player chose direction to go
BRoom* ChooseDirection()
{
//this variable records the direction user wants to go
char direction;

//ask the user where to go
cout <<"\nWhere will you like to go?\n";
cout <<"1)North\n";
cout <<"2)South\n";
cout <<"3)East\n";
cout <<"4)West\n";
cin >>direction;

switch(direction)
{
case ''n'':
if(northexit)
return northexit;
break;
case ''s'':
if(southexit)
return southexit;
break;
case ''e'':
if(eastexit)
return eastexit;
break;
case ''w'':
if(westexit)
return westexit;
break;
default:
cout <<"You picked a wrong route!\n";
return NULL;
break;
}
}
};


source file 4:


#include "BRoom.hpp"
#include "room1.hpp"
#include "BPlayer.hpp"

int main()
{
BRoom* rom1=new room1;
BPlayer* player=new BPlayer(rom1);
player->Explore();
delete rom1;
delete player;
return 0;
}

Share this post


Link to post
Share on other sites
//this is the function that prints the room description
virtual void PrintDescription();

//this is the function that prints the directions available\
virtual BRoom* ChooseDirection();

Note the \ at the end of the second comment. *nods* Toast it.
It''s the line continuation marker. It means the line:
virtual BRoom* ChooseDirection();

Is also taken as being a comment.

Share this post


Link to post
Share on other sites
omg
thanx man
but u missed one error

i fixed it though
THANX MAN
I LUV U
I WANNA KISS U
I OWE U SO MUCH!!!!!!

thanx

Share this post


Link to post
Share on other sites
GOD DAMN IT
i incorporated this help into my game and guess wat
MORE ERRORS
i dont get it

u knoe the drill
4 source files blah blah

source file 1:

#include
#include

//this is the class for the first area player is in
class Area1 : public BArea
{
//this part is private
private:

//this is for choosing directions
char direction;

//this part is public
public:

//this is the constructor
Area1(BArea* east, BArea* west)
{
eastexit=east;
westexit=west;
}

//this is the function that prints the area description
void PrintDescription()
{
int choice;
cout <<"As you look around your stainless steel gantry, you see your custom made\n";
cout <<"capsule in the corner. On the capsule is the word PROTON in bright silver.\n";
cout <<"You goto your access port and download the latest information. One bit of info\n";
cout <<"is very interesting in that the commander announced the completion of the Battle\n";
cout <<"Simulator room. You make a mental note to visit it later.\n\n";
system("PAUSE");

//start option checking loop
do
{
cout <<"\nStatus:\n";
cout <<"1)Check your stats\n";
cout <<"2)Look for a way out\n";
cin >> choice;

switch(choice)
{
case 1:
player->Stats();
break;
case 2:
break;
default:
cout <<"You chose a wrong option!\n";
break;
}
}while(choice=1);
}

virtual BArea* ChooseArea()
{
//if there is a corridor going north tell the player
if(northexit)
cout <<"There is a corridor leading to the north\n";

//if there is a corridor leading south tell the player
if(southexit)
cout <<"There is a corridor leading to the south\n";

//if there is a corridor leading east tell the player
if(eastexit)
cout <<"There is a corridor leading to the east\n";

//if theer is a corridor leading west tell the player
if(westexit)
cout <<"There is a corridor leading west\n";

cout <<"\nWhere will you go?\n";
cin >> direction;

switch(direction)
{
case ''n'':
if(northexit)
return northexit;
break;
case ''s'':
if(southexit)
return southexit;
break;
case ''e'':
if(eastexit)
return eastexit;
break;
case ''w'':
if(westexit)
return westexit;
break;
default:
cout <<"You picked a wrong direction!\n";
return NULL;
break;
}
}
};

source file 2:

//this is the base class for all areas
class BArea
{
//this part is protected
protected:

//this is the north route
BArea* northexit;

//this is the south route
BArea* southexit;

//this is the east route
BArea* eastexit;

//this is the west route
BArea* westexit;

//this part is public
public:

//this is the function that prints the area description
virtual void PrintDescription();

//this is the function that chooses next area
virtual BArea* ChooseArea();

};

source file 3:

//this is the base class that has all the stats for each character
class BStats
{
//this part is protected
protected:

//this is the hp
int hp;

//this is the base hp
int bhp;

//this is the agility
int agility;

//this is the armor
int armor;

//this is the level
int level;

//this is the exp
int exp;

//this is the exp for next level
int nlevel;

//this is the strength
int strength;

//this is the saber damage
int sdamage;

//this is the gun damage
int gdamage;

//this is the special damage
int spdamage;


};

source file 4:

#inlcude
#include

//this is the class that maes the player object
class CPlayer : public BStats
{
//this part is private
private:

//this holds the current area
BArea* currentarea;

//this holds the next area
BArea* nextarea;

//this part is public
public:

//this is the constructor which loads the currentarea
CPlayer(BArea* start)
{
currentarea=start;
hp=150;
bhp=hp;
agility=10;
armor=20;
level=1;
exp=0;
nlevel=20;
strength=10;
sdamage=15;
gdamage=10;
spdamage=25;
}

//this is the function that starts the whole game off(start exploring)
void Explore()
{
//print the area description
currentarea->PrintDescription();

//user picks a new area to go to
nextarea=currentarea->ChooseArea();

//if direction is valid go there
if(nextarea!=NULL)
currentarea=nextarea;
}

//this is the function that displays the stats of player
void Stats()
{
cout <<"\t\tUSER STATS\n";
cout <<"\nHp: " << hp <<"\n";
cout <<"Strength: " << strength <<"\n";
cout <<"Armor: " << armor <<"\n";
cout <<"Agility: " << agility <<"\n";
cout <<"Level: " << level <<"\n";
cout <<"Exp: " << exp <<"\n";
cout <<"Next Level: " << nlevel <<"\n";
cout <<"Saber Damager: " << sdamage <<"\n";
cout <<"Gun Damage: " << gdamage <<"\n";
cout <<"Special Damage: " << spdamage <<"\n";
system("PAUSE");
}
};

source file 5:

#include "Area1.hpp"
#include "BArea.hpp"
#include "BStats.hpp"
#include "CPlayer.hpp"

int main()
{
BArea* room1=new Area1;
CPlayer* player=new CPlayer(room1);
player->Explore();
delete room1;
delete player;
return 0;
}

thanx

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!