Data structures question for card game

0 favourites
  • 3 posts
From the Asset Store
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • Hi! I'm trying to make a solitaire card game. I'm not really sure what sort of data structure(s) I should be using in Construct to manage the state of the card stacks. Each of the cards has an instance variable with an ID, which is all I really need to store in the data structure, and I could work everything else out from that.

    In this game, there are five columns of stacks. One or more of the columns could be empty at any particular time. Each of the columns can have multiple stacks. I.e. in the included image, [13,56,23] is one stack and [38,57] is a second stack in the same column. There could be any number of these stacks (well, technically up to 30 or so, because of other limitations in the game). Any particular stack could contain any number of cards, although I could and probably will insert an artificial constraint limiting this to 20 or so.

    I thought maybe I should be using a multi-dimensional array, but it seems like those are more aimed towards data that doesn't have any empty values in it. How should I be storing the data to be able to push, pop, and query the IDs of cards in the various stacks?

    Tagged:

  • I made a version of spider solitaire a couple years ago, and I used an array to create the deck, shuffle it, then spawned all the cards onto the screen - as each card is created it is assigned instance variables that tell it what the face value is, what suit, whether it is face up or face down, and what column it is in.

    after every move I would calculate if cards are movable or not, and if any complete suits exist.

    I used another array to hold each move, so that moves could be undone.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You may be able to do it without arrays, and in many cases it will make things easier. (it depends on the game of course)

    You have 52 instances of card sprite, you can use instance variables, layers and z-ordering. This gives you enough information about the value, state, location and order of any card. It also allows to easily pick cards, without the need to look them up in the array. For example to draw the top card from the deck:

    Card on layer "deck"
    Card Pick top instance
    	Card move to layer "table"
    	....
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)