Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The program simulates a simple game of chance using three to six dice. The dice are six-sided and each side has a distinct number between

The program simulates a simple game of chance using three to six dice. The dice are six-sided and each side has a distinct number between 1 and 6 on it. When a dice is rolled, then each number occurs with equal chance. The game proceeds in three stages, setup, play, and end stage. During the setup stage the user is asked to enter the number of dice that will be used in the game. If the input of the user is not a natural number between 3 and 6, then an error message should be shown and the user is asked again for a number. This continues until the input of the user is a natural number between 3 and 6, denoted by N in the following. The check and error messages must be realised using JavaScript, not using HTML5 elements and attributes. During the play stage the game proceeds in rounds during which the program maintains a balance of points won and the number of rounds played. Initialy, both balance and number of rounds played is zero. In each round, the program first increments the number of rounds played by one, then rolls the N dice and computes the number of points won according to the following table: Description Points Calculation Example (with four dice) Example Points Calculation All N dice have the same value 60 + Sum of the values of all the dice 3,3,3,3 60 + 3 + 3 + 3 + 3 = 72 N - 1 but not N dice have the same value 40 + Sum of the values of all the dice 4,4,4,6 40 + 4 + 4 + 4 + 6 = 58 2,5,2,2 40 + 2 + 5 + 2 + 2 = 51 A run (a sequence K+1 to K+N for some K 0) 20 + Sum of the values of all the dice 3,4,5,6 20 + 3 + 4 + 5 + 6 = 38 4,3,2,1 20 + 4 + 3 + 2 + 1 = 30 4,6,3,5 20 + 4 + 6 + 3 + 5 = 38 All dice have different values, but it is not a run Sum of the values of all the dice 4,5,3,1 4 + 5 + 3 + 1 = 13 3,6,2,5 3 + 6 + 2 + 5 = 16 Any other outcome 0 4,5,3,3 0 The number of points won is then added to the balance of points and constitutes the balance at the end of the round. The program will then display the number of rounds played, the dice values (possibly in the form of a nice graphical representation), the number points won in that round, and the balance of points at the end of the round. The program then provides the user with the options (i) to continue with another round, or (ii) to end the game. If option (i) is chosen, then the program remains in the play stage and proceeds with another round. If option (ii) is chosen, then the program proceeds to the end stage. In the end stage, the program computes the average number of points won per round and displays the number of rounds played, the balance of points when reaching the end stage, the average number of points won per round played, rounded to one digit after the decimal point. Additional requirements and comments: The bulk of your JavaScript code should be in a JavaScript library called game.js. Before submitting your solution, you should create a copy of game.js named game.pretty.js in a directory other than your public_html directory, say, your home directory. Then make the file game.js indecipherable for humans using the command uglifyjs $HOME/game.pretty.js --compress --mangle > $HOME/public_html/game.js. Make sure that after performing this operation your game still works. Also make sure that the file game.pretty.js can only be read by yourself. Use of images for the dice and absence of JavaScript prompts and alerts improve the quality of the game design. Remember that if you use images, then they must be your own or your use must be legal under copyright law. You should also provide a reference for the source or sources of your images in your code. Within each round of the play stage, the user only needs to be shown the information for the current round, there is no requirement that the user can still see what happened in previous rounds. Indeed, it may result in better quality game design if they do not. The code should be written in such a way that it could deal with an arbitrary number of dice. JavaScript engines differ from browser to browser. You should make sure that your system works in all commonly used browsers (e.g., Google Chrome, Mozilla Firefox, Microsoft Internet Explorer 9 or higher) and on all commonly used platforms (e.g., Linux derivatives and Microsoft Windows). Your JavaScript program should only depend on your own code. JavaScript libraries/frameworks should not be used. Your code should follow the COMP519 Coding Standard. This includes pointing out which parts of your code have been developed with the help of on-line sources or textbooks and references for these sources.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions