Jump to content
  • Advertisement
Sign in to follow this  
Kheyas

I need advices

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

Hey guys!
I started a simple text based game. Basically all I need is some advice and help. How can i make the save/load system work? How can I improve the code? Is there a way to use multiple files? Would using classes make it better?(I still don't know how to use classes -they seems so complicated sad.png ).
The code is here: Code
The exe is here: Executable

Share this post


Link to post
Share on other sites
Advertisement
switch(choise)
{
case 1:{CreateCharacter();}
case 2:{LoadCharacter();CharacterMenu();}
case 3:{About();MainMenu();}
case 4:{Quit();}
default:{WrongValue();MainMenu();}
}


should be something like:

switch(choise)
{
case 1:{CreateCharacter();} break;
case 2:{LoadCharacter();CharacterMenu();} break;
case 3:{About();MainMenu();} break;
case 4:{Quit();} break;
default:{WrongValue();MainMenu();} break;
}


if you don't put break after a statement, other statements bellow will be also executed.
Break makes sure that it does not happens.

Share this post


Link to post
Share on other sites
There is absolutely a way to use multiple files, but how you do that will depend a little bit on your compiler/IDE. For Code::Blocks and Visual Studio it should just be a matter of adding those files to your project. To use code from different files you have to declare that code somewhere first. Header files are good way of doing this. Then you can (for example) all your character creation code in a file called CharacterCreation.cpp. Put definitions of the functions in CharacterCreation.hpp and in your main file have an include of CharacterCreation.hpp.

Making classes would definitely make it better. Classes as a concept aren't too difficult to understand. Creating your own constructors, destructors, operators, and using inheritance can get tricky but just basic use of classes is fairly straight forward. Think of a class as an actual object. For example in your code you have a character. That character has a bunch of information that is all kept separately at the moment, but you can use a class to combine all that information into a single variable.

class Character
{
public:
char[30] name;
int classType;
int level = 1;
int maxHealth;
int experience;
int experienceRequired = 100;
int health;
int damage;
};


Then you create a character variable based on the character class.

Character character;


And access the previous variables all from that class.

character.health = 90;
character.damage = 10;
character.experience = character.experience + 5;


This is a crude example that hopefully shows you how classes can be good just for bookkeeping, but the benefits don't stop there. Once you feel comfortable you can also add methods (functions that are specific to a class). In your current code CreateCharacter, SaveCharacter, and LoadCharacter would all be great methods to put into your class when you feel ready.

As you may imagine this makes it a lot easier to have more than one character as well. Before you would have had to create new (differently named) variables for each of your characters. With a class you can just do:

Character character1;
Character character2;
Character character3;
character1.name = "Conan";
character2.name = "Caesar";
character3.name = "Achilles";


Note: This example is really more similar to a struct because all the information is public (can be accessed from any class) and it has no methods; however, as a basic demonstration I think it suffices. As you learn more about methods and inheritance (especially) though, you will see that classes are actually far more powerful than this simple bookkeeping.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!