- Home /
Creating a card game. Best ways to interpret the various cards?
I'm working on a card game. There are 100 cards to start with and all of them do different things. The cards are design to have a trigger, an action and a target. Right now all the card data is in a database, which the game will load in at start. What is the best way to interpret the various cards? Right now I've created a way to write expressions, like (trigger) ? TRIGGER_TYPE @ TARGET_TYPE, (action) ACTION_TYPE, (target) ? TARGET_TYPE : TARGET_MODIFIER. It's a simple syntax, though tedious to write expressions for each card, I have some ideas for simplification but I'm sitting here getting ready to research on how to read through a string with regex and interpret the cards but I can't help but wonder if there is a better way to approach this task.
Answer by PaulGregory · Nov 26, 2013 at 02:20 PM
You have devised a tedious expression, which you don't yet know how to read. Yes, there is a better way.
You need to convert the human-readable abilities of each card into a series of properties that can be understood by your game. There is no need for you to stuff all the data into a text string and then extract it.
I assume your actual database has the trigger, action and target in separate columns in a table along with columns for the card name, text and art references etc. If not, it should. The game does not need to 'read' a card like a human would, it needs to be aware of its properties. You need to store the properties against the card reference. You then apply the properties to a game object when the card comes into play, along with additional properties such as which player controls it.
Each thing you have may actually be multiple properties - for your card's TARGET_TYPE you probably need an additional property that specifies the quantity of targets it would apply to, and use a spare number like 0 to mean all. And then another property to specify whether this relates to all players, all opponents, the opponent of your choice etc.
It will be worth your while reading a detailed description of a card game that has triggers, actions and targets - such as the official turn steps to Magic: The Gathering - so you can begin to imagine what data you will need and at what points, even for a less complicated game.
Thanks for the response.
I would say this is overall a better way to approach this. It is less tedious, not by much but it helps. Also, it doesn't make sense to extract the data out of the expression string when you can just lay it out on a table. The expressions were pretty nice for readability though, now my table has about 13 extra fields and many of records won't use them. Still, I think you are right, this is a better solution.
Your answer
Follow this Question
Related Questions
Replace() with string and Regex not replacing numbers/integers 2 Answers
How to replace a word inside a string with different white space combos? 0 Answers
Quick SQLite question for Unity Game Database 1 Answer
Get the upper Chars out of a string 1 Answer
How do I connect to an Oracle Database? 6 Answers