Card game engine?

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

Card game engine?

Post 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.
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: Card game engine?

Post by XianForce »

If you're using C++, I'd recommend a map
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

Re: Card game engine?

Post by like80ninjas »

Ah yes, it'd be C++ with SDL/GL. Forgot to mention that.
JesseGuarascia
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 70
Joined: Mon Dec 13, 2010 10:55 pm

Re: Card game engine?

Post 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 >.>
-- Jesse Guarascia

I like C/++, SDL, SFML, OpenGL and Lua. If you don't like those, then gtfo my sig pl0x (jk trollololololol)
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

Re: Card game engine?

Post 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.
JesseGuarascia
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 70
Joined: Mon Dec 13, 2010 10:55 pm

Re: Card game engine?

Post 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.
-- Jesse Guarascia

I like C/++, SDL, SFML, OpenGL and Lua. If you don't like those, then gtfo my sig pl0x (jk trollololololol)
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

Re: Card game engine?

Post by like80ninjas »

I know this. I said vector meaning deque.
JesseGuarascia
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 70
Joined: Mon Dec 13, 2010 10:55 pm

Re: Card game engine?

Post by JesseGuarascia »

like80ninjas wrote:I know this. I said vector meaning deque.
Oh :lol: my apologies
-- Jesse Guarascia

I like C/++, SDL, SFML, OpenGL and Lua. If you don't like those, then gtfo my sig pl0x (jk trollololololol)
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

Re: Card game engine?

Post 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.
User avatar
wtetzner
Chaos Rift Regular
Chaos Rift Regular
Posts: 159
Joined: Wed Feb 18, 2009 6:43 pm
Current Project: waterbear, GBA game + editor
Favorite Gaming Platforms: Game Boy Advance
Programming Language of Choice: OCaml
Location: TX
Contact:

Re: Card game engine?

Post 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.
The novice realizes that the difference between code and data is trivial. The expert realizes that all code is data. And the true master realizes that all data is code.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Card game engine?

Post 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.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
MrDeathNote
ES Beta Backer
ES Beta Backer
Posts: 594
Joined: Sun Oct 11, 2009 9:57 am
Current Project: cocos2d-x project
Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
Programming Language of Choice: C/++
Location: Belfast, Ireland
Contact:

Re: Card game engine?

Post 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.
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
Post Reply