This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-03-04 13:35:51

infinitum3d
Scratcher
Registered: 2009-05-10
Posts: 100+

Basic SCRATCH programming format/flowchart? (Card Game)

So basically, what is 'proper' format for a Scratch Program? (I know, I know, whatever works, right?) But there must be some basic standard that works well, and can be used as a template or guideline for a simple program.

For example:

When Flag clicked: (this script may be needed in several/all sprites and possibly the stage)
.set all default variables to zero (or possibly one(1) for true/false booleans)
.set default starting position of all sprites (and graphic for background, as needed)


For a simple "Cut the deck" card game, where its a player versus the computer, a simple random number generator works well.

Create a sprite named Deck
create a variable named SelectRndCard

When 'Deck' clicked
set [SelectRndCard] to (pick random (1) to (13))
if <(selectRndCard)=1>
.switch to costume [card1]
else
.if <(selectRndCard)=2>
..switch to costume [card2]
.else
..if <(selectRndCard)=3>
...switch to costume [card3]
..else

This gets very large if there were 52 cards to choose from. Can ARRAYS be used in SCRATCH?

Could BROADCAST be used? for example
if <(selectRndCard)=1>
broadcast [card1wasSelected]
else if <(selectRndCard)=2>
broadcast [card2wasSelected]
else if...

OK, that gets really big, too. I know I'm kinda rambling on incoherently, just thinking out loud...

So, any ideas on a standardized format for programming a simple card game? I have a working 'Cut the Deck' program with just 5 random numbers, and player vs AI, but its pretty big already, with just 5 cards... So I'm open to any suggestions.

Thanks!

~Tony

Offline

 

#2 2010-03-04 13:41:33

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Basic SCRATCH programming format/flowchart? (Card Game)

There is no "proper" format. Most people have different methods, although generally programming sorta goes like this:

[Starting, reset variables to original values]-->[run beginning script]-->[run project]
(not very specific, is it?)
There is no real proper format because scratch can do a lot of things. A platforming game and a graphing project would have different beginnings...

And scratch does have arrays in lists and the item (something) of block...


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#3 2010-03-04 13:47:32

BWOG
Scratcher
Registered: 2008-09-19
Posts: 1000+

Re: Basic SCRATCH programming format/flowchart? (Card Game)

For your deck script, you can do

Switch to costume (SelectRndCard)

Offline

 

#4 2010-03-04 14:10:18

infinitum3d
Scratcher
Registered: 2009-05-10
Posts: 100+

Re: Basic SCRATCH programming format/flowchart? (Card Game)

Wow, you guys are fast! Thanks for the quick reply.

BWOG, I don't understand how switch to costume (SelectRndCard) would work. The variable is just a number, correct? Not the name of a costume...

I'll play with it and see what happens.

Thanks again!

Update:

OK, since I'm working on a card game, and card games are usually 'turn-based', not 'real-time', would it be recommended to have a button of some sort that ends the player turn and calls the AI turn? I guess I could add it into the scripts, something like Broadcast EndPlayerTurn, and then at the end of the AI turn, have it broadcast EndAiTurn...

Again, just thinking out loud... Hopefully this will help others who may be working on card games.

Last edited by infinitum3d (2010-03-04 14:13:50)

Offline

 

#5 2010-03-04 14:13:48

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Basic SCRATCH programming format/flowchart? (Card Game)

infinitum3d wrote:

Wow, you guys are fast! Thanks for the quick reply.

BWOG, I don't understand how switch to costume (SelectRndCard) would work. The variable is just a number, correct? Not the name of a costume...

I'll play with it and see what happens.

Thanks again!

When you make that script, the costume NUMBER and not the name is used.


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#6 2010-03-04 14:17:39

infinitum3d
Scratcher
Registered: 2009-05-10
Posts: 100+

Re: Basic SCRATCH programming format/flowchart? (Card Game)

Thanks guys! I see now how the costume number correlates with the SelectRndCard. As long as I have my Costume number match the random number variable, it works great!

Thats going to save me a lot of time!

Offline

 

Board footer