Looking for the right direction

edited September 2013 in Help request
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

  • edited September 2013
    Concept Sketch
    [hide]130929060503647906.png
    130929060655889665.png
    [/hide]
  • edited September 2013
    Maxx wrote:
    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)
    I'd suggest using the config system right away.
    It gives you access to serialization (both read & write) and can handle lists (as well other features which are less important here).
    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).
    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.
    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")?
    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.
    -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)
    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:
    [CardTemplate]
    Name = CardName
    Graphic = CardGraphic
    Type = Fire
    Property = Attack # Buff # Permanent
    AP = 10 ; Attack points
    BuffType = Defense
    BuffValue = 2
    ...
    

    Then you can store any deck as a list of card:
    [MyDeck]
    CardList = CardTemplate1 # CardTemplate45 # CardTemplate1
    

    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!
  • edited September 2013
    If you really need a per card unique ID, simply add an indirection level:
    [UniqueCard1]
    Type = Nightmare; One of the template mentioned above
    
    [UniqueCard12783645]
    Type = Swamp
    
    [Deck]
    CardList = UniqueCard1 # UniqueCard128861 # ...
    
  • edited September 2013
    First of all, thanks for your time... :]

    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
    Example of deck.txt:
    Nightmare | 7ED   <- This would also be an array
    The cardID is set by the slot# in array first entry id = 1
    

    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.
  • edited September 2013
    Im concerned because I havent thought yet how the logic of loadCardImage would work, maybe something like by looking up the (Cards Deck Array) cardID -> (Card specific info array) cardName
    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.
  • edited October 2013
    I don't have computer access at the moment and typing an answer on my phone would be too tedious.
    I'll post my answer tomorrow night, sorry for the delay.
  • edited October 2013
    Maxx wrote:
    First of all, thanks for your time... :]

    The template style you mention would be really tedious, having to create the 2500+ cards in code manually.

    My pleasure, happy to help if I can. :)

    I'm not entirely sure we're speaking of the same thing.
    Those 2500 cards, are they unique (such as Goblin and Swamp are 2 of them, but Goblin1 & Goblin2 are still a Goblin?).
    You'll have to author them in some fashion, unless it's already done. What I'm proposing is to store them via the config system, which does not mean they have to be manually authored.

    When I describe an example of template, those don't have to be typed manually and can be filled programmatically via the orxConfig API.
    I will be using a bi-dimensional array
    One that stores the deck, after reading the deck.txt
    Example of deck.txt:
    Nightmare | 7ED   <- This would also be an array
    The cardID is set by the slot# in array first entry id = 1
    

    so the cardID (array position) points to the Array of strings loaded from the .txt (hope im explaining myself clearly)

    That's fine again, however I'm not sure what those strings are. What does a card refers to, ie. what does that array of strings represent exactly?
    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.

    That answers part of my initial question. If you already have storage and serialization there's probably very little incentive to use the config system for that purpose. :)
    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.

    What would be the advantage over removing it from the originating deck? To me it sounds it only makes it harder to handle the random picking.
    Im concerned because I havent thought yet how the logic of loadCardImage would work, maybe something like by looking up the (Cards Deck Array) cardID -> (Card specific info array) cardName
    get the "cardName" and stick a ".png"

    That actually isn't really a problem at all. You could do a simple extension appending as you suggest, or just store the ID of the graphic to use, per card. I'm not sure what your already existing tool generate, but based on that you can do whatever you want.

    Regarding orx, you can create the texture yourself and plug it to the object, but it's more hassle than simply doing something as simple as (admitting we're using Scroll on top of orx):
    ScrollObject *CreateCard(const orxSTRING _zName)
    {
        orxCHAR zTextureName[256];
    
        orxString_NPrint(zTextureName, 256, "%s.png", _zName);
    
        orxConfig_PushSection(_zName);
    
        orxConfig_SetString("Texture", zTextureName);
    
        orxConfig_PopSection();
    
        return CreateObject(_zName);
    }
    

    And in config:
    [CardTemplate]
    Graphic = @
    Pivot = center
    ...
    
    [[email protected]]
    

    You can even add a resource type that would do this conversion automatically, but it might be a bit overkill.
    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'm sorry if I'm not answering precisely your question, I feel like I'm not grasping all the aspects of it. However using the config system you can have any kind of template, with any number of variables or lookup and have them either authored manually in a file or automatically generated using code.

    As I don't know all the details of your game it's a bit hard to give precise answers. How I see it, if I were to make a card game, I'd have my card database, all stored using the config system (can be serialized from a different format using the orxConfig API if need be) and I'll have config-backed lists for players hands and decks.
Sign In or Register to comment.