Is there a pattern for this?
Why make it so complicated - For the sake of maintenance make it like it looks. A two dimensional array will do fine and since it is static will give you best lookup performance - You then just need a way to go from Name/Type to array index.
Yes, give a try to the Decorator design pattern.
hint: just create a Normal
class with all the stats you need. Then create a Decorator
class for each
row of the matrix: FireDecorator
, SteelDecorator
, that apply the multiplier for attack/defense.
bonus #1: you can build very easily a "Fire Steel Character", dynamically (the intent of the pattern)
bonus #2: when you add another character, say the "Giant", you just add one class, without touching anything else
It's a basic multiple-dispatch problem. Unfortunately, most languages do not support multiple dispatch.
So I would probably use a map of maps. The outer map maps attacks to maps of defenses, which in turn map defenses to scores/effects/whatever.
You could use the Visitor pattern, but that gets cumbersome fast.
In Python, assuming that you aren't using much subclassing (e.g. no subclasses of Ice), you could use a dictionary mapping (attack,defense)
tuples to scores. That would be a rather clean solution and would be supported by a variety of languages (all you need is a Pair class and an ability to represent attack types as objects, either via a class object or something like an enum).