Battle System with stats

Started by
3 comments, last by _goat 17 years, 9 months ago
Hey Guys! I'm making alittle feature on my battle system right now. currently it's working with random numbers but still theres a limit ofcourse :-) but I wanna break this limit with level system. but I haven't seen a code with a system that could read in my text (or what everkind of document) f.ex. strength=10 health=250 something like this :-) anybody who can give me just an example of the code that can read these numbers :-D
I wanna become a good programmer for my game :-)
Advertisement
Offhand:

#include <iostream>#include <fstream>#include <sstream>#include <string>std::istream& parse_line(std::istream& is, std::string& token, int& value){   std::string line;   std::getline(is, line);   std::istringstream iss(line);   std::getline(iss, token, '=');   iss >> value;   return is;}int main(){   std::ifstream file("data.txt");   while(!file.eof())   {      std::string token;      int value;      parse_line(file, token, value);      std::cout << token << " is " << value;   }}


Note that this code is very brittle.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Hi,

you could try an INI Parser. There should be one available for nearly every language.

Check out the Wikipedia Page on INI Files as they have an explanation of the file format as well as links to some libraries.

Good Luck,
ya Storm
Hi Fruny! :-)

I can't really figure out your code :-) I'm using C++ as a language.

Fruny is it possible you can make //comment on the command lines and what they do and why? :-) would help me alot! :-D

btw. Thanks for the help :-D
Quote:Original post by Anonymous Poster
Hi Fruny! :-)

I can't really figure out your code :-) I'm using C++ as a language.

Fruny is it possible you can make //comment on the command lines and what they do and why? :-) would help me alot! :-D

btw. Thanks for the help :-D


Uh oh! Sounds like somebody needs to read up on his/her C++. You should at least know what the things are (ie, namespaces, typenames etc); no one expects you to know what they do on first glance, but you should know what they are. Fruny is using the C++ language, in fact, he's using it so well, he's confused you.

Adding support for the // token isn't particularly hard, but it will require more of the same code, so you have to ask yourself, "Do I ask for this code and use it, without knowing what it does or how it works, or do I learn these (very very useful) structures and functions for myself?"

I advise the latter, if only because people aren't going to be holding your hand for your whole life, and whilst they may help you with logic problems, no one's going to code it for you, they'll leave that (and rightly so) up to you! [grin]

There's currently a C++ workshop happening, and there should be a link up the top of these forums. I advise to check it out, it'll go some way to explain what Fruny's coded.
[ search: google ][ programming: msdn | boost | opengl ][ languages: nihongo ]

This topic is closed to new replies.

Advertisement