Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ - RPG

Name: Anonymous 2010-10-29 15:44

Lets program a roleplaying game together. Each post must contain either a new function or an edited version of an old function in psudocode. I will start:

int dealDamage(int hp, int damage){
    return hp - damage;
}

Name: Anonymous 2010-10-31 15:04

>>82

struct _weapon {
    const signed char TYPE_MELEE = 0;
    const signed char TYPE_PROJECTILE = 1;
    const signed char TYPE_SPECIAL = 2;
    const signed char DEFAULT_TYPE = -1;
    const int DEFAULT_AMMO = -2;
    const int DEFAULT_DAMAGE = -2147483648;

    unsigned int id = 0;
    int damage = DEFAULT_DAMAGE;
    signed char type = DEFAULT_TYPE;
    int ammo = DEFAULT_AMMO;
} weapon;


This allows you to compare against known default values if necessary. I forget if C has Sepples-esque const or if you shove static in there. Either way, it's an improvement on your code tagless shit.

There are some other things you could do, like using type as an enum or something, but I felt that it wasn't necessary for the purposes here and an enum tends to be a replacement for int. Since you want as little byte storage as possible, char constants are probably better.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List