Guest User

Untitled

a guest
Apr 27th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1. from Tkinter import *
  2.  
  3. class Node(object):
  4. def __init__(self, name, description):
  5. object.__init__(self)
  6. self.name = name
  7. self.description = description
  8. self.optionA = None
  9. self.optionB = None
  10.  
  11. def setName(self, name):
  12. self.name = name
  13.  
  14. def getName(self):
  15. return self.name
  16.  
  17. def setDescription(self, description):
  18. self.description = description
  19.  
  20. def getDescription(self):
  21. return self.description
  22.  
  23. def setoptionA(self,optionA):
  24. self.optionA = optionA
  25.  
  26. def getoptionA(self):
  27. return self.optionA
  28.  
  29. def setoptionB(self, optionB):
  30. self.optionB = optionB
  31.  
  32. def getoptionB(self):
  33. return self.optionB
  34.  
  35. def Display(self):
  36. print self.description
  37. print "What do you do now?"
  38. print "1) %s" % self.optionA.getName()
  39. print "2) %s\n" % self.optionB.getName()
  40.  
  41. class Game(Tk):
  42. def __init__(self):
  43. Tk.__init__(self)
  44. self.headerFont = ("Veranda", "25","bold")
  45. self.textFont = ("Veranda", "20", "normal")
  46. self.buttonFont = ("Veranda", "15", "normal")
  47. #self.configure(background = "light blue")
  48. self.title("Zelda Text Adventure!")
  49.  
  50. self.start()
  51.  
  52. def setupGrid(self):
  53. self.lblOutput = Label(self, text = "Zelda Text Adventure!", font = self.headerFont).grid(columnspan = 2)
  54.  
  55. self.lblDescription = Label(self, text = self.currentNode.description,font = self.textFont)
  56. self.lblDescription.grid()
  57.  
  58.  
  59. self.btnOptionA = Button(self, text = self.currentNode.optionA.name,font = self.buttonFont,relief = RIDGE)
  60. self.btnOptionA.grid()
  61. self.btnOptionA["command"] = self.pickOptionA
  62.  
  63. self.btnOptionB = Button(self, text = self.currentNode.optionB.name,font = self.buttonFont,relief = RIDGE)
  64. self.btnOptionB.grid()
  65. self.btnOptionB["command"] = self.pickOptionB
  66.  
  67. def pickOptionA(self):
  68. self.currentNode = self.currentNode.getoptionA()
  69. self.end(self.currentNode.description)
  70.  
  71. def pickOptionB(self):
  72. self.currentNode = self.currentNode.getoptionB()
  73. if self.currentNode.getoptionA() == None:
  74. self.end(self.currentNode.description)
  75. else:
  76. self.updateGrid()
  77.  
  78. def updateGrid(self):
  79. self.lblDescription["text"] = self.currentNode.description
  80. self.btnOptionA["text"] = self.currentNode.optionA.getName()
  81. self.btnOptionB["text"] = self.currentNode.optionB.getName()
  82.  
  83. def end(self, description):
  84. self.lblDescription["text"] = description
  85. self.btnOptionA.grid_remove()
  86. self.btnOptionB.grid_remove()
  87.  
  88. def start(self):
  89. start = Node("Start", "You wake up to a cucco gnawing at your leg.\nNOT AGAIN, you think.")
  90. swat = Node("Swat at it furiously with your sword.", "You swat at the cucco and a swarm comes in and attacks your beautiful face.\nYour health was low, so game over.")
  91. shake = Node("Kindly shake it off.", "The cucco backs away and leaves you to ponder where you are.\nYou survey your surroundings.")
  92.  
  93. light = Node("Go toward the light.", "You go towards the light and realized you're in the forest.\nYou hear, 'Hey! Listen!'\nNavi finds you.\nYou kill yourself because if you don't, Navi's annoyingness will." )
  94. dark = Node("Go towards the darkness.", "You go towards the darkness and see you're in a dungeon.\nThe first thing you see is a ReDead.\nYou successfully defeat it.")
  95.  
  96. door = Node("Leave through the dungeon door.", "You open the door and a swarm of bats knock you to your death.")
  97. water = Node("Follow a little stream of water.", "You leave the dungeon and immediately fall into water.\nDo you have Zora armor?")
  98.  
  99. no = Node("No?", "In that case, you get hit in the face repeatedly by an Octorok until you drown.")
  100. yes = Node("Yes.", "You swim to safety and see Zoras waving at you.")
  101.  
  102. trip = Node("Wave to the Zoras.","You start walking and trip in front of them. They laugh and you die of embarrassment!")
  103. talk = Node("Go to the Zoras and talk.", "You talk to them and they say, 'Hey, nice suit.' \nThey also tell you the whereabouts of Zelda! Yes!")
  104.  
  105. suit = Node("Brag about your suit.", "You brag way too much and annoy the Zoras, therefore exiling you to fight yourself. You forget to save Zelda.")
  106. follow = Node("Follow what they said to find Zelda.", "You do what they say, yadda yadda yadda...you rescue Zelda! YAY! \nBut she still didn't give you a reward...")
  107.  
  108. start.setoptionA(swat)
  109. start.setoptionB(shake)
  110. shake.setoptionA(light)
  111. shake.setoptionB(dark)
  112. dark.setoptionA(door)
  113. dark.setoptionB(water)
  114. water.setoptionA(no)
  115. water.setoptionB(yes)
  116. yes.setoptionA(trip)
  117. yes.setoptionB(talk)
  118. talk.setoptionA(suit)
  119. talk.setoptionB(follow)
  120.  
  121. self.currentNode = start
  122. self.setupGrid()
  123.  
  124. def main():
  125. a = Game()
  126. a.mainloop()
  127.  
  128. if __name__ == '__main__':
  129. main()
Add Comment
Please, Sign In to add comment