a character class for my rpg

This is a discussion on a character class for my rpg within the Other Technologies forums in category; 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 ...

Go Back   Application Development Forum > Other Technologies

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 04-28-2005, 01:51 PM
Kotori
Guest
 
Default a character class for my rpg

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

Reply With Quote
  #2  
Old 04-28-2005, 03:05 PM
jacob@nomail.invalid
Guest
 
Default Re: a character class for my rpg

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.
Reply With Quote
  #3  
Old 04-28-2005, 03:44 PM
David Haley
Guest
 
Default Re: a character class for my rpg

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 a
question 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)
---------------------------
Reply With Quote
  #4  
Old 04-28-2005, 08:39 PM
Peter Ashford
Guest
 
Default Re: a character class for my rpg

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?
Reply With Quote
  #5  
Old 04-28-2005, 08:59 PM
Tim Ford
Guest
 
Default Re: a character class for my rpg

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
Reply With Quote
  #6  
Old 04-28-2005, 10:35 PM
Peter Ashford
Guest
 
Default Re: a character class for my rpg

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?
Reply With Quote
  #7  
Old 04-28-2005, 10:40 PM
Peter Ashford
Guest
 
Default Re: a character class for my rpg

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.
Reply With Quote
  #8  
Old 04-28-2005, 11:18 PM
Tim Ford
Guest
 
Default Re: a character class for my rpg

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
Reply With Quote
  #9  
Old 04-29-2005, 12:16 AM
Erik Max Francis
Guest
 
Default Re: a character class for my rpg

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
Reply With Quote
  #10  
Old 04-29-2005, 12:17 AM
Erik Max Francis
Guest
 
Default Re: a character class for my rpg

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
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 12:25 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.