Randomized an array for a deck of cards Forum Home > Construct 2 General > How do I....? |
Post Reply
|
Page 123 4> |
| Author | |
Post Options
Quote Reply
Topic: Randomized an array for a deck of cardsPosted: 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 |
|
![]() |
|
Post Options
Quote Reply
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!
|
|
![]() |
|
Post Options
Quote Reply
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).
|
|
![]() |
|
Post Options
Quote Reply
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.
|
|
![]() |
|
Post Options
Quote Reply
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 |
|
![]() |
|
Post Options
Quote Reply
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 |
|
![]() |
|
Post Options
Quote Reply
Posted: 05 Nov 2011 at 2:25pm |
|
Have you looked at the example? Example Card shuffle it' not very short and tricky but should explain how to use the plugin. Joe7 |
|
![]() |
|
Post Options
Quote Reply
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. |
|
![]() |
|
Post Options
Quote Reply
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. |
|
![]() |
|
Post Options
Quote Reply
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 |
|
![]() |
|
Post Reply
|
Page 123 4> |
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |