Sunday, August 7, 2011

Enums, Classes

I think I posted earlier about the problem I was having where if I make each monster and object it's own class that I then have to create a separate list of all of them since the code in several places will refer to objects as groups with index numbers.  So, from MONNUM to MONNUM.  I didn't want to maintain a separate list of objects, since without reflection it's very hard to associate something with an actual class.  I opted instead for using an Enum, but that has the problems that not only do all the definitions have to be in one huge file, but for each type that has a slightly different constructor, I'm overloading it using another dummy class so that I can foo(int, int, int), from foo(int, int, int).  I'm still having to put a crapload of data into a constructor that I can't read.  It winds up looking like:


GLAIVE(new Weapon(), 45, "glaive", "single-edged polearm", false, false,
true, 8, 75, 6, 6, 10, 0, EnumSet.of(WeaponType.SLASH),
Skills.POLEARMS, Material.IRON),


RIN_SUSTAIN_ABILITY(new Ring(), 159, "sustain ability",
Property.FIXED_ABIL, "bronze", 100, true, false, 4, Material.COPPER),

etc.

The best part about taking a few months off of coding is coming back and saying "zOMG, how f'ing sleep deprived *WERE* you?"  because when I look at these, I just want to close the laptop again and ignore it for another week.  (This has happened once already)

Oh, and I have to do a new Ring() up there because you can't make an instance variable before the actual Enumerations, and I'm trying really hard to avoid globals so that I can eventually detangle this.  Yuck, 'eh?

My goal this morning was to do something easy to work into webhack again, and I quickly got mired down in this.  I think I'm going to move to something a little more hybrid like.  Namely:

public Enum ObjectName {
  GLAIVE(new Obj.Glaive),
  RIN_SUSTAIN_ABILITY(new Obj.RingSustainAbility)
}

And then just delegate all the calls over.

As my daughter likes to say.  "Yucky!"

0 comments:

Post a Comment