mardi 1 mars 2016

How should one save different method's parameters in a DB?

I have recently started working on a side-project making a "Magic: The Gathering"-style card game with C#, just for my personal development as a programmer.

A card can either be a "Monster" or a "Spell", and I would like to fire certain events whenever a particular scenario happens (for example, a Monster heals another friendly Monster whenever it gets hit; or a Spell deals damage when an enemy Monster is put on the board).

Currently I am storing all my cards in an RDBMS, where I have tables like "Monster" and "MonsterTrigger". The latter holds a MonsterId, TriggerType, and MethodName. When a Monster is loaded, I check whether it has any Trigger effects, and associate the corresponding EventHandler to it, which then calls the method specified in the MethodName column via Reflection.

My question is, how should I save the methods' parameters in the db? Methods can have different number of parameters, different data types, etc. (For example DestroyAllMonsters() vs DrawCards(numOfCards) vs. Heal(monsterId, hp)). My initial thought was to just save the parameters as comma-delimited or something along those lines, but this doesn't seem like good practice. My other idea was to switch over to a NoSQL DB, but I would really like to keep everything on a RDBMS for this project if I can help it.

I would very much like to hear your suggestions. Thanks in advance!





Aucun commentaire:

Enregistrer un commentaire