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

#1 2010-03-03 16:04:51

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

Scratch card game? Selecting/accepting the card?

I'm trying a VERY simple card game. I want scratch to have a deck of cards in the center of the screen, and one spot at the top of the screen for the AI card to be displayed, and one spot at the bottom for MY card to be displayed.


I have a sprite called "Deck" in the center of the screen
I have a sprite called "AI_card" at the top of the screen
I have a sprite called "MY_card" at the bottom of the screen
I have four possible costumes for each sprite;
DRAW (which is on the deck),
Blank (which is the grey button),
1 (a white button with a number 1),
and 2 (a white button with the number 2).


When I click the Deck, I want the costume of Deck to change to either a 1 or a 2. I have this working. I created a variable called 'selectRandomCard'.

Here's my project so far:
<when[ deck ]clicked>
<set{ selectRandomCard }to ( <pick random( 1 )to( 2
If <(selectRandomCard) = [1]>
switchToCostume[card1]
ElseIf <(selectRandomCard)=[2]>
switchToCostume[card2]

This works great. When I click the deck, the deck costume changes to either 1 or 2 randomly. Now, I want to give the player the option of accepting the card that is shown on the deck.

I tried the LOOKS option 'say' combined with the SENSING option '<key [space] pressed>' but it didn't work.

Can anyone direct me to a simple tutorial on 'input/output' commands? Maybe using the SENSING option 'Ask and wait?'

Thanks!

~Tony
ps, sorry, having some trouble with 'Scratch Blocks'.

Last edited by infinitum3d (2010-03-03 16:14:06)

Offline

 

#2 2010-03-03 16:15:57

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: Scratch card game? Selecting/accepting the card?

Make it do this: When the sprite is clicked, it broadcasts something. The broadcast is what happens when you select the card. Don't forget what number the card has - set a variable.

Any questions?


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#3 2010-03-03 17:31:56

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

Re: Scratch card game? Selecting/accepting the card?

I think I understand. Broadcast sends out a message to all the other sprites, letting them know what happened to the 'clicked' sprite, so I would need to do something like....

create a variable called Discarded

When 'Deck' clicked
switch to costume 'whatever'
say "If you want this card click your hand, otherwise click the discard pile"
When 'DiscardPile' clicked
broadcast DISCARDED...

this lets all the scripts react to the 'discarded' variable, right? So I can go back into the 'Deck' script and  use :

When I Receive 'DISCARDED'
etc, etc

I think I can use this. Thanks!!!


UPDATE! I got it working. I use two broadcasts, (playerTurn, and aiTurn) and the variable isPlayerTurn as a boolean:

if isPlayerTurn = 1 then 'do player stuff'
set isPlayerTurn = 0
broadcast [aiTurn]

if isPlayerTurn = 0 then 'do ai stuff'
set isPlayerTurn = 1
broadcast [playerTurn]

It goes kinda like this...
For the AI stuff I have;

When I receive [aiTurn]
if isPlayerTurn = 1
stop script
else 'do ai stuff'
set isPlayerTurn = 1
broadcast [playerTurn]

Thanks guys!

Last edited by infinitum3d (2010-03-04 16:03:33)

Offline

 

#4 2010-03-04 16:40:19

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

Re: Scratch card game? Selecting/accepting the card?

Hey guys. Is there anything wrong with my using this thread as a personal journal to keep track of how I'm progressing?  Again, maybe others will come along and get some good ideas from it.

So my very simple card game is coming along nicely. I have a deck (sprite) in the center screen and a grey box at the top for the AI to place its card, and a grey box at the bottom for MY pile. When I click the 'Deck', the sprite uses MOTION>glide...to... to slide to the right and a short distance toward me, and displays a random number (costume). When I click 'my pile' (sprite), the card glides to the spot, my turn ends, and the ai gets its turn.

On the ai turn, the 'deck' sends a card to the right and partway toward the AI side of the screen. Using the LOOK>thinking option, the ai decides if it wants the card (it always takes it at this stage) then the sprite glides...to... the ai spot. The ai turn ends, and its MY turn again.

Nothing fancy so far, but it works!

Next step, figuring out how to turn this into a game LOL. It could make a very simple Blackjack game, but thats been done already in SCRATCH.

More to come!

~Tony

Last edited by infinitum3d (2010-03-04 16:43:00)

Offline

 

#5 2010-03-05 00:34:08

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: Scratch card game? Selecting/accepting the card?

There's nothing wrong with using this topic, though the topic name isn't right - you could either start a new topic, or report the topic post and ask for the name to be changed.  smile

Good luck on your project!  big_smile


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#6 2010-03-05 11:39:11

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

Re: Scratch card game? Selecting/accepting the card?

http://scratch.mit.edu/projects/infinitum3d/915039

Here's the link to the project so far. It can be used as the template for a basic card game, I guess. I'll update it and continue to post here.

Thanks Jonathan for the comments!

~Tony

Offline

 

Board footer