Die Roller

die

Today we are going to implement a die roller, a program that rolls one six-sided die and displays the face of the top side.  To get the job done, we’re going to need some tools that we used in some of our other programs like random integers and the drawSquare() function.

Here is a summary of the program requirements:

  • Steal the drawSquare() function from our pervious programs.
  • Create a function for each of the six faces of the die, drawOne() to drawSix().  The functions should place the dots on the faces based on the size of the edges of the square, as we discussed in class.  Remember that we call this a relative placement instead of an absolute placement.
  • The main program will set up the turtle and screen, generate a random integer from 1 to 6, and decide which face to draw using an if-elif-else block.
  • Name your program file yourname-dieroller.py and submit it for grading here.

Here is a short video demonstrating the output of the program:

The code below is an outline for the program you will write.  I’ve included hash tag comments in the places where you will need to fill in your own code.  You can copy this into a new Python file named yourname-dieroller.py and then complete the program.

# diceroller.py

import turtle
import random

# ****************************************
# Function Definitions
# ****************************************

def drawSquare(t, sz):
    """Make turtle t draw a square of with side sz."""

    # Put the code here for the drawSquare function

def drawOne(t,sz):
    """Make turtle t draw one dot in center of square."""

    drawSquare(t, sz)
    t.penup()
    t.goto(sz/2,sz/2)
    t.pendown()
    t.stamp()	

def drawTwo(t,sz):
    """Make turtle t draw two dots in corners of square."""

    drawSquare(t, sz)
    t.penup()
    t.goto(0.25*sz,0.75*sz)
    t.pendown()
    t.stamp()
    t.penup()
    t.goto(0.75*sz,0.25*sz)
    t.pendown()
    t.stamp()

def drawThree(t,sz):
    """Make turtle t draw three dots along diagonal of square."""

    # Put your code here to draw three dots.  Hint: combine drawOne() and Drawtwo.

def drawFour(t,sz):
    """Make turtle t draw four dots in corners of square."""

    # Put your code here to draw four dots on the face.

def drawFive(t,sz):
    """Make turtle t draw five dots in the corners and center of square."""

    # Put your code here to draw five dots on the face.

def drawSix(t,sz):
    """Make turtle t draw six dots on the square."""

    # Put your code here to draw four dots on the face.

# ****************************************
# Main Program Code
# ****************************************

# Set size of square for die
sz = 200

# Generate the die roll
# Put a statement here to generate a random number between 1 and 6.  
# Store it in a variable name roll or something similar.
#
#
#

# Setup the Turtle for drawing
# Put code here to create alex and the screen.
# Be sure to set alex's shape to "circle".
#
# Try this to set the shape of the stamp: alex.shape('circle')
# and use wn.title("Put you window title here") to put a title on the turtle window.
#
#

# Decide which die to draw

# Put your if-elif-else block here that decides which face to draw, then call that function.
#
#
#
#

# Quit when the user clicks the mouse on the screen
wn.exitonclick()

When your program is complete and working correctly, make sure the filename is yourname-dieroller.py and then submit it for grading here.