Advertisement
davidhellam

Python: Simple Adventure

Aug 10th, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.36 KB | None | 0 0
  1. from guizero import App, Text, TextBox, PushButton, info, yesno
  2.  
  3. def turnaround(name,bucket):
  4.     nowattack=yesno("An idea dawns...","You are now armed with a bucket of water. Will you now face the Dragon?\n\nClick [Yes] to fight the Dragon.\n\nClick [No] to run and hide.")
  5.     if nowattack:
  6.         face2face(name,bucket)
  7.     else:
  8.         fail(name)
  9.  
  10. def face2face(name,bucket):
  11.     info("In the bowels of the Maze...","You see the Dragon turning slowly towards you, its mouth dribbling with vitriol...")
  12.     attack = yesno("Fight or Flight?","What will you do? \n\nClick on [Yes] to run headlong and attack the Dragon\n\nClick on [No] to find an escape route")
  13.     if (attack and bucket):
  14.         info("A successful strategy...,","You see the Dragon draw its breath, ready to spray you with flames. Quick as a flash, you throw the bucket of water down its throat.\n\nThe Dragon roars in pain as its fire extinguishes. You now draw your sword and slay the beast before it recovers from the shock!")
  15.         success(name)
  16.     elif (attack and not bucket):
  17.         info("Brave but stupid...","With a loud cry you launch yourself directly into a stream of flame. You die!")
  18.         fail(name)
  19.     else:
  20.         bucket=yesno("What\'s this?","You trip over a bucket of water as you look for a way to evade the Dragon.\n\nClick on [Yes] to pick up the bucket.\n\nClick on [No] to run as fast as you can.")
  21.         if bucket:
  22.             turnaround(name,bucket)
  23.         else:
  24.             info("Flamed from behind...","Unfortunately, you cannot run fast enough, the stream of fire and the Dragon\'s roar are the last things you remember.")
  25.             fail(name)
  26.  
  27. def success(name):
  28.     info("Congratulations!","Well done, "+name+", you have killed the Dragon.\n\nUnfortunately, there is a Troll at the front gate...")    
  29.  
  30. def fail(name):
  31.     info("And so it ends...","Sadly, "+name+", you have failed to slay the Dragon.\n\nBetter luck in another life!")
  32.  
  33. def adventure():
  34.     name = tbx_name.value
  35.     bucket = False
  36.     info("And so it begins...","Welcome, "+name+", to the Maze of Mystery!")
  37.     info("The Great Hall","You are in the Great Hall of King Xorgix.\n\nA fearsome Dragon has just ravaged the castle and left the place in ruins.")
  38.     descend = yesno("Will you go down the hole?","There is a huge hole in the middle of the floor, a wisp of smoke rises from it,\n\nClick on [Yes] to descend into the hole\n\nClick on [No] to leave the Great Hall and search the Courtyard")
  39.     if descend:
  40.         info("Into the Maze...","You crawl down into a maze of tunnels. It is getting hotter, but you finally see a dull red glow in front of you.")
  41.         face2face(name,bucket)
  42.     else:
  43.         info("You hear a whooshing sound...","A sudden beating of wings and a blast of fire from behind are the last things you remember.")
  44.         fail(name)
  45.        
  46. app = App(title='My Simple Pop-Up Adventure', bg="yellow", width=640, height=480)
  47. app.text_color="blue"
  48. txt_title = Text(app, text="Welcome to the Great Adventure",size=24)
  49. txt_title.text_color="black"
  50. txt_underline = Text(app, text = "#################################",size=24)
  51. txt_underline.text_color="yellow"
  52. txt_underline.bg="black"
  53. txt_name = Text(app,text="Please enter your name below:",size = 12)
  54. tbx_name = TextBox(app, width = 20)
  55. btn_start = PushButton(app, text = "Click me to begin the adventure!", command=adventure)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement