Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <meta http-equiv="Content-Type" content="text/html;charset=UTF8">
- <body>
- <script>
- ///////////////////////////////////////////////////////////////////////////////
- // Begin Framework
- function printMessage(message) {
- document.write(message);
- document.write("<br/>");
- }
- function rollDice(numberOfDice) {
- // Setup our array for storing all of the dice rolls
- this.diceRolls = [];
- // Setup our empty display message for all of the rolls
- var diceRollsMessage = "";
- // Roll each of the die in turn
- for (var diceRoll = 0; diceRoll < numberOfDice; ++diceRoll) {
- // If this is not our first roll then add in a comma to the output string
- if (diceRoll > 0) {
- diceRollsMessage += ", ";
- }
- // Roll the current die
- currentRoll = rollDie(6);
- // Add the current die roll to the message
- diceRollsMessage += currentRoll;
- // Store the current die value
- this.diceRolls[this.diceRolls.length] = currentRoll;
- }
- // Display all of the dice rolls
- printMessage("Dice Rolls: " + diceRollsMessage);
- }
- rollDice.prototype.numDie = function(dieValue) {
- var matchingDieCount = 0;
- // Iterate over all of the stored dice rolls
- for (var roll = 0; roll < this.diceRolls.length; ++roll) {
- // If the roll matches our search value then increment the count of matching die
- if (this.diceRolls[roll] == dieValue) {
- ++matchingDieCount;
- }
- }
- return matchingDieCount;
- }
- // Run the game
- game();
- // End Framework
- ///////////////////////////////////////////////////////////////////////////////
- function rollDie(numberOfSides) {
- ///////////////////////////////////////////////////////////////////////////////
- // Begin Block 1 to Complete
- Math.floor((Math.random() * 6) + 1); //produce a random number between 1 and 6 inclusive
- // End Block 1 to Complete
- ///////////////////////////////////////////////////////////////////////////////
- }
- function turn() {
- // Roll all 6 dice
- var diceRolls = new rollDice(6);
- // Start the score for this turn at 0
- var score = 0;
- ///////////////////////////////////////////////////////////////////////////////
- // Begin Block 2 to Complete
- var num1 = diceRolls.numDie(1);
- var num2 = diceRolls.numDie(2);
- var num3 = diceRolls.numDie(3);
- var num4 = diceRolls.numDie(4);
- var num5 = diceRolls.numDie(5);
- var num6 = diceRolls.numDie(6);
- if(num1 == 1) //if one 1 is rolled score +100
- {
- score += 100 // add 100 to score
- }
- if(num1 == 2) //if two 1's are rolled
- {
- score += 200 //add 200 to score
- }
- if(num1 == 3) //if 3 1's are rolled
- {
- score += 1000 //add 1000 to score
- }
- if(num5 == 1) //if one 5 is rolled
- {
- score += 50 //add 50 to score
- }
- if(num5 == 2) //if two 5's are rolled
- {
- score += 10 //add 10 to score
- }
- if(num2 == 3) //if three 2's are rolled
- {
- score += (100*2) //add 100*2
- }
- if(num3 == 3) //if three 3's are rolled
- {
- score += (100*3) //add 100*3
- }
- if(num4 == 3) //if three 4's are rolled
- {
- score += (100*4) //add 100*4
- }
- if(num5 == 3) //if three 5's are rolled
- {
- score += (100*5) //add 100*5
- } //add 100*5
- if(num6 == 3) //if three 6's are rolled
- {
- score += (100*6) //add 100*6
- }
- var randomMultiplier = Math.floor((Math.random() * 6) + 1)
- if(num1 !=1 && num1 !=2 && num1 !=3)
- {
- score += ((2*3000) + (3000 * randomMultiplier))
- }
- if(num2 !=1 && num2 !=2 && num2 !=3)
- {
- score += ((2*200) + (200 * randomMultiplier))
- }
- if(num3 !=1 && num2 !=2 && num2 !=3)
- {
- score += ((2*300) + (300 * randomMultiplier))
- }
- if(num4 !=1 && num2 !=2 && num2 !=3)
- {
- score += ((2*400) + (400 * randomMultiplier))
- }
- if(num5 !=1 && num2 !=2 && num2 !=3)
- {
- score += ((2*500) + (500 * randomMultiplier))
- }
- if(num6 !=1 && num2 !=2 && num2 !=3)
- {
- score += ((2*600) + (600 * randomMultiplier))
- }
- // End Block 2 to Complete
- ///////////////////////////////////////////////////////////////////////////////
- printMessage("This turn was worth " + score + " points");
- return score;
- }
- function didWin(score) {
- ///////////////////////////////////////////////////////////////////////////////
- // Begin Block 3 to Complete
- var win = 1
- if(score >= 30000)
- {
- var win = 1
- }
- else
- {
- var win = 0
- }
- document.write(win)
- // End Block 3 to Complete
- ///////////////////////////////////////////////////////////////////////////////
- }
- function game() {
- // Start the score for the game at 0
- var score = 0;
- ///////////////////////////////////////////////////////////////////////////////
- // Begin Block 4 to Complete
- var score = turn();
- // End Block 4 to Complete
- ///////////////////////////////////////////////////////////////////////////////
- // Determine if we won and display a suitable message
- if (didWin(score)) {
- ///////////////////////////////////////////////////////////////////////////////
- // Begin Block 5 to Complete
- if(win == 1)
- {
- printMessage("You win!")
- }
- // End Block 5 to Complete
- ///////////////////////////////////////////////////////////////////////////////
- else {
- ///////////////////////////////////////////////////////////////////////////////
- // Begin Block 6 to Complete
- printMessage("You lose")
- // End Block 6 to Complete
- ///////////////////////////////////////////////////////////////////////////////
- }
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement