Lesson 1 (Dice Roll Guesser)

Lesson 1 (Dice Roll Guesser)

Today's objective is to create a mini game that produces the below output.
image.png

Learning Intention:

  • I can construct a decision tree diagram to show the logic in my dice roll guesser.
  • I can follow the steps below to create a functioning dice roll guesser.
  • Ext. I can add additional features to my game to enhance the user experience

 

Activity Description Assessment Criteria
Decision Tree

The below decision tree clearly demonstrates the different elements of the dice roll guesser game.

image.png

 

Activity:

Copy the above decision tree for the dice roll guesser. The decision tree should clearly show the flow of your program and the user's inputs. Remember to use the accurate conventions including:

  • Diamonds for elements requiring user input
  • Rectangles for computer output not requiring an input
  • Colours to distinguish between valid and invalid program inputs
  • Directional arrows with labels to show stored variables and/or users inputs.

purposeful design of algorithms and game map.

  • Decision tree/flowchart has accurate conventions and clearly shows the flow of the game.
Creating the game

Step 1: Creating the game loop

  • The below code declares a boolean variable as true which will act as the condition for the while loop. "game_on" will be true until the point where the user either wins or loses.
  • The game loop is created with the first line of code in the loop asking for the user to input their guess and storing the response as an integer in the variable "user_guess"
  • Next the computer generates a random integer between 1 and 6 that it stores in a variable called "roll_result"

image.png

 

Step 2: Checking the user input against the dice roll

Before we check the user input and dice roll, we need to make sure the users lives are set to 3 at the beginning of the program. We do this by creating a variable and setting the value.

image.png

Now we can check to see if the user has guessed correctly or incorrectly. An if statement inside our while loop with a condition that the user_guess == roll_result will check whether the user has won.

image.png
If the user guesses incorrectly, not only do we have to subtract a life from their total but we also need to run another check to see if they still have live remaining. We do that by nesting an if statement inside the else to determine if they are out of lives.

image.png

proficient implementation of game that includes functioning and purposeful use of iteration, conditional statements, variables and user input.