Randomized an array for a deck of cards

Get help using Construct 2

Post » Thu Nov 03, 2011 5:36 am

Im playing a round with a card game project. I have the basic functions down, making the deck, shuffling the deck and dealing the cards out. If you could take a look at my capx and let me know if there is a better way to randomized the array for the deck. Or if you have any other tips or tricks for the rest of my code I would like to see it. As I am just learning Construct 2.

http://dl.dropbox.com/u/1244375/CardGame2.capx

Updated 1/25/2014 -----------------------------------------------------

Hello all,
I been away for a long time.
I have updated this card game demo to fix the shuffle and I took out the plugin Moveto so it will run off stock Construct2.

Here is the updated file:
https://dl.dropboxusercontent.com/u/124 ... 2014-01-25 19:09:35

I know it's been a long time but I have made some more updates to this demo. Updated 6/29/2016
https://www.dropbox.com/s/6x3rl4dsnweterp/CardGame12.capx?dl=0
Last edited by Maxum on Wed Jun 29, 2016 8:59 pm, edited 1 time in total.
B
15
S
10
G
8
Posts: 107
Reputation: 4,944

Post » Thu Nov 03, 2011 6:42 am

It seems you certainly know what you are doing... Achieving that all with 33 events is an achievement!
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Thu Nov 03, 2011 9:57 am

It's pretty nice. I don't thnik you can squeeze a lot more of improvements, but if you want, you can use the Randomized Array to do the shuffling automatically on start. (That's what I used in my Fifteen game sample).
B
33
S
9
G
6
Posts: 709
Reputation: 6,704

Post » Sat Nov 05, 2011 10:58 am

you can use the Randomized Array to do the shuffling automatically on start


Is there a tutorial that explains step by step how to use this array object?

I have tries to self explore but without sucess.
B
21
S
5
G
5
Posts: 163
Reputation: 5,028

Post » Sat Nov 05, 2011 1:23 pm

Maxum, your way to shuffle is awesome. I never thought of something like that to permutate stuff around the first index from loop to loop is great.

I would have done something like keeping a string of 52 tokens and just pick randomly each token, fill the Array and delete them, until there's no token to pick.
But your way is far better.

The rest of the code is a bit heavy though, so let me show you how to simplify :
shuffleCard.capx
in just 14 events

vidi I don't know if there's a tuto, but in short you can set value to indexes like X or X,Y or X,Y,Z
Array is just a data container. Test some stuff and come back with question if you don't understand what's going on.Yann2011-11-05 13:24:37
Last edited by Yann on Sun Sep 14, 2014 10:30 am, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sat Nov 05, 2011 1:54 pm

You know if C2 had a z-index, and a for each ordered, you wouldn't need the array at all. The cards themselves could be the array. To shuffle all you would have to do is:

For each card set z-index to random(52)
Then you could even un-shuffle them:

For each card (ordered by instance variable book)
-> For each card (ordered by instance variable number)
--> card set z index to loopindex

Easy peasy
Image Image
B
161
S
48
G
91
Posts: 7,359
Reputation: 67,273

Post » Sat Nov 05, 2011 2:25 pm

[QUOTE=vidi] you can use the Randomized Array to do the shuffling automatically on start


Is there a tutorial that explains step by step how to use this array object?

I have tries to self explore but without sucess.
[/QUOTE]
Have you looked at the example?

Example Card shuffle
it' not very short and tricky but should explain how to use the plugin.

Joe7
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Sat Nov 05, 2011 3:03 pm

Thank you Joe7 It looks like I was looking for.
Can you tell me wich plugin I need? I can not open this exemple.
B
21
S
5
G
5
Posts: 163
Reputation: 5,028

Post » Sat Nov 05, 2011 5:43 pm

Thanks Yann for checking out my project and showing me how to simplify it. I have to say your way is more elegant and efficient.

I have made a few more changes.I am now using   rexrainbow Behavior plugin -- MoveTo it lets you move the sprite to the target position straight from current position.

Here is the new capx Card Game Update
And if you do not want to install the plugin you can see it here Card Game

Thanks agian Yann and the others that took the time to check out my project. If any one else has any more pointers I like the hear them as I am trying to learn the best way to use Construct 2.
B
15
S
10
G
8
Posts: 107
Reputation: 4,944

Post » Sat Nov 05, 2011 5:58 pm

Right now I am trying to figure out the best way to enter in the card face value into my array system. I am thinking about using a three dimensional array. X would be the card deck number. Y would be the card face value. Z would be the ace check / alternate face value.

I am trying to figure out the best way to code this. I would love to see your ideas on this.

Thanks
B
15
S
10
G
8
Posts: 107
Reputation: 4,944

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 24 guests