Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

How do I draw dice with dots in Python?

$
0
0
Here is the website for my assignment and the guidelines I am supposed to follow.

http://lhs-sfusd-ca.schoolloop.com/assignment/view?id=1356608919949&return_url=1360456228666

Here is the code I have so far and I need to include the random function and draw dots on my dice. I'm not sure where to put in the random function and how to draw dots. I want to keep all my code except for the last section with the random integers because I'm not sure where to put in that part into my code. Help is much appreciated!

from nodebox.graphics import *
import random

class FlatDie:
    def __init__(self):
        self.roll()
    def roll(self):
        self.dots = 3
    def show(self,x,y):
        stroke(0)
        fill(0)
        rect(x,y,30,30)
        fill(1)
        text(str(self.dots),x+10,y+10)
     
def draw (canvas):
    if canvas.mouse.pressed or canvas.frame == 1:
        total = 0
        i = 0
        while i < 6:
            Zac = FlatDie()
            Zac.roll()
            Zac.show(i * 35,85)
            total = total + Zac.dots
            i+=1
        fill(0)
        text("Total roll: " + str(total),10,10)
 
canvas.size = 200,200
canvas.run(draw)

die1=random.randint(1,6)
die2=random.randint(1,6)
die3=random.randint(1,6)
die4=random.randint(1,6)
die5=random.randint(1,6)
die6=random.randint(1,6)
total=int(die1+die2+die3+die4+die5+die6)


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>