Randomized an array for a deck of cards

Forum Home Forum Home > Construct 2 General > How do I....?
 Post Reply Post Reply Page  123 4>
Author
2,962 Rep
Post Options Post Options   Quote Maxum Quote  Post ReplyReply Direct Link To This Post Topic: Randomized an array for a deck of cards
    Posted: 03 Nov 2011 at 5:36am
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
Back to Top
19,045 Rep
Post Options Post Options   Quote sqiddster Quote  Post ReplyReply Direct Link To This Post Posted: 03 Nov 2011 at 6:42am
It seems you certainly know what you are doing... Achieving that all with 33 events is an achievement!
Back to Top
5,295 Rep
Post Options Post Options   Quote Pode Quote  Post ReplyReply Direct Link To This Post Posted: 03 Nov 2011 at 9:57am
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).
Back to Top
3,173 Rep
Post Options Post Options   Quote vidi Quote  Post ReplyReply Direct Link To This Post Posted: 05 Nov 2011 at 10:58am
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.
Back to Top
11,752 Rep
Post Options Post Options   Quote Yann Quote  Post ReplyReply Direct Link To This Post Posted: 05 Nov 2011 at 1:23pm
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 :
http://dl.dropbox.com/u/23551572/C2/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.

Edited by Yann - 05 Nov 2011 at 1:24pm
Back to Top
16,470 Rep
Post Options Post Options   Quote newt Quote  Post ReplyReply Direct Link To This Post Posted: 05 Nov 2011 at 1:54pm
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
Back to Top
2,772 Rep
Post Options Post Options   Quote Joe7 Quote  Post ReplyReply Direct Link To This Post Posted: 05 Nov 2011 at 2:25pm
Originally posted by vidi vidi wrote:

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.

Have you looked at the example?

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

Joe7
Back to Top
3,173 Rep
Post Options Post Options   Quote vidi Quote  Post ReplyReply Direct Link To This Post Posted: 05 Nov 2011 at 3:03pm
Thank you Joe7 It looks like I was looking for.
Can you tell me wich plugin I need? I can not open this exemple.
Back to Top
2,962 Rep
Post Options Post Options   Quote Maxum Quote  Post ReplyReply Direct Link To This Post Posted: 05 Nov 2011 at 5:43pm
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.
Back to Top
2,962 Rep
Post Options Post Options   Quote Maxum Quote  Post ReplyReply Direct Link To This Post Posted: 05 Nov 2011 at 5:58pm
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
Back to Top
 Post Reply Post Reply Page  123 4>

Forum Jump Forum Permissions View Drop Down