Advertisement
Guest User

Untitled

a guest
Jan 13th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. #Christopher Ticona
  2. #Vision and Hearing examination
  3.  
  4. import pygame #All implementation of pygame itself
  5.  
  6. pygame.init()
  7.  
  8. #Colors
  9. black = (0, 0, 0)
  10. white = (255, 255, 255)
  11. red = (255, 0, 0)
  12. green = (0, 255, 0)
  13. blue = (0, 0, 255)
  14. yellow = (255, 255, 0)
  15.  
  16. #Images
  17. imageOne = pygame.image.load("imageOne.gif")
  18. imageOne = pygame.transform.scale(imageOne,(200,200))
  19. imageTwo = pygame.image.load("imageTwo.png")
  20. imageTwo = pygame.transform.scale(imageTwo, (400,400))
  21.  
  22. #Messages and questions
  23. welcome = "Welcome to my program! Let's get started. Today, we'll be examining your eyesight/color and hearing to see if you need any glasses or support for your sense. Don't worry, this could help your health!"
  24. summaryProgram = "There will be multiple images and sounds when you're answering the exam to test yourself on hearing, eyesight, and color blindness. Be honest and don't judge yourself if you get it wrong! Good luck!"
  25.  
  26. questionOne = "1) What do you see?: "
  27. questionTwo = "2) What's 1 letter from the 20/20 vision section?"
  28.  
  29. #Screen to display graphics
  30. screen = pygame.display.set_mode((1550, 720))
  31. screen.fill(white)
  32. pygame.display.set_caption("Vision and Hearing Examination")
  33.  
  34. class Button:
  35. def __init__(self, rect, command):
  36. self.rect = pygame.Rect(rect)
  37. self.image = pygame.Surface(self.rect.size).convert()
  38. self.image.fill((red))
  39. self.function = command
  40.  
  41. def get_event(self, event):
  42. if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
  43. self.on_click(event)
  44.  
  45. def on_click(self, event):
  46. if self.rect.collidepoint(event.pos):
  47. self.function()
  48.  
  49. def draw(self, surf):
  50. surf.blit(self.image, self.rect)
  51.  
  52.  
  53. def button_was_pressed():
  54. if (pygame.MOUSEBUTTONDOWN == answerOne):
  55. printText("You're correct! 1 Point", 15, 350, 100, black)
  56. else:
  57. printText("You're incorrect! Keep going!", 15, 350, 100, black)
  58.  
  59.  
  60. def button_was_pressed1():
  61. if (pygame.MOUSEBUTTONDOWN == answerTwo):
  62. printText("You're correct! 1 Point", 15, 350, 300, black)
  63. else:
  64. printText("You're incorrect! Keep going!", 15, 350, 300, black)
  65.  
  66. def printText(txtText, Textsize , Textx, Texty, Textcolor):
  67. #User's font
  68. myfont = pygame.font.SysFont('Comic Sans MS', Textsize)
  69. #Input text
  70. label = myfont.render(txtText, 1, Textcolor)
  71. #Coordinates of text
  72. screen.blit(label, (Textx, Texty))
  73. #Show the full display
  74. pygame.display.flip()
  75.  
  76. def textButton(text,x,y):
  77. font = pygame.font.SysFont("Comic Sans MS", 30)
  78. textsurface = font.render((text), True, (0,0,0))
  79. button_rect = textsurface.get_rect(topright=(x,y))
  80. screen.blit(textsurface, button_rect)
  81.  
  82. #Font is automatically Comic Sans MS (Change if needed)
  83. #printText(Text, Size, X, Y, Color)
  84. welcomingMessage = printText(welcome, 15, 5, 10, black)
  85. explanation = printText(summaryProgram, 15, 5, 30, black)
  86. questionOne = printText(questionOne, 15, 5, 100, black)
  87. questionTwo = printText(questionTwo, 15, 5, 300, black)
  88.  
  89. #Images displayed to the quiz
  90. screen.blit(imageOne,(700,100))
  91. screen.blit(imageTwo,(600,300))
  92.  
  93. #Button(rect=(x, y, height, width), command=button_was_pressed)
  94. #Question 1
  95. btn = Button(rect=(25,120,105,30), command=button_was_pressed)
  96. btn1 = Button(rect=(200,120,105,30), command=button_was_pressed)
  97. btn2 = Button(rect=(25,180,105,30), command = button_was_pressed)
  98. btn3 = Button(rect=(200,180,105,30), command = button_was_pressed)
  99. #Question 2
  100. btn4 = Button(rect=(25,320,105,30), command=button_was_pressed1)
  101. btn5 = Button(rect=(200,320,105,30), command=button_was_pressed1)
  102. btn6 = Button(rect=(25,380,105,30), command=button_was_pressed1)
  103. btn7 = Button(rect=(200,380,105,30), command=button_was_pressed1)
  104.  
  105. answerOne = btn
  106. answerTwo = btn6
  107.  
  108. done = False
  109. while not done:
  110. for event in pygame.event.get():
  111. if event.type == pygame.QUIT:
  112. done = True
  113. exit()
  114. quit()
  115. btn.get_event(event)
  116. btn1.get_event(event)
  117. btn2.get_event(event)
  118. btn3.get_event(event)
  119. btn4.get_event(event)
  120. btn5.get_event(event)
  121. btn6.get_event(event)
  122. btn7.get_event(event)
  123. btn.draw(screen)
  124. btn1.draw(screen)
  125. btn2.draw(screen)
  126. btn3.draw(screen)
  127. btn4.draw(screen)
  128. btn5.draw(screen)
  129. btn6.draw(screen)
  130. btn7.draw(screen)
  131.  
  132. #Text over button
  133. #Question 1
  134. textButton("8", 90, 110)
  135. textButton("3", 250,110)
  136. textButton("7", 90, 170)
  137. textButton("18", 250, 170)
  138. #Question 2
  139. textButton("B", 90, 310)
  140. textButton("A", 250, 310)
  141. textButton("O", 90, 370)
  142. textButton("X", 250, 370)
  143. pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement