The Scenario:
********************
A user made Deck.txt file that contains a list with the names of creatures (cardName),
those names are the same as the corresponding sprites (cardName.png).
The aim is to read the list, get the # of entries contained in the list and
create an array with a size equal to that total (cardDeck),
where each entry has an unique ID. (cardID)
The Questions:
********************
1]Should the cardDeck be done using an Array or Vectors?
-Comments: I thought first of an array because then I could use a randomPick function to select a random entry of the players cardDeck array, remove that entry and add it to cardHand array (showing the new card on the players hand).
2]Is it possible to create a generic blank object called card and @ runtime set the card to have the correct image (depending on its cardID -which calls its-> cardName and then uses it to load the sprite with "cardName" + ".png")?
-Comments: There are lots of different cardNames so that means a generic / template method is needed so the game doesnt need to carry all the cardInfo (names & sprites) and the users synchronize their previously made decks (with an external assistant) obtaining their opponents cardInfo throught network and stored in a temp dir before the game begins and is removed when it ends. (multiplayer thoughts)
Thats it for now...
Thanks in advanced
:]
Comments
[hide]
[/hide]
It gives you access to serialization (both read & write) and can handle lists (as well other features which are less important here).
That's really up to you, depending on your tastes.
An array would be slightly more optimal (though it shouldn't have any impact here) but will require you to compress manually the remaining cards when picking one from the middle.
Yes, it's possible. However I don't think that's the easiest method to handle your situation, but I'd need more details about how you'd write your logic to give you an alternate solution, more in the orx-spirit of doing things.
How many unique cards are we talking about?
Anyway, you can define a config "template" and use it as needed.
First thing, if you're not using Scroll, I'd recommend having a look at that post and all the links mentioned in it.
I'd then define a card config "template", something like:
Then you can store any deck as a list of card:
Where the card templates are the unique names (Nightmare, Goblin, Swamp, ...).
This way you can easily load a deck from config to memory by using orxConfig_GetListCounter()/orxConfig_GetListString().
Then when you want to write it back (either for network or savegame), you can simply do it with orxConfig_SetListString().
Lastly, you ask for disk serialization (orxConfig_Save(), with optional encryption), and this file can either be a savegame or sent over the network.
When creating a card, simply call orxObject_CreateFromConfig (or, if you use Scroll, Scroll::CreateObject()).
When it's loaded you can then retrieve all the attributes you need from its config section (Type, AP, ...). Then again Scroll makes it easier as you can bind a C++ class to a config section and initialize everything from within the virtual method OnCreate().
Lemme know if you have any other questions or if part of what I wrote are not very clear.
Cheers!
The template style you mention would be really tedious, having to create the 2500+ cards in code manually.
I will be using a bi-dimensional array
One that stores the deck, after reading the deck.txt
so the cardID (array position) points to the Array of strings loaded from the .txt (hope im explaining myself clearly)
Im developing a Sandbox so the user creates a Deck using an already existing external asistant software and stores the output deck.txt and pics of the cards inside a directory
of the sandbox. Thats why I spoke about a synchro. betweeen users sending each other that data, so the the player can see opponent cards that he didnt originally store.
I could save a variable inside the second array, that determines if that card has already been picked out of the Deck (variable given for example) and when the card is given out to the hand, it sets to 1 so next time the user picks a card the PickRandomCard will ignore that entry.
get the "cardName" and stick a ".png"
The thing is I dont know the ORX approach...
Thats why I spoke about a template-item CARD(like the black card in the picture) so it has a variable sprite, loaded depending on an array entry thats looked up based on the cardID -> cardName.
I'll post my answer tomorrow night, sorry for the delay.