I have a regulation 52 card deck...I made it one sprite with 52 costumes. How can I deal cards out on the stage? It seems like I have to have all the costumes on the stage at once, which does not make sense.
How can I, for example, deal four cards to four plays(w est, north, east, and south)? South will be the dealer and he will deal one card to west, one to north, one to east, one to south and so on until each player has four cards.
The tutorials don't seem to cover this though I've seen a few card games, but the logic was difficult to follow. All I want to know for now is how to deal 16 cards out on the stage for all to see.
Thanks.
[Name and email removed by mod - please don't share personal info]
Last edited by Harakou (2012-05-20 00:02:38)
Offline
First of all, don't post personal information such as full names or emails...Scratch team doesn't like it for liability reasons and such, plus it's not a good idea in general. If you have 52 sprites this is going to be difficult...better to put all the costumes in one sprite. However, either way you're going to need lists. One list per hand probably, one for shuffling and one for being shuffled.
The list for being shuffled (call it "unshuffled") will simply have either the numbers 1-52 or 1-13 and one of the characters h, d, s, or c. In order to shuffle this into the shuffled deck, use a script like this:
when gf clicked delete [all v] of [shuffled v] delete [all v] of [unshuffled v] set [char v] to [d] set [# v] to (0) repeat (13) change [# v] by (1) add (join((#)|(char))) to [unshuffled v] end set [char v] to [s] set [# v] to (0) repeat (13) change [# v] by (1) add (join((#)|(char))) to [unshuffled v] end set [char v] to [h] set [# v] to (0) repeat (13) change [# v] by (1) add (join((#)|(char))) to [unshuffled v] end set [char v] to [c] set [# v] to (0) repeat (13) change [# v] by (1) add (join((#)|(char))) to [unshuffled v] end repeat (52) set [# v] to (pick random (1) to (length of [unshuffled v])) add (item (#) of [unshuffled v]) to [shuffled v] delete (#) of [unshuffled v] endThis should produce a well-shuffled deck in the list called "shuffled."
Last edited by AtomicBawm3 (2012-05-19 23:11:34)
Offline
AtomicBawm3 wrote:
First of all, don't post personal information such as full names or emails...Scratch team doesn't like it for liability reasons and such, plus it's not a good idea in general. If you have 52 sprites this is going to be difficult...better to put all the costumes in one sprite. However, either way you're going to need lists. One list per hand probably, one for shuffling and one for being shuffled.
The list for being shuffled (call it "unshuffled") will simply have either the numbers 1-52 or 1-13 and one of the characters h, d, s, or c. In order to shuffle this into the shuffled deck, use a script like this:when gf clicked delete [all v] of [shuffled v] delete [all v] of [unshuffled v] set [char v] to [d] set [# v] to (0) repeat (13) change [# v] by (1) add (join(#) (char)) to [unshuffled v] end set [char v] to [s] set [# v] to (0) repeat (13) change [# v] by (1) add (join(#) (char)) to [unshuffled v] end set [char v] to [h] set [# v] to (0) repeat (13) change [# v] by (1) add (join(#) (char)) to [unshuffled v] end set [char v] to [c] set [# v] to (0) repeat (13) change [# v] by (1) add (join(#) (char)) to [unshuffled v] end repeat (52) set [# v] to (pick random (1) to (length of [unshuffled v])) add (item (#) of [unshuffled v]) to [shuffled v] delete (#) of [unshuffled v] endThis should produce a well-shuffled deck in the list called "shuffled."
After you "shuffle" the deck, you can distribute by simply "passing out" the items of your now shuffled lists to the hands of the players.
I just fixed up the "join" block.
For dealing out the cards, you can create a list for each player's hand (north, south, east, west), and then do something like this.
repeat (round((52) / (NumberOfPlayers))) add (item (1 v) of [ShuffledDeck v]) to [WestHand v] delete (1 v) of [ShuffledDeck v] add (item (1 v) of [ShuffledDeck v]) to [NorthHand v] delete (1 v) of [ShuffledDeck v] add (item (1 v) of [ShuffledDeck v]) to [EastHand v] delete (1 v) of [ShuffledDeck v] add (item (1 v) of [ShuffledDeck v]) to [SouthHand v] delete (1 v) of [ShuffledDeck v] endAfter the loop finishes, each player (West, North, East, South) will have a hand of cards. If you only wanted to deal out 5 cards at a time, you could just repeat (4 players) * (5 cards) = 20 times.
Offline
You might want to study the following game source:
http://scratch.mit.edu/projects/BoltBait/2327569
I think you could learn a lot about deck manipulations from looking at the structure of it and the scripts.
EDIT: You might also look at this project http://scratch.mit.edu/projects/BoltBait/662083
Last edited by BoltBait (2012-05-20 00:45:46)
Offline
Got it to work just fine, although I made it 1-52 instead of 1-13s, etc. I was able to put all four hands, the face up table cards, the unshuffled cards and the shuffled cards each in their own lists. These lists display just fine(showing me numbers from 1 to 52, which are the costume numbers of the card deck) so I know all cards dealt are unique with no repetition.
The problem is that my card game requires that at least four cards be face up in the middle of the screen. Each player can match cards by rank and take one card off the table to match with a card in their hand(this is simplified). Each round has four turns, where the player either matches a card on the table or plays any card in his hand face up to the table. When the round is over, another round of four cards is dealt to each player. The table cards stay where they are. The same thing happens for the third and final round.
How do I get the table cards to stay face up in the middle of the screen? It seems that with changeCostume, I can only display one card at a time(I have a cardDeck sprite with 52 costumes). Is there some sort of command where I can just display all table cards(they are already in their own list)?
Thanks.
Offline
If you store the positions you want to go, you can do something like this. Every time you want to re-draw the screen, you execute this script. The lists have to be "parallel," so the card you want to be at item 1 of XPositions, item 1 of YPositions, must be identified by item 1 of Deck.
clear set [i v] to (0) repeat (NumberOfPositions) change [i v] by (1) go to x: (item (i) of [XPositions v]) y: (item (i) of [YPositions v]) switch to costume (item (i) of [Deck v]) stamp
Last edited by amcerbu (2012-05-20 18:23:12)
Offline
help! i am making a card deck and i cant relate the list to the costume number of the cards. i cant find the number of a certain item, if you could tell me how to do that, it would be great! thanks in advance.
Offline