| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hi, i'm relatively new to programming. I've worked with Java for awhile, but i have really seen its limitations when it comes to game programming, so i've started developing on my own. I have done simply stuff already so i decided to move on up the ladder of difficulty. I am posting a copy of a character class that i have recently written. I need it to be flexible enuf to be called relatively frequently in my battle engine. Here it is: #include <string.h> using namespace std; class CHero { public: // Setters void setHeroHp(int m_HeroHp); void setHeroMp(int m_HeroMp); void setHeroAtk(int m_HeroAtk); void setHeroDef(int m_HeroDef); void setHeroLck(int m_HeroLck); void setHeroExp(long m_HeroExp); void setHeroLvl(int m_HeroLvl); void setHeroName(string m_HeroName); void setHeroClass(string m_HeroClass); // Getters int getHeroHp(); int getHeroMp(); int getHeroAtk(); int getHeroDef(); int getHeroLck(); long getHeroExp(); int getHeroLvl(); string getHeroName(); string getHeroClass(); private: // Data Storage int heroHp; int heroMp; int heroAtk; int heroDef; int heroLck; long heroExp; int heroLvl; string heroName; string heroClass; }; // Class Definitions // Setters void CHero::setHeroHp(int m_HeroHp) { heroHp = m_HeroHp; } void CHero::setHeroMp(int m_HeroMp) { heroMp = m_HeroMp; } void CHero::setHeroAtk(int m_HeroAtk) { heroAtk = m_HeroAtk; } void CHero::setHeroDef(int m_HeroDef) { heroDef = m_HeroDef; } void CHero::setHeroLck(int m_HeroLck) { heroLck = m_HeroLck; } void CHero::setHeroExp(int m_HeroExp) { heroExp = m_HeroExp; } void CHero::setHeroLvl(int m_HeroLvl) { heroLvl = m_HeroLvl; } void CHero::setHeroName(string m_HeroName) { heroName = m_HeroName; } void CHero::setHeroClass(string m_HeroClass) { heroClass = m_HeroClass; } // Getters int CHero::getHeroHp() { return heroHp; } int CHero::getHeroMp() { return heroMp; } int CHero::getHeroAtk() { return heroAtk; } int CHero::getHeroDef() { return heroDef; } int CHero::getHeroLck() { return heroLck; } long CHero::getHeroExp() { return heroExp; } int CHero::getHeroLvl() { return heroLvl; } string CHero::getHeroName() { return heroName; } string CHero::getHeroClass() { return heroClass; } If anyone can give me any insight into any improvements i can make towards this code, i'd really appreciate it! Basically what i'm trying to do with this is create a new hero at the beginning of the game, and during the character creation process allow the user to "roll" for the ability scores. But more with random number generators later ![]() btw Thanks In Advance ~ Kotori |
|
#2
| |||
| |||
| Kotori: > class CHero (... snip 110 Lines Of Code ...) > If anyone can give me any insight into any improvements i can make > towards this code, i'd really appreciate it! I would prefer: struct _CHero { int heroHp; int heroMp; int heroAtk; int heroDef; int heroLck; long heroExp; int heroLvl; char *heroName; char *heroClass; }; typedef struct _CHero CHero; -- «I nostri occhi vedono tutto, ma con grande distacco.» Lestat. |
|
#3
| |||
| |||
| This day of Thu, 28 Apr 2005 19:05:33 GMT, jacob@nomail.invalid saw fit to scribe: >Kotori: > >> class CHero >(... snip 110 Lines Of Code ...) > >> If anyone can give me any insight into any improvements i can make >> towards this code, i'd really appreciate it! > >I would prefer: > >struct _CHero { > int heroHp; > int heroMp; > int heroAtk; > int heroDef; > int heroLck; > long heroExp; > int heroLvl; > char *heroName; > char *heroClass; >}; >typedef struct _CHero CHero; Since we're using C++, you can dispense with the clunky typedef syntax. e.g. struct CHero { // not sure how relevant the 'C' is anymore // ... }; You also probably don't need to have 'hero' in front of every data member, since you're already inside the hero class. e.g. struct Hero { int hp; int mp; // ... char * name; char * class; // this one won't compile because 'class' is a keyword in C++ // so perhaps it's a good place to put 'heroClass' }; Personally I would also attach '_' to data members (e.g. int hp_ but that's aquestion of style preference. Some have the _ before, others have m_hp, others have mi_hp, others have miHp, etc... But yes, I agree that if all the class has is a bunch of members with getters and setters for each, you might as well have a struct or keep the class and expose all members as public. (Recall that in C++, structs are classes where everything is and only can be public.) Incidentally you might want to use the STL string class instead of char *. If you're used to Java, that might make your life easier. -- ~david-haley david-usenet@the-haleys.com (no unmunging necessary) --------------------------- |
|
#4
| |||
| |||
| Kotori wrote: > Hi, i'm relatively new to programming. I've worked with Java for > awhile, but i have really seen its limitations when it comes to game > programming Really? What might those limitations be? |
|
#5
| |||
| |||
| Peter Ashford wrote: > Really? What might those limitations be? He wasn't looking for a religious argument, so stop trying to draw one out. God, fanboys of all types are annoying. -Tim |
|
#6
| |||
| |||
| Tim Ford wrote: > Peter Ashford wrote: > >> Really? What might those limitations be? > > > He wasn't looking for a religious argument, so stop trying to draw one > out. God, fanboys of all types are annoying. > > -Tim Who said I was trying to create a religious argument? I wanted to know what limitations the OP was talking about. What's wrong with that? |
|
#7
| |||
| |||
| Tim Ford wrote: > Peter Ashford wrote: > >> Really? What might those limitations be? > > > He wasn't looking for a religious argument, so stop trying to draw one > out. God, fanboys of all types are annoying. > > -Tim ....and by the way - fuck off. How dare you assume that I'm some kind of "fanboy" on the basis of one question? FYI, although I have done some simple games in Java, I work in C++ ATM. Go shove your self-rightous assumptions. |
|
#8
| |||
| |||
| Peter Ashford wrote: > ...and by the way - fuck off. How dare you assume that I'm some kind of > "fanboy" on the basis of one question? FYI, although I have done some > simple games in Java, I work in C++ ATM. Go shove your self-rightous > assumptions. As if your working with C++ has anything to do with your java fanboyness. Are you seriously telling me you weren't waiting for him to list the reasons he doesn't like Java for games so that you could attack each reason to prove it wrong? Be honest ![]() -Tim |
|
#9
| |||
| |||
| David Haley wrote: > Personally I would also attach '_' to data members (e.g. int hp_ but that's a> question of style preference. Some have the _ before, others have m_hp, others > have mi_hp, others have miHp, etc... The prefixed underscore frequently runs afoul of Standard violations, specifically undefined behavior due to using implementation-reserved identifiers. -- Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis If I had another face, do you think I'd wear this one? -- Abraham Lincoln |
|
#10
| |||
| |||
| Tim Ford wrote: > Are you seriously telling me you weren't waiting for him to list the > reasons he doesn't like Java for games so that you could attack each > reason to prove it wrong? Be honest ![]() So what exactly do you think _you're_ trying to do here, chief, if not exactly the same thing? -- Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis If I had another face, do you think I'd wear this one? -- Abraham Lincoln |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.