Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1.  
  2. Save New Duplicate & Edit Just Text
  3. from tkinter import *
  4. from random import randint
  5. import time
  6. location = [0,0]
  7. window = Tk()
  8. Direction = "none"
  9. Gold = 0
  10. window.geometry("1000x800")
  11. window.title("Wander")
  12.  
  13.  
  14. def GoldF():
  15. global Gold
  16. global GCount
  17. global GLabel
  18. Gold = Gold + 5
  19. GCount.grid()
  20. GCount.delete(0.0, END)
  21. GCount.insert(END, Gold)
  22. GLabel.grid()
  23. Start()
  24.  
  25. def Found():
  26. global Gold
  27. global GCount
  28. chance = randint(1, 5)
  29. if chance == 1:
  30. W.delete(0.0, END)
  31. W.insert(END,"You find some gold as you travel")
  32. North.grid_remove()
  33. South.grid_remove()
  34. West.grid_remove()
  35. East.grid_remove()
  36. GButton.grid()
  37. else:
  38. Start()
  39.  
  40.  
  41. def Display():
  42. global Direction
  43. Loc.delete(0.0, END)
  44. location[0] = str(location[0])
  45. location[1] = str(location[1])
  46. Loc.insert(END, location[0]+","+location[1])
  47. W.delete(0.0, END)
  48. W.insert(END,"You traveled", Direction)
  49. time.sleep(3)
  50. Found()
  51.  
  52.  
  53. def WanderNorth():
  54. global location
  55. global Direction
  56. MovementV = randint(1, 3)
  57. Vmove = location[1]
  58. Nomove = location[0]
  59. Vmove = int(Vmove)
  60. Nomove = int(Nomove)
  61. Vmove = Vmove + MovementV
  62. location = [Nomove,Vmove]
  63. print(location)
  64. Direction = "North"
  65. Display()
  66.  
  67. def WanderEast():
  68. global location
  69. global Direction
  70. MovementH = randint(1, 3)
  71. Hmove = location[0]
  72. Nomove = location[1]
  73. Hmove = int(Hmove)
  74. Nomove = int(Nomove)
  75. Hmove = Hmove + MovementH
  76. location = [Hmove,Nomove]
  77. print(location)
  78. Direction = "East"
  79. Display()
  80.  
  81. def WanderSouth():
  82. global location
  83. global Direction
  84. MovementV = randint(1, 3)
  85. Vmove = location[1]
  86. Nomove = location[0]
  87. Vmove = int(Vmove)
  88. Nomove = int(Nomove)
  89. Vmove = Vmove - MovementV
  90. location = [Nomove,Vmove]
  91. print(location)
  92. Direction = "South"
  93. Display()
  94.  
  95. def WanderWest():
  96. global location
  97. global Direction
  98. MovementH = randint(1, 3)
  99. Hmove = location[0]
  100. Nomove = location[1]
  101. Hmove = int(Hmove)
  102. Nomove = int(Nomove)
  103. Hmove = Hmove - MovementH
  104. location = [Hmove,Nomove]
  105. print(location)
  106. Direction = "West"
  107. Display()
  108.  
  109.  
  110.  
  111. W = Text(window, width=30, height=5, wrap=WORD, bg="Pink")
  112. W.grid(row=1, column=1, columnspan=6, rowspan=5)
  113. Loc = Text(window, width=9, height=1, wrap=WORD, bg ="Cyan")
  114. Loc.grid(row=2, column=7, sticky="n")
  115. GCount = Text(window, width=3, height=1, wrap=WORD, bg="Yellow")
  116. GCount.grid(row=2, column=8, stick="n")
  117. GButton = Button(window, text="Pickup", width=5, command=GoldF)
  118. GButton.grid(row=3, column=8, rowspan=2, columnspan=1, sticky="n")
  119. GLabel = Label(window, text= "Gold")
  120. GLabel.grid(row=1, column=8, stick="n")
  121. LocNot = Label(window, text= "Location")
  122. LocNot.grid(row=1, column=7, stick="n")
  123. North = Button(window, text="North", width=5, command=WanderNorth)
  124. North.grid(row=6, column=1, rowspan=2, columnspan=1, sticky="w")
  125. East = Button(window, text="East", width=5, command=WanderEast)
  126. East.grid(row=6, column=5, rowspan=2, columnspan=1, sticky="e")
  127. South = Button(window, text="South", width=5, command=WanderSouth)
  128. South.grid(row=6, column=2, rowspan=2, columnspan=1, sticky="w")
  129. West = Button(window, text="West", width=5, command=WanderWest)
  130. West.grid(row=6, column=6, rowspan=2, columnspan=1, sticky="e")
  131.  
  132.  
  133. def Start():
  134. North.grid()
  135. South.grid()
  136. West.grid()
  137. East.grid()
  138. GButton.grid_remove()
  139. W.delete(0.0, END)
  140. W.insert(0.0, "Which way do you want to travel?")
  141. W.delete(2.0, 3.0)
  142.  
  143. def Hide():
  144. GCount.grid_remove()
  145. GCount.delete(0.0, END)
  146. GLabel.grid_remove()
  147. GButton.grid_remove()
  148. Start()
  149.  
  150. Hide()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement