CSE 111 - Fall 2010 - Banner
  • CSE 111 - Fall 2010
CSE 111 - Fall 2010 - Navigation
CSE 111 - Fall 2010 - Lab Assignment #5

Lab Assignment #5
Last modified: November 09 2010 07:55:48 PM

CSE 111 - Fall 2010 - Lab Assignment #5

For this week's scratch assignment, instead of working on it as a group, the TAs will explain the basic concepts needed for the lab, but you will work on your own. Feel free to ask questions when you have them.

Lab Attendance #3

There will be a lab attendance grade assigned for this assignment. Note that there is a separate line item in the syllabus for lab attendance. This attendance is the third of those three lab attendance grades. In order to receive full credit for the lab attendance, you need to attend at least one lab session during the weeks of November 1st, November 8th or November 15th.

 

Resources

For this or future labs, you can always (and probably will need to) refer to the getting started guide.

General Explanation of Assignment

You will build a game that rolls a pair of dice. The user will "bet" on each roll and their total score will be computed after each roll. Keep reading the lab assignment for further explanation of how to build the solution to this assignment.

Open Scratch

Click the Scratch program to open it on your computer.

Making a Pair of Dice (Start with one)

Pick a sprite that will represent the picture on the first die. The pictures on each of the dice may be different. You will need to create 6 costumes for each of the dice. In order to do this, "copy" the costume of the sprite 6 times. Edit each of the costumes to insert a number into the costume. Notice the T button in the edit dialog. This is a text button that will allow you to add text to the costume. Put the numbers 1 through 6 in each of the costumes.

Making a Pair of Dice (Make the second)

If you would like a different image for your second die, do the same thing with the other image. Otherwise, you can simply copy this sprite (and costumes) to make your second.

Put the two dice on the screen next to each other.

Change the background (if you'd like)

If you want this game to follow a particular "theme", feel free to change the background of the stage.

Create some "guess" "buttons"

You will need three "buttons" to click on to make your guesses for each of the dice rolls. These "buttons" do not need to be images of buttons, but should clearly indicate the guess the user is making. The guesses relate to the total value rolled on the two dice. They are:

  • Less than 7
  • Equal to 7
  • More than 7

Make the three sprites for these "buttons" and place them appropriately on the stage.

Making your Guess

Create a variable that can be seen by all sprites named "Guess". Make sure you can see it on the stage and move it to a location on the stage that makes sense to you visually. The value of Guess should be set when one of the three buttons is clicked. If the more than 7 button is clicked, the value of Guess should be set to "high". If the less than 7 button is clicked, the value of Guess should be set to "low". If the equal to 7 button is clicked, the value of Guess should be set to "equal".

At this point, make sure that clicking on the "buttons" sets the correct value in the Guess variable.

When Green Flag Clicked

Add a script block to the stage so that when the green flag is clicked, the value of Guess is set to 0.

Last step for Buttons

Each button should broadcast the message "Roll dice" after setting the value of the Guess variable.

First Die Rolls

The first die should receive the broadcast "roll dice". When it does, a "roll" needs to happen. Rolling a die is actually causing a random number to be chosen for the die, showing the correct costume based on the number, and then updating the dice total correctly. The next several paragraphs will break down these steps to get the first die "rolled".

Create a variable for the die

Create a variable named "Rolled For Die 1" that is only for the sprite that is the first die. When the first die received the message "Roll dice", the value of that variable should be set to a random number between 1 and 6. At this time, you can check that this is working by having the variable on the stage. After a while, you can make this variable "hidden" (by un-checking the box next to the variables name on the Variables tab).

Change Costumes

After we set the value of the variable, we can check its value in an if-statement and set the costume of the sprite accordingly.

Create a variable for the total roll

Create a variable named "Total rolled" that is for all sprites and position it appropriately on your stage. It must remain visible while your program is working.

Looking at the script for your sprite for the first die, find an appropriate place the change the value of the Total rolled variable by the value that is selected randomly.

Check out that everything is working correctly by running your program and watching the total of the rolls appear.

Note that the total keeps going up. But, at the end of the each roll, the total should reset back to zero. So, the first part of the script for the first die should reset the value of Total rolled back to zero.

Roll the next die

Broadcast a message "Roll Die 2" when all of the steps for die 1 are completed. The code for the second die is very similar to the first die. A random number must be selected between 1 and 6 for this die, the costume should be updated and the total rolled should be updated. Refer to the preceeding paragraphs if you don't remember how to do any of these. After this die has completed its jobs, it should broadcast the message "Total computed".

Did you guess correct?

The stage is listening for the "Total computed" broadcast. When it receives it, we need to figure out whether or not the user guessed correctly about the outcome of the dice roll. In order to do this, we will need a variable to hold the total points and some logic about when the user was correct. The next few paragraphs will discuss these steps.

Create a variable named Points Earned

so that it is for all the sprites and position it appropriately on your stage. You will update its value based on the correctness of the user's guess.

Is the user correct?

We need to determine if the user guessed correctly. The user guessed correctly if one of the following conditions are met. Otherwise, the user guessed incorrectly and points should be subtracted from the total points earned.

  • If the user guessed the total would be higher than 7 and it was.
  • If the user guessed the total would be equal to 7 and it was.
  • If the user guessed the total would be less than 7 and it was.

A few hints for this. Notice that the above are compound expressions (think "and" "or"). Also remember what the values were that the variable Guessed was set to (high, low, equal). And note, that there is a block in Operators that is "length of ". We can look at the length of the word stored in the variable Guessed and determine which guess was picked. Combine that with the total from the dice, and you can determine if the guess was correct and award points accordingly.

Submit your work

When you have finished your Lab 5 assignment, select to save it by selecting "Save As" from the File menu. Save the project as YourNameLab5 where you put your name in for "YourName" in the filename. Submit it to the digital drop box in UBLearns. In the digital dropbox, you can submit multiple times. We will only grade the last submission you make, so make sure that the last submission is the one you want graded.

NOTE: The assignment is not technically due until Sunday, November 28th at 11:55pm. However, you are welcome and encouraged to submit the assignment early. NO late assignments will be graded.

Want to work on Scratch at Home?

Go to http://www.scratch.mit.edu and download it to your own computer.

 

Lab 5 Grading Information

There are 25 parts to this guideline - each part is worth 4 points.

  1. A loadable project was turned into the digital drop box.
  2. There is a sprite that represents a die that has 6 costumes. The values of the costumes are clear to the user. If not, 0 points awarded.
  3. There are two dice on the stage.
  4. There are three buttons present with the choices for each clearly indicated.
  5. A variable named guess has been created and is visible on the stage.
  6. A variable named total rolled has been created and is visible on the stage.
  7. A variable named points earned has been created and is visible on the stage.
  8. On Green flag, the value of guess is set to 0.
  9. On Green flag, the value of points earned is set to 0.
  10. When the user clicks a button, the value of the variable guess is correctly set.
  11. After setting the guess, the message "roll dice" is broadcast.
  12. The first die is programmed to react to the "roll dice" message.
  13. The first die resets the value of the total roll variable when the "roll dice" message is received.
  14. There is a variable (in the first die) that should not be visible on the stage.
  15. This variable for the first die is set to a random number when "roll dice" broadcast is received.
  16. The costume of the die is set based on the value selected for that variable.
  17. After the value for the first die is established, that value is added to the variable for the total rolled.
  18. The first die broadcasts the message to roll dice 2.
  19. The second die has a variable that is set to a random number, changes its costume based on that number, and adds the value selected to the total value.
  20. After the above operations, the second die broadcasts the message that the total is computed.
  21. The stage responds to the total computed message.
  22. If the user has guessed high and the total rolled is greater than 7, points should be awarded.
  23. If the user has guessed equal and the total rolled is 7, points should be awarded.
  24. If the user has guessed low and the total rolled is less than 7, points should be awarded.
  25. If none of the three above conditions are met, points should be deducted from the total.
CSE 111 - Fall 2010 - Footer

Page maintained by Adrienne Decker

Contact: adrienne@buffalo.edu | 130 Bell Hall | (716)645-3184