Event | Day | Date | Time |
---|---|---|---|
Release | Wed | Sep 04 | 09:00 AM ET |
Due | Wed | Sep 11 | 05:00 PM ET |
In this homework, you will implement a simple dice game (Pig) where two players race to reach 100 points. On each turn, the current player repeatedly rolls a die until a “1” is rolled or the player decides to “hold”:
The first player to score 100 or more points wins.
Please note, in the context of the Pig dice game, the “turn total” refers to the sum of all dice rolls a player makes during their current turn (unless they roll a 1, which resets the turn total to 0).
On the other hand, “score” refers to the total number of points a player has accumulated throughout the entire game. This includes points from previous turns as well as the current turn, provided the player decides to ‘hold’ and add their turn total to their score.
Please see the demo on Panopto.
Log into your GitHub account at https://github.com/. Next, click on this link and accept the invitation. This will create a private GitHub repository containing the starter code.
Please ensure the repository remains private. Do not alter its visibility or add collaborators. Clone this repository locally to commence your work.
Clone the repository to your computer, then open the index.html
file in VSCode to familiarize yourself with its content. You’ll find the layout bears resemblance to the one we used for the Rock-Paper-Scissors game. Notably, this file uses the Bootstrap progress bar component. For a better understanding of how this component works, review its documentation.
You should refrain from making any changes to the index.html file.
Open the index.js
file and familiarize yourself with its content. You’ll notice the event listeners for the “Roll” and “Hold” buttons:
roll
function simulates the roll of a fair six-sided die and updates the UI to display the outcome.hold
function demonstrates how to update the progress bar for Player-1. Each time you press the “Hold” button, it will add +10 to the score and +5 to the turn total.Your assignment is to complete the game implementation as per the provided description, specification, and demo.
Update the info.json
file with links to your GitHub repository and your deployed app’s location:
After updating the info.json
file, commit and push your code to your GitHub repository. Afterwards, submit your work on Gradescope.
Should you need to resubmit, push the changes to your repository first and then re-submit on Gradescope.
Teaching assistants will evaluate your submission using the following criteria:
Spec 1: The game initializes with both players’ scores and turn totals set to zero. Player-1’s turn is initiated, and both “Roll” and “Hold” buttons are enabled.
Spec 2: Clicking the “Roll” button simulates rolling a die, updating the UI to display the outcome.
Spec 3: When a player rolls a number other than 1, that number is added to their turn total, reflected in the UI. The other player’s progress remains unchanged, and the UI indicates it’s still their turn.
Spec 4: Player progress bars display two bars: one for the score and one for the turn total. Score bars use royal blue, and turn total bars use animated turquoise stripes.
Spec 5: Rolling a non-1 number doesn’t alter the player’s score unless it would result in a score of 100 or more. In such a case, the game initiates the hold action for that player.
Spec 6: Numeric values for score and turn total are displayed within the progress bars unless the value is zero.
Spec 7: If a player rolls a 1, their turn total resets to zero, and it becomes the other player’s turn without altering either player’s score.
Spec 8: Clicking “Hold” adds the current turn total to the player’s score, updating the UI accordingly while switching turns.
Spec 9: After holding, the player’s turn total resets to zero and reflects this change in the UI.
Spec 10: If a player’s score reaches 100, they are declared the winner, and their progress bar turns green, displaying “100 🎉” as their score.
Spec 11: If a player’s roll results in a total score (current score plus turn total) of 100 or more, the hold action is automatically initiated, ending the game.
Spec 12: Upon game end, the “Roll” and “Hold” buttons become disabled to prevent further gameplay.
Spec 13: The code demonstrates readability through consistent indentation, descriptive naming, and appropriately placed comments.
Spec 14: Programming style emphasizes modularity, with helper functions focusing on single responsibilities and avoiding excessive length. Objects or arrays are preferred over primitives where applicable for better code organization and practices.