Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1.  
  2. import time
  3. import random
  4. import console
  5. def get_answers(filename) :
  6. '''read and parse the answer file'''
  7. ret = []
  8. filehandle = open(filename,'r')
  9. for line in filehandle.readlines() :
  10. if line.strip().startswith('#') :
  11. continue
  12. if '--' in line :
  13. line, otherstuff = line.split('--',1)
  14. line = line.strip()
  15. if line != '' :
  16. ret.append(line)
  17. filehandle.close()
  18. return ret
  19.  
  20.  
  21. answers = get_answers('Eight_Ball_Answers.text')
  22.  
  23. import ui
  24.  
  25. def button_tapped(sender):
  26. sender.title = random.choice(answers)
  27.  
  28. view = ui.View()
  29. view.name = 'Magic Eight Ball'
  30. view.background_color = 'black'
  31. button = ui.Button(title='To Begin Magic Eight Ball, Tap Me!')
  32. button.center = (view.width * 0.5, view.height * 0.5)
  33. button.flex = 'LRTB'
  34. button.action = button_tapped
  35. view.add_subview(button)
  36. view.present('sheet')
  37.  
  38. #you also need this in another file, that is named Eight_Ball_Answers.text
  39.  
  40. # positives
  41. It is certain
  42. It is decidedly so
  43. Without a doubt
  44. Yes definitely
  45. You may rely on it
  46. As I see it, yes
  47. Most likely
  48. Outlook good
  49. Yes
  50. Signs point to yes
  51.  
  52. #ask agains
  53. Reply hazy try again
  54. Ask again later
  55. Better not tell you now
  56. Cannot predict now
  57. Concentrate and ask again later
  58.  
  59. # negitives
  60. Don't count on it
  61. My reply is no
  62. My sources say no
  63. Outlook not so good
  64. Very doubtful
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement