Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. from random import *
  2.  
  3. def main():
  4. #selecting the folder with images
  5. showInformation("Please select the folder that contains the images of the dice.")
  6. setMediaPath()
  7.  
  8. #call function roll
  9. rollDice()
  10.  
  11. #call function display roll
  12. displayRoll()
  13.  
  14. game()
  15.  
  16. return "game over"
  17.  
  18.  
  19. def game():
  20. roll1 = rollDice()
  21.  
  22. #Player loses on first roll
  23. if roll1 in (2,3,12):
  24. showInformation("Player loses")
  25.  
  26. #player wins on first roll
  27. if roll1 in (7,11):
  28. showInformation("Player wins")
  29.  
  30. #Now we keep rolling until we get the value of the first roll or 7
  31. while roll1 != (7, roll1):
  32. showInformation("Next roll")
  33. #roll again
  34. roll2 = rollDice()
  35.  
  36. #extra roll player loses
  37. if roll2 == 7:
  38. showInformation("Player loses")
  39. return "loss"
  40.  
  41. #extra roll player wins
  42. elif roll2 == roll1:
  43. showInformation("Player wins")
  44. return "win"
  45.  
  46. def rollDice():
  47. #rolling the dice
  48. die1 = randrange(1,7)
  49. die2 = randrange(1,7)
  50.  
  51. roll1 = die1 + die2
  52. #putting the dice into a list
  53. dice = die1 + die2
  54. dice = [die1, die2, dice]
  55.  
  56. printNow("Player rolled a " + str(die1) + " + " + str(die2) + " = " + str(roll1)) #displays die1 + die2 and what they equal
  57.  
  58. returnList = []
  59. returnList = dice, roll1
  60.  
  61. #sets the funciton = to sum of the dice
  62. return returnList
  63.  
  64.  
  65.  
  66. def displayRoll():
  67. returnList = rollDice()
  68.  
  69. #List of the die pictures. Ex. ("1.jpg")
  70. diePics = []
  71. diePics = str(returnList[1]) + ".jpg", str(returnList[1]) + ".jpg" #displays die1 + die2 and what they equal
  72.  
  73.  
  74. #select the first two dice and select their pictures
  75. pic = makePicture(diePics[0])
  76. pic2 = makePicture(diePics[1])
  77.  
  78. #get width and height of picture size, double width to allow for two dice
  79. cWidth = getWidth(pic)
  80. cWidth = cWidth*2
  81. cHeight = getHeight(pic)
  82. cHeight = cHeight + 1
  83.  
  84. #show the dice side by side
  85. canvas = makeEmptyPicture(cWidth, cHeight)
  86.  
  87. #copy the dice into the same canvas
  88. copyInto(pic, canvas, 0, 0)
  89. copyInto(pic2, canvas, 79, 0)
  90. show(canvas)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement