Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import *
- def main():
- #selecting the folder with images
- showInformation("Please select the folder that contains the images of the dice.")
- setMediaPath()
- #call function roll
- rollDice()
- #call function display roll
- displayRoll()
- game()
- return "game over"
- def game():
- roll1 = rollDice()
- #Player loses on first roll
- if roll1 in (2,3,12):
- showInformation("Player loses")
- #player wins on first roll
- if roll1 in (7,11):
- showInformation("Player wins")
- #Now we keep rolling until we get the value of the first roll or 7
- while roll1 != (7, roll1):
- showInformation("Next roll")
- #roll again
- roll2 = rollDice()
- #extra roll player loses
- if roll2 == 7:
- showInformation("Player loses")
- return "loss"
- #extra roll player wins
- elif roll2 == roll1:
- showInformation("Player wins")
- return "win"
- def rollDice():
- #rolling the dice
- die1 = randrange(1,7)
- die2 = randrange(1,7)
- roll1 = die1 + die2
- #putting the dice into a list
- dice = die1 + die2
- dice = [die1, die2, dice]
- printNow("Player rolled a " + str(die1) + " + " + str(die2) + " = " + str(roll1)) #displays die1 + die2 and what they equal
- returnList = []
- returnList = dice, roll1
- #sets the funciton = to sum of the dice
- return returnList
- def displayRoll():
- returnList = rollDice()
- #List of the die pictures. Ex. ("1.jpg")
- diePics = []
- diePics = str(returnList[1]) + ".jpg", str(returnList[1]) + ".jpg" #displays die1 + die2 and what they equal
- #select the first two dice and select their pictures
- pic = makePicture(diePics[0])
- pic2 = makePicture(diePics[1])
- #get width and height of picture size, double width to allow for two dice
- cWidth = getWidth(pic)
- cWidth = cWidth*2
- cHeight = getHeight(pic)
- cHeight = cHeight + 1
- #show the dice side by side
- canvas = makeEmptyPicture(cWidth, cHeight)
- #copy the dice into the same canvas
- copyInto(pic, canvas, 0, 0)
- copyInto(pic2, canvas, 79, 0)
- show(canvas)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement