Randomized an array for a deck of cards

0 favourites
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • You have two things involved that are close to each other but quite differente in application.

    On one side you have the Array with all the card shuffled or not

    On the other side you have the number (from 0 to 51) from which you can guess the value and color (see my last post for that)

    Basically, you can really do anything that you want with this system.

    The cards will always keep the same order in the deck, so you will always find out witch card has been drawn and where (in the deck).

    If you have some game that involve putting back card in the deck you will just have to move values inside the Array

    If you have some game that involve other deck, just use another array

    However, if you want to know if you have pairs, flush, straight, three of a kind... that kind of stuff, it will me more tricky

    I guess you could start by loading each hands on a two dimensionnal array (set value at(hand,index) to cardValue) and compare each member to count similarities (how many cards have the same value or color) or sequences (what is the biggest sequence and what is it?)

    Well... dunno it's getting complicated and I don't even know if I'm in the scope of your question...

  • Thanks Yann, you answer confirm that this is not the way to go for me.

    What I want is to be able to click on a card, retrieve it's value/suit, then destroy it or drag it across the screen.

    The array method gives me the value with a mathematical "trick" but doesn't get me the spawned object id.

    Now I just started in construct, so I'm not really sure if it's even possible to have an event like:

    onclick spawned_object_10 do something..

    As I see it he only way would be to load each card as a different object and then using a randomized array spawning them on the screen, keeping each of them indipendent.

  • For me to have a usefull opinion on your question, I need to know more precisely how your game would be played.

    'cause maybe there's some easier ways to do, not what you say here, but what you want to achieve.

    Without telling me the end result I can't really guess if you take an easy or a hard path... a wrong or a good one.

    Here it's as if I look at your game too closely.

  • Hi 0plus1,

    if you check out the card object it has CardSuite and FaceValue for each card as it dealed out. So it has every thing you need.

  • Maxum Thanks, I understand now, I didn't knew construct kept track of the instanced object, it's incredible how easy it is, I'm a programmer (applications, not games) so I'm accustomed to another way of thinking, incredible.. as soon as I finish my game I'll be sure to show it you.

    Yann I'm re-doing the classic solitaire (the one included in windows) to learn construct

  • Oh yeah, so as in Maxum's example, the dealt card have it's value and color more or less embedded in the number of the animation frame he is on, you will have no problem to know which card you have on the board.

    You will just have to compare the value and color of the card you drag and the card that you will overlap.

    Easy Peasy.

  • The shuffle is incomplete... note the King of Spades

  • Hi there. I see that this forum and postings are a little old but im thinking the information is still useful. I have downloaded and tried to open the capx examples but they are not opening in the newest version of C2. The below is the error I get when trying to load any of the examples within this post.

    ---------------------------

    Error loading project

    ---------------------------

    Failed to open project '\\?\C:\Users\Owner\AppData\Local\Temp\cap29HGH1\Scramble Cards.caproj':

    object type uses unknown plugin ID

    Under element: c2project \ object-folder \ object-type

    Line 111, column 9

    The file may be invalid. Try checking the file in a text editor (projects are saved in XML format).

    ---------------------------

    ---------------------------

    Are there any updated examples I can use or maybe is there something I am doing wrong?

    Thanks for any help on this.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • ^^ Did you ever figure this out? I'm having the same problem with another example project.

  • jlouter: the error means the capx needs a specific (custom) plugin to be opened.

    Apparently those examples were made before Ashley implements dialogs that gives the name of the missing plugin(s).

    On the first page of this thread you can see this post that links to the required plugin.

  • jlouter: the error means the capx needs a specific (custom) plugin to be opened.

    Apparently those examples were made before Ashley implements dialogs that gives the name of the missing plugin(s).

    On the first page of this thread you can see this post that links to the required plugin.

    I downloaded the plugin that was listed in that post, and still had an issue with trying to open the capx like jlouter mentioned.

    I also have an alternative shuffle in case anyone would like it:

    <img src="http://i91.photobucket.com/albums/k286/seridras/DealDraw.png" border="0">

    This should address the issue mentioned above for incomplete shuffling.

  • Hi Everybody! I am working on a card game and this project was a great place to start. I need to make one change and so far I was not able to find a solution. The project posted in this discussion deals the cards in a row. I need to assign a position to each new card... How can I change the events so that I can each new card where to go...

    Thanks so much!

  • Hi jolibidi

    The creating a memory match game tutorial shows some way to have more control about the cards layout.

    Would it help you in solving your issue ?

  • Hi Kyatric! The tutorial is great. I was able to make changes so that I can assign the card position after I click on it. I've been trying to make one other change but I think it's way too complicated.. I'm trying to spread the cards in a sort of a fan, (each card cover the one before it with a bit of a offset or padding on the left) instead of placing in a tableau. Any suggestion how to go about it?

  • loop from 0 to the total number of cards-1. use the loopindex +/- any offset you want to position each card as you loop thru

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)