Page 1 of 1

Card game engine?

Posted: Sun Mar 27, 2011 6:00 pm
by like80ninjas
What would be the best way to store a large amount of "cards" like magic the gathering cards or similar. Each card would have various stats and maybe an effect, and then be sortable into a deck which is randomized for battle.

I was thinking of using a large amount of arrays, but there has to be a way to store the cards data that i'm overlooking, as the ways I have thought of seem terrible.


So basically, I'd like to know the best, or most effective ways to create a card game engine.

Re: Card game engine?

Posted: Sun Mar 27, 2011 6:06 pm
by XianForce
If you're using C++, I'd recommend a map

Re: Card game engine?

Posted: Sun Mar 27, 2011 6:07 pm
by like80ninjas
Ah yes, it'd be C++ with SDL/GL. Forgot to mention that.

Re: Card game engine?

Posted: Sun Mar 27, 2011 6:40 pm
by JesseGuarascia
XianForce wrote:If you're using C++, I'd recommend a map
Going from this, I'd also suggest a deque, as it's most relative to an actual deck of cards. You can push and pop things from the "top" or "bottom" of a deque, as well as access individual cards in the deck.

I'd also LOVE to see the finished product. I'm a huge advocate of card games online, as they can allow for much easier access to new cards, and far better organization. Just Chaotic was stupid as fuck >.>

Re: Card game engine?

Posted: Sun Mar 27, 2011 6:48 pm
by like80ninjas
I'm thinking of using vectors for the deck. I really just want a great way to store the raw card data. Like it's name and stats and what not.

Re: Card game engine?

Posted: Sun Mar 27, 2011 6:51 pm
by JesseGuarascia
A vector, deque, and map are almost completely identical. A map allows for access by a Key (int, string, whatever you want), and a deque is a double sided stack (essentially). Both of these are better alternatives for this sort of thing. I don't see why you're fixated on vectors. Besides, using the alternatives we gave you would be beneficial, as you wouldn't have to write some container methods and cycle through each member of the vector to tell if it's the one you really want.

Re: Card game engine?

Posted: Sun Mar 27, 2011 6:56 pm
by like80ninjas
I know this. I said vector meaning deque.

Re: Card game engine?

Posted: Sun Mar 27, 2011 7:01 pm
by JesseGuarascia
like80ninjas wrote:I know this. I said vector meaning deque.
Oh :lol: my apologies

Re: Card game engine?

Posted: Sun Mar 27, 2011 7:03 pm
by like80ninjas
Like I said, I think I have the whole deck idea down, I just want to know some good ways to store the data of cards.

The data would be static except for negative effects from gameplay, so I'm thinking of making some sort of static card list and copying the data out of it to the actual "cards" used in the game.

Re: Card game engine?

Posted: Sun Mar 27, 2011 7:37 pm
by wtetzner
like80ninjas wrote:Like I said, I think I have the whole deck idea down, I just want to know some good ways to store the data of cards.

The data would be static except for negative effects from gameplay, so I'm thinking of making some sort of static card list and copying the data out of it to the actual "cards" used in the game.
I'd say store the data for each card object in map. Then have a map from card name to card object.
For cards that will then be used in a deck, you can have a collection (vector, stack, etc.) of maps containing the name of the card represented, as well as any changes to the original.

Edit: If every card has the same types of attributes, I would create a card class/struct. If each card has different types of attributes, I'd use a map.

Re: Card game engine?

Posted: Sun Mar 27, 2011 9:39 pm
by dandymcgee
I would use STL map to represent the objects in the engine. You can store all of the card information in a SQL database. This way you can easily query for the cards relevant to the current game then load the data into the map.

Re: Card game engine?

Posted: Mon Mar 28, 2011 2:52 am
by MrDeathNote
dandymcgee wrote:I would use STL map to represent the objects in the engine. You can store all of the card information in a SQL database. This way you can easily query for the cards relevant to the current game then load the data into the map.
If you have a large number of cards and you want the game to be easily expandable then this is porbably a good idea.