Archived

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

ending prog outside of main()

This topic is 5531 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

I''m working on a lame text rpg, i can detect death, however the game continues, return 0; wont kill the app after i say game over, and then you just keep playing... Now I could write if thens into the turn code, like if my function returns some special number then quit game, but thats horribly inefficent i think. Is there an easier way to solve this such as killing the game from an outside function? -Kris

Share this post


Link to post
Share on other sites
When i try to use exit() the compiler says: error line 325 in stdlib.h to few arguments for void exit()

what do i have to provide exit()? a number in seconds till exit?

Share this post


Link to post
Share on other sites
Hey, I''m working on a lame text RPG too.

How far into development are you??

I designed the different classes and races, set up my main menu, designed weapons, and started my main game loop structure.

How experienced at C++ are you (I assume you''re using C++).

Share this post


Link to post
Share on other sites
exit() takes a single parameter, the exit status code. In general, 0 is assumed to mean normal termination, and non-zero is assumed to mean abnormal termination. So just use exit(0) or exit(1). It doesn''t matter too much unless you are actually checking if a program completed successfully (which you might do, for example, in a shell script).

Share this post


Link to post
Share on other sites
I started this past saturday learning C++, mines really lame in comparison to yours, all im working on right now is a battle system, when you start the game, its just like monster attacking, and so on, almost done with that.


-Kris

Share this post


Link to post
Share on other sites
I thought of using the checkfordeath() function i use to set a variable to something, and have the games main code in main() to loop while that variable is not to set to the check for death or something, however i get that the variable was not declared, is there some way to make a variable accesible to all functions, and not isolated to their own enviroments?

If that were possible i could just trash my checkfordeath() function, and do that when the damages are calculated.

Share this post


Link to post
Share on other sites
well, i suggest you work on learning c++ in a non game programming context first, but the answer to your question is to make it global, i.e. declare it outside of any function making it accessible to all of your functions

Share this post


Link to post
Share on other sites
There was an AP Computer Science case study on this a few years back (before they switched to the aquarium one). Honestly, I''ve never really looked at it, so I don''t know how good it is, but it sounds like a good example of how things can be done.

Personally, this is how I would design the game.

I''d have one Player class. If there''s only one player, that''s fine; create one player object.

I''d also make an Object class, and derive each object in the game from it.

I''d then make a Location class. Each Location would contain an array/list/vector of Objects and Players, AND, an array of pointers to other Locations (which I''ll call Doors). These would be movement options.

Each Location would have a short Name string, and a longer Description string. You could probably store all this in a text file for easy modification.

Each Player has a pointer to the Location it''s in. In order to make sure that it and the pointers in each Location correspond, I would use one member function of Player to Move; it would be a friend to the Location class.

In my main game loop, I would do something like this:


  
//Pseudocode

Player you;

while(you.Alive())
{
int choice;

cout << "You are in the " << you->Place.Name << ".\n\n"
<< you->Place.Description << "\n\n";

cout << "Where would you like to go from here?\n";

for(int i=0; i < you->Place.nDoors; i++)
{
cout << i << ".)\t" << you->Place.Doors[i]->Name << endl;
}
cout << "Enter the number of your choice: ";
cin >> choice;

you.Move(you->Place.Doors[choice]); //Pass the Move function a pointer to the next place


cout << endl;

}


Now, actually, this bit of pseudocode isn''t REALLy how you''d want to structure your code. You''d really want to delegate most of the Location description responsibilities to the Locations, and most of the description of the items within them to those items, and so on. Much of the game code would actually be within the Location class. However, I gave you this simple bit of pseudocode to help you get the idea, not REALLY to show how to do the OO design here.

I think that, with an approach like what I''ve described, you''ll be able to store most of your game within a text file, actually, and you could easily extend or change your game. Whatever you decide to do, I hope that I''ve given you some ideas.

Good luck!

Share this post


Link to post
Share on other sites
Time to read some tuts, that crap is way to advanced for me, today is like my 3rd day dealing with c++, however thanks.

All I was doing was creating a battle mode =\



-Kris

Share this post


Link to post
Share on other sites
Heh, ok then! One day at a time!

If you''re looking for a good site with good, clear, concise tutorials for the basics of C++, check out the www.cprogramming.com tutorials section. That really helped me get started!

Share this post


Link to post
Share on other sites