scratch - rock, paper, scissors

60
Is creating a game on your to-do list? If so, lets it off!

Upload: sara-gibbons

Post on 16-Apr-2017

77 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: Scratch - Rock, Paper, Scissors

Is creating a game on your to-do list?

If so, lets

it off!

Page 2: Scratch - Rock, Paper, Scissors
Page 3: Scratch - Rock, Paper, Scissors
Page 4: Scratch - Rock, Paper, Scissors

SARA GIBBONSSoftware Engineer

@saragibby [email protected] saragibby.com

Page 5: Scratch - Rock, Paper, Scissors

WHAT KIND OF STUFF USES Software

Page 6: Scratch - Rock, Paper, Scissors
Page 7: Scratch - Rock, Paper, Scissors
Page 8: Scratch - Rock, Paper, Scissors
Page 9: Scratch - Rock, Paper, Scissors
Page 10: Scratch - Rock, Paper, Scissors
Page 11: Scratch - Rock, Paper, Scissors
Page 12: Scratch - Rock, Paper, Scissors

As a Software Engineer I get to work on all of this cool stuff!

Page 13: Scratch - Rock, Paper, Scissors

WHAT DOES ASoftware Engineer

DO?

Page 14: Scratch - Rock, Paper, Scissors

Software Engineer = Master Builder

Page 15: Scratch - Rock, Paper, Scissors
Page 16: Scratch - Rock, Paper, Scissors
Page 17: Scratch - Rock, Paper, Scissors
Page 18: Scratch - Rock, Paper, Scissors
Page 19: Scratch - Rock, Paper, Scissors

Master Builder

•Solve problems

•Build cool things

•Use their imagination

All things Software Engineers get to do everyday!

Page 20: Scratch - Rock, Paper, Scissors

Being a Software Engineer…is like being paid to be

creative,solve problems,

build things!

Page 21: Scratch - Rock, Paper, Scissors
Page 22: Scratch - Rock, Paper, Scissors

Go to Scratch homepage: https://scratch.mit.edu/

Click Create to get started

Let’s get started

Page 23: Scratch - Rock, Paper, Scissors

Click sprite icon to add your character

Pick a character

A picture on the stage that a script can move and

change.

spritepick your character

Page 24: Scratch - Rock, Paper, Scissors

After you pick your character it will load next to the Scratch cat. Move it to its own space in the stage.

stage

workspace

give your character some space

Page 25: Scratch - Rock, Paper, Scissors

We are going to add 4 variables to hold choices and scores:

● Cat Choice ● Cat Score ● Your Choice ● Your Score

1. Select Data from Scripts list

2. Press Make Variable button

Works like a container to hold a number, phrase, or other

important stuff used in several places in your code.

variable

2

1

create some variables

Page 26: Scratch - Rock, Paper, Scissors

After you’ve created your variables they will appear in the upper left corner of the stage.

Drag them over to their right character.

put your variables on the screen

Page 27: Scratch - Rock, Paper, Scissors

Now we can start our game!

1. Click on your character

2. Go to the Events scripts

3. Drag to your workspace

This is where your computer game is going to start.1

3

2

start your game

Page 28: Scratch - Rock, Paper, Scissors

1. Go to the Control scripts

2. Drag the repeat until piece below the first piece 3. Now go to the Operators scripts

4. Drag the or test over and snap it to the repeat until piece

The first player to 3 points wins! Let’s use the or test to check for a winner.1

23

4

4

2

repeat until there is a winner

Page 29: Scratch - Rock, Paper, Scissors

1

2

2We need to check if each score is equal to 3. Let’s add the equals checks to each side of the or.

1. Go to the Operators scripts

2. Drag 2 equals piece, one to each side of the or

add checks for each score

Page 30: Scratch - Rock, Paper, Scissors

1

23

32

Now that we have our equals pieces in place let’s fill them in so the check works.

1. Go to the Data scripts

2. Drag Cat Score into a equals piece, and set the value to 3

3. Drag Your Score into a equals piece, and set the value to 3

is there a winner?

Page 31: Scratch - Rock, Paper, Scissors

The first step to the game is to ask your choice, Rock (1), paper (2), or scissors (3)?

1. Go to the Sensing scripts

2. Drag the ask and wait piece into the repeat until piece

3. Go to the Data scripts

4. Drag the set to piece below the ask and wait piece

1

2

3

4

pick rock, paper or scissors

Page 32: Scratch - Rock, Paper, Scissors

One you make your choice we want to save it to the Your Choice variable we created earlier.

1. Go to the Sensing scripts

2. Drag the answer piece into the set to piece

1

2

save your choice

Page 33: Scratch - Rock, Paper, Scissors

Checks to see a condition is true. If it is, then does the stuff

you tell it to. If not true, does nothing.

if statement

Now that we know your choice, let’s check to see if you picked Rock.

1. Go to the Control scripts

2. Drag the if then piece under the set to piece

1

2

check your choice

Page 34: Scratch - Rock, Paper, Scissors

1. Go to the Operators scripts

2. Drag the equals condition piece into the if then piece

We want to first check if you picked Rock. So let’s add a condition to the if then piece.

3. Go to the Data scripts 4. Drag Your Choice into the equals condition and set the other value to 1

1

3

2

4

was your choice rock?

Page 35: Scratch - Rock, Paper, Scissors

If you picked Rock, let’s have your character say “Rock!”

1. Go to the Looks scripts

2. Drag the say for piece inside the if piece

3. Change what you want your character to say to Rock!3

2

1

say rock

Page 36: Scratch - Rock, Paper, Scissors

Now let’s fill in the if check for Paper(2). We can duplicate the check for Rock to get started.

1. Right-click on the if then piece

2. Click duplicate to copy that whole block. It will put it on top of the first one, just drag it down underneath the first if then

3. Change the equals number to 2, and change the say text to Paper!

1 2

3

3

Just means to make a copy of the entire piece

you put together

duplicatedid you pick paper?

Page 37: Scratch - Rock, Paper, Scissors

Let’s fill in the if check for Scissors(3) by doing a duplicate again.

1. Right-click on the if then piece

2. Click duplicate to copy that whole block. It will put it on on top of the first one, just drag it down underneath the first if.

3. Change the equals number to 3, and change the say text to Scissors!

1 2

3

3

did you pick scissors?

Page 38: Scratch - Rock, Paper, Scissors

After you say your pick, time to tell the cat to pick. We can do this by broadcasting a message.

Sends a message out to tell something else to do something. Like when you raise your hand in

class, you are broadcasting to your teacher.

broadcast

1. Go to the Events scripts

2. Drag the broadcast and wait piece under the last if then piece

You can leave it as broadcasting message1.

This is the message we are going to tell the cat to listen for.

1

2

tell the cat to make it’s choice

Page 39: Scratch - Rock, Paper, Scissors

Wake up cat!!! Let’s tell the cat what message to listen for. When that message is broadcast the cat will start up and make it’s pick.

1. Click on the cat character

2. Go to the Events scripts

3. Drag the when I receive piece onto the workspace

4. Make sure it’s set to listen for message1, which is what you are broadcasting after your pick

1

2

3

4

have the cat to be ready to pick

Page 40: Scratch - Rock, Paper, Scissors

3. Go to the Operators scripts

4. Drag the pick random piece into the set to piece

5. Change the numbers to 1 and 3

Now we need to have the cat make a choice. Let’s do this by setting it’s choice to random pick.

1. Go to the Data scripts

2. Drag the set to piece below the when I receive piece

1

2

3

4

5

set cat’s choice

Page 41: Scratch - Rock, Paper, Scissors

Time to check the cat’s choice so we can have it tell us what it picked.

3. Go to the Operators scripts

4. Drag the equals piece into the if then piece

1. Go to the Control scripts

2. Drag the if then piece below the set to piece

1

2

3

4

check the cat’s choice

Page 42: Scratch - Rock, Paper, Scissors

Just like you did for your choice, let’s check first to see if the cat picked Rock.

1. Go to the Data scripts

2. Drag the Cat Choice variable piece into the equals condition

3. Go to the Looks scripts

4. Drag the say for piece into the if then piece

5. Change it to say Rock!

1

2

3

4 5

did the cat pick rock?

2

Page 43: Scratch - Rock, Paper, Scissors

Now let’s fill in the if check for Paper(2). We can duplicate the check for Rock to get started.

1. Right-click on the if then piece

2. Click duplicate to copy that whole block. It will put it on on top of the first one, just drag it down underneath the first if then

3. Change the equals number to 2, and change the say text to Paper!

did the cat pick paper?

1 2

3

3

Page 44: Scratch - Rock, Paper, Scissors

Let’s fill in the if check for Scissors(3) by doing a duplicate again.

1. Right-click on the if then piece

2. Click duplicate to copy that whole block. It will put it on on top of the first one, just drag it down underneath the first if.

3. Change the equals number to 3, and change the say text to Scissors!

did the cat pick scissors?

1 2

3

3

Page 45: Scratch - Rock, Paper, Scissors

Now that you and the cat both made your choices, let’s see who the winner of the round is.

1. Go to the Control scripts

2. Drag an if then piece below the last if then where you checked the cat’s choice

1

2

check for a winner

Page 46: Scratch - Rock, Paper, Scissors

Let’s first check to see if the round was a tie. If you can the cat both picked the same then no one gets a point.

3. Go to the Data scripts

4. Drag Cat Choice and then Your Choice onto the equals operator

5. Drag a change by piece into the if then piece to change Your Score by 0

1. Go to the Operators scripts

2. Drag an equals operator piece onto the if then you just added

1

3

4

5

2

check for a winner… was it a tie?

4

Page 47: Scratch - Rock, Paper, Scissors

To see who won the round we’ll need to check Your Choice to the Cat Choice. Let’s start by seeing if your Paper beat cat’s Rock.

3. Go to the Operators scripts

4. Drag an and piece into your if then

1. Go to the Control scripts

2. Drag an if then piece below the if then that checks for a tie

1

2

3

4

did you beat the cat?

Page 48: Scratch - Rock, Paper, Scissors

Now let’s add the piece to check if Cat Choice was Rock and Your Choice was Paper.

3. Go to the Data scripts

4. Drag Cat Choice into a equals, and set the check value to 1

5. Drag Your Choice into a equals, and set the check value to 2

1. Go to the Operators scripts 2. Drag 2 equals pieces into the and condition

1

2

3

45

45

did you cat rock? and you pick paper?

Page 49: Scratch - Rock, Paper, Scissors

Your Paper beat cat’s Rock, so you earned a point!

Let’s change Your Score by 1.

1. Go to Data scripts

2. Drag a change by piece into the if then that checks if Your Choice of Paper(2) beat Cat Choice of Rock(1)

3. Set the change by piece to change Your Score by 1

1

2

3

you won the round!

Page 50: Scratch - Rock, Paper, Scissors

COMBINATION CATCHOICE

YOURCHOICE CHANGE

1

2

3

1

3

1

2

2

3

3

Your Score

Your Score

Cat Score

Cat Score

Cat Score

For each row in the table….

1. Right-click on the if then piece we just created

2. Click duplicate to copy that whole block

3. Change the values for each choice

4. Update which score needs to get Changed according to the chart

Now to have to repeat this 5 more times to cover all the other choice combinations. You know what this calls for? Duplicate!!

check the rest of the combinations

Page 51: Scratch - Rock, Paper, Scissors

When you are all done here is what it all your checks look like.

check the rest of the combinations

Page 52: Scratch - Rock, Paper, Scissors

1. Go to Data scripts

2. Drag 2 set to pieces under the last if then

3. Have one set Cat Choice and the other set Your Choice

4. Set the to value on each to 0

1

2

3 4

reset choices for next roundNow that the round is over, we figured out if there was a winner, and gave them a point. Let’s set the choice variables back to 0 to play again.

Page 53: Scratch - Rock, Paper, Scissors

Let’s go back to your character and check for game winner. Remember, we told it repeat until someone gets 3 points? Time to check who got 3 points and celebrate!

1. Click on your character

2. Go to the Control scripts

3. Drag an if then else piece below the repeat until

2

1

3

Like an if then but this will do something when not true.

If it is, then does the stuff you tell it If not true, goes to else to do the

other stuff

if then elseand the winner is?

Page 54: Scratch - Rock, Paper, Scissors

To check for a winner let’s see if Cat Score is greater than Your Score.

3. Go to the Data scripts

4. Drag Cat Score to the first side of the greater than

5. Drag Your Score to the second value in the greater than

1. Go to the Operators scripts 2. Drag a greater than piece into the if then

1 3

4 5

2

did the cat win?

Page 55: Scratch - Rock, Paper, Scissors

Time to broadcast a another message to the cat. This time will use a new message, so it triggers a different action from the cat.

1. Go to the Events scripts

2. Drag a broadcast piece into the if

3. From the message drop down select new message

4. Name the message message2 and click OK

You’ll then see message2 in your broadcast piece.

1

2

3

4

tell the cat it won

Page 56: Scratch - Rock, Paper, Scissors

If we know the cat didn’t when, then you know you are the winner!

Time to announce You Win!

2

1

3

you win!

1. Go to the Looks scripts

2. Drag the say piece into the else section of the if then else piece

3. Change the say text to You Win!

Page 57: Scratch - Rock, Paper, Scissors

Now let’s tell the cat it needs to listen for message2. Then when it gets that message it should say Cat Win!

1. Click on the cat character

2. Go to the Events scripts

3. Drag the when I receive piece onto the cat’s workspace

4. Select message2 from the when I receive dropdown

1

2

3

4

have the listening for the win

Page 58: Scratch - Rock, Paper, Scissors

The cat won. Let’s let him tell everyone Cat Wins!

1. Go to the Looks scripts

2. Drag the say piece under the when I receive piece

3. Change the text in say to Cat Wins!

1

2

3

okay cat, say that you won

Page 59: Scratch - Rock, Paper, Scissors

1. Go to the Data scripts

2. Drag 2 set variable pieces below the repeat until for each score

3. Change one to set Your Score to 0

4. Change the other to set Cat Score to 0

Once the game has a winner, set the scores back to 0 to play again.

1

2

3 & 4

reset scores for next round

Page 60: Scratch - Rock, Paper, Scissors

Click on flag to run your program and play your game!

you did it!