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.
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.
For this or future labs, you can always (and probably will need to) refer to the getting started guide.
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.
Click the Scratch program to open it on your computer.
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.
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.
If you want this game to follow a particular "theme", feel free to change the background of the stage.
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:
Make the three sprites for these "buttons" and place them appropriately on the stage.
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.
Add a script block to the stage so that when the green flag is clicked, the value of Guess is set to 0.
Each button should broadcast the message "Roll dice" after setting the value of the Guess variable.
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 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).
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 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.
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".
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.
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.
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.
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.
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.
Go to http://www.scratch.mit.edu and download it to your own computer.
There are 25 parts to this guideline - each part is worth 4 points.