an excellent project! Instead of creating a different sprite for each of the 52 cards you could also create just a single sprite with 52 costumes, and when shuffling assign a random costume to it (the 'switch to costume ___' block also takes numbers, variables and even the 'pick random from 1 to 52' block as an argument). Then you could 'stamp' the sprite in the location you want it to appear (say the top row) and keep track of the drawn cards in five global integer variables, preventing them from being drawn again.
Download this project!
Download the 53 sprites and 54 scripts of "Deck Shuffler" and open it in Scratch
Project Notes
The program I created is a simple deck shuffler. It has all 52 cards and randomly chooses 5 of them in sequence.
1. I spent roughly 4 hours learning to use scratch and creating this program. 2. I based the program on the poker idea we were talking about in class. If we're to build a poker program, we'll first need to shuffle. 3. I programmed very elementary C in high school. 4. I did enjoy using scratch. The visual sprites made the program quite easy to use, and the functions provided were useful as well.
My one gripe is the apparent impossibility of creating and caling custom functions. Instead of creating one shuffle function to be called on by each card, I had to copy paste the code to all 52 individual cards. This was very frustrating. 5. I learned that a GUI programming tool actually has the potential to work! This could be great stuff for younger learners. 6. I have to admit it - there is a bug in my program. Two, actually. First, I forgot to "withdraw" cards from the deck once they were on the board. The randomization part does a static 1-52, and there is the possibility of a card drawn twice. This needs to be corrected.
Second, for some reason I can't quite figure out, Scratch sometimes leaves old cards on the screen. I suspect this is a memory issue with my machine. The vestigal cards do not affect the shuffling once it has begun.
Comments
You need to be logged in to post comments
Add a Comment
an excellent project! Instead of creating a different sprite for each of the 52 cards you could also create just a single sprite with 52 costumes, and when shuffling assign a random costume to it (the 'switch to costume ___' block also takes numbers, variables and even the 'pick random from 1 to 52' block as an argument). Then you could 'stamp' the sprite in the location you want it to appear (say the top row) and keep track of the drawn cards in five global integer variables, preventing them from being drawn again.