Documente Academic
Documente Profesional
Documente Cultură
Fall Lab 10
MATERIAL COVERED
• Array basics
Notes:
• Each lab is scored out of 2 points. Each completed lab exercise is worth 1 point. You must
complete two to receive full marks on the lab.
• Name your files something similar to LastnameFirstnameLab10Silver.pde.
• Your completed lab must be submitted before the deadline to the “Lab 10” submission folder.
Submit your Processing code (pde file) for each question.
• In this lab, each exercise depends on the previous exercise, so you will need to do them in
order.
• You are encouraged to do as many as you can. It’s excellent practice for assignments, tests,
exams, and future courses.
• The Bronze exercise is very small, and all students are encouraged to complete at least the Silver
exercise.
• Lab 11 will be a continuation of this lab, and will allow you to complete a fully-functional single-
person game.
Overall description
In this lab, you will implement a simplified version of the dice game Yahtzee™. For those familiar
with the game:
• Only the top half of the score sheet will be used in Lab 10.
• It is a single player game only.
• In each exercise, you will write two small functions which will add one more aspect to the
game. All other necessary code will be supplied.
• The Bronze level will only allow 5 dice to be rolled.
• The Silver level will allow re-rolling of some of the dice.
• The Gold level will keep score, and complete a simplified game.
The main functions (setup, draw, etc.) will be provided, including all necessary graphics code. You
need only write the small array-based functions.
Roll em!
The game is played by rolling 5 dice. The dice roll will be stored in an int[] array containing 5 integer
values from 1 to 6. A function void drawDie(int position, int value) will be provided, which
will draw one die in the canvas, in one of NUM_DICE locations. The first parameter is the location, which
must be a value from 0 (the leftmost die) to NUM_DICE-1 (the rightmost die). The second parameter is
the number to be shown on the die (from 1 to 6). Start with the file Lab10BronzeTemplate.pde. Add
one array and two small functions to create a program that will roll and display the dice.
1. Create an int[] global variable and initialize it to an array that will hold the NUM_DICE dice.
2. Write a function void rollDice() which will fill the array with a new dice roll – NUM_DICE
random integers between 1 and NUM_SIDES (these constants are already defined for you).
3. Write a function void showDiceRoll() which will draw the dice roll by calling the provided
drawDie function NUM_DICE times – once for each die.
Once complete, the bronze program should roll the dice every time you click on the canvas.