Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Tkinter import *
- class Node(object):
- def __init__(self, name, description):
- object.__init__(self)
- self.name = name
- self.description = description
- self.optionA = None
- self.optionB = None
- def setName(self, name):
- self.name = name
- def getName(self):
- return self.name
- def setDescription(self, description):
- self.description = description
- def getDescription(self):
- return self.description
- def setoptionA(self,optionA):
- self.optionA = optionA
- def getoptionA(self):
- return self.optionA
- def setoptionB(self, optionB):
- self.optionB = optionB
- def getoptionB(self):
- return self.optionB
- def Display(self):
- print self.description
- print "What do you do now?"
- print "1) %s" % self.optionA.getName()
- print "2) %s\n" % self.optionB.getName()
- class Game(Tk):
- def __init__(self):
- Tk.__init__(self)
- self.headerFont = ("Veranda", "25","bold")
- self.textFont = ("Veranda", "20", "normal")
- self.buttonFont = ("Veranda", "15", "normal")
- #self.configure(background = "light blue")
- self.title("Zelda Text Adventure!")
- self.start()
- def setupGrid(self):
- self.lblOutput = Label(self, text = "Zelda Text Adventure!", font = self.headerFont).grid(columnspan = 2)
- self.lblDescription = Label(self, text = self.currentNode.description,font = self.textFont)
- self.lblDescription.grid()
- self.btnOptionA = Button(self, text = self.currentNode.optionA.name,font = self.buttonFont,relief = RIDGE)
- self.btnOptionA.grid()
- self.btnOptionA["command"] = self.pickOptionA
- self.btnOptionB = Button(self, text = self.currentNode.optionB.name,font = self.buttonFont,relief = RIDGE)
- self.btnOptionB.grid()
- self.btnOptionB["command"] = self.pickOptionB
- def pickOptionA(self):
- self.currentNode = self.currentNode.getoptionA()
- self.end(self.currentNode.description)
- def pickOptionB(self):
- self.currentNode = self.currentNode.getoptionB()
- if self.currentNode.getoptionA() == None:
- self.end(self.currentNode.description)
- else:
- self.updateGrid()
- def updateGrid(self):
- self.lblDescription["text"] = self.currentNode.description
- self.btnOptionA["text"] = self.currentNode.optionA.getName()
- self.btnOptionB["text"] = self.currentNode.optionB.getName()
- def end(self, description):
- self.lblDescription["text"] = description
- self.btnOptionA.grid_remove()
- self.btnOptionB.grid_remove()
- def start(self):
- start = Node("Start", "You wake up to a cucco gnawing at your leg.\nNOT AGAIN, you think.")
- 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.")
- shake = Node("Kindly shake it off.", "The cucco backs away and leaves you to ponder where you are.\nYou survey your surroundings.")
- 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." )
- 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.")
- door = Node("Leave through the dungeon door.", "You open the door and a swarm of bats knock you to your death.")
- water = Node("Follow a little stream of water.", "You leave the dungeon and immediately fall into water.\nDo you have Zora armor?")
- no = Node("No?", "In that case, you get hit in the face repeatedly by an Octorok until you drown.")
- yes = Node("Yes.", "You swim to safety and see Zoras waving at you.")
- trip = Node("Wave to the Zoras.","You start walking and trip in front of them. They laugh and you die of embarrassment!")
- 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!")
- 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.")
- 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...")
- start.setoptionA(swat)
- start.setoptionB(shake)
- shake.setoptionA(light)
- shake.setoptionB(dark)
- dark.setoptionA(door)
- dark.setoptionB(water)
- water.setoptionA(no)
- water.setoptionB(yes)
- yes.setoptionA(trip)
- yes.setoptionB(talk)
- talk.setoptionA(suit)
- talk.setoptionB(follow)
- self.currentNode = start
- self.setupGrid()
- def main():
- a = Game()
- a.mainloop()
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment