Advertisement
gPiOBox

Further - Tell the Truth! - RPi - Python

Oct 16th, 2017
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 22.23 KB | None | 0 0
  1. """
  2. filename:gpio_rpi_python_truth.py
  3. Tell the Truth! game code
  4. written by Trevor Olsson & Matthew Wells
  5. © GPIO Support Services LTD MMXVII
  6. more info at www.gpio.co.uk/truth
  7. """
  8. from gpiozero import LED
  9. from time import sleep
  10. import random
  11. import pygame
  12. import time
  13. import sys
  14. import random
  15. import vlc
  16. import os
  17.  
  18. pygame.init()
  19. pygame.font.init()
  20. font = pygame.font.SysFont("monospace",15)
  21. #font_large = pygame.font.SysFont("monospace",)
  22.  
  23. displayInfo = pygame.display.Info()
  24. screen = pygame.display.set_mode((displayInfo.current_w,displayInfo.current_h),pygame.FULLSCREEN)
  25. #screen = pygame.display.set_mode((displayInfo.current_w,displayInfo.current_h))
  26. display_width,display_height = screen.get_size()
  27. font_large = pygame.font.SysFont("monospace",displayInfo.current_h/10)
  28.  
  29. black = (0,0,0)
  30. white = (255,255,255)
  31. red = (255,0,0)
  32. green = (0,255,0)
  33. blue = (0,0,255)
  34.  
  35.  
  36. crashed = False
  37.  
  38. OP_old = 0
  39. OP1 = LED(17) # A=0,B=0 in Truth Table
  40. OP2 = LED(18) # A=0,B=1 in Truth Table
  41. OP3 = LED(27) # A=1,B=0 in Truth Table
  42. OP4 = LED(22) # A=1,B=1 in Truth Table
  43. OP5 = LED(23)
  44. OP6 = LED(24)
  45.  
  46. INA = 0
  47. INB = 0
  48. INC = 0
  49. IND = 0
  50. INE = 0
  51. INF = 0
  52. ING = 0
  53.  
  54. # tables used to ensure Gibberish is not a real gate
  55. ANDg = [0,0,0,1]
  56. ORg = [0,1,1,1]
  57. NANDg = [1,1,1,0]
  58. NORg = [1,0,0,0]
  59. XORg = [0,1,1,0]
  60. XNORg = [1,0,0,1]
  61.  
  62. # tables used to turn on lights
  63. AND = [OP4] # Lights required for AND list
  64. OR = [OP2, OP3, OP4] # Lights required for OR list
  65. NAND = [OP1, OP2, OP3] # Lights required for NAND list
  66. NOR = [OP1] # Lights required for NOR list
  67. XOR = [OP2,OP3]
  68. XNOR = [OP1,OP4]
  69. ALL= [OP1, OP2, OP3, OP4, OP5, OP6] # All lights list - used to turn all off
  70.  
  71. score=0
  72. chances=10 # number of goes
  73. def getFinalScore(a,b,c):
  74.     score = 0
  75.     if b == 1:
  76.         score = a/c+4
  77.     if b == 2:
  78.         score = a/c+2
  79.     if b == 3:
  80.         scpre = a/c+4
  81.     scoreDisplay(score)
  82.     writeScore(score)
  83. def writeScore(score):
  84.     fHandler = open("Scores.txt", "r")
  85.     fData = fHandler.readlines()
  86.     fHandler.close()
  87.     fHandler = open("Scores.txt", "w")
  88.     fData.append(str(score)+"\n")
  89.     fHandler.writelines(fData)
  90.     fHandler.close()
  91. def quitF():
  92.     pygame.quit()
  93.     sys.exit()
  94. def AND_on():
  95.     for light in AND:
  96.         light.on()
  97. def OR_on():
  98.     for light in OR:
  99.         light.on()
  100. def NAND_on():
  101.     for light in NAND:
  102.         light.on()
  103. def NOR_on():
  104.     for light in NOR:
  105.         light.on()
  106. def XNOR_on():
  107.     for light in XNOR:
  108.         light.on()
  109. def XOR_on():
  110.     for light in XOR:
  111.         light.on()
  112. def Gibberish_on():
  113.     tmp = True
  114.     while tmp:
  115.         attempt = [random.randrange(0,1),random.randrange(0,1),random.randrange(0,1),random.randrange(0,1)]
  116.         if attempt != ANDg and attempt != ORg and attempt != NANDg and attempt != NORg and attempt != XNORg and attempt != XORg:
  117.             tmp = False
  118.     if attempt[0] == 1:
  119.         OP1.on()
  120.     if attempt[1] == 1:
  121.         OP2.on()
  122.     if attempt[2] == 1:
  123.         OP3.on()
  124.     if attempt[3] == 1:
  125.         OP4.on()
  126. def ALL_off():
  127.     for light in ALL:
  128.         light.off()
  129. def ALL_on():
  130.     for light in ALL:
  131.         light.on()
  132. def lightsDefault():
  133.     ALL_off()
  134.     OP5.on()
  135.     OP6.off()
  136. def correctFlash(gate):
  137.     player = play('correct.mp3')
  138.     running = True
  139.     while running:
  140.         randomLight = random.randint(1,6)
  141.         randomStatus = random.randint(1,2)
  142.         if randomLight == 1:
  143.             if randomStatus == 1:
  144.                 OP1.on()
  145.             elif randomStatus == 2:
  146.                 OP1.off()
  147.         elif randomLight == 2:
  148.             if randomStatus == 1:
  149.                 OP2.on()
  150.             elif randomStatus == 2:
  151.                 OP2.off()
  152.         elif randomLight == 3:
  153.             if randomStatus == 1:
  154.                 OP3.on()
  155.             elif randomStatus == 2:
  156.                 OP3.off()
  157.         elif randomLight == 4:
  158.             if randomStatus == 1:
  159.                 OP4.on()
  160.             elif randomStatus == 2:
  161.                 OP4.off()
  162.         elif randomLight == 5:
  163.             if randomStatus == 1:
  164.                 OP5.on()
  165.             elif randomStatus == 2:
  166.                 OP5.off()
  167.         elif randomLight == 6:
  168.             if randomStatus == 1:
  169.                 OP6.on()
  170.             elif randomStatus == 2:
  171.                 OP6.off()
  172.         #strText = "Correct!!"
  173.         #text = font_large.render(strText, 1, black)
  174.         text2 = font_large.render(gate, 1, black)
  175.         screen.fill(green)
  176.         #screen.blit(text, (display_width/2-len(strText), display_height/2))
  177.         screen.blit(text2,(display_width/2-len(gate),display_height/2))
  178.         playing = set([1,2,3,4])
  179.         state = player.get_state()
  180.         pygame.display.update()
  181.         pygame.event.clear()
  182.         if state not in playing:
  183.             running = False
  184.         sleep(.1)
  185.     ALL_off()
  186. def wrongFlash():
  187.     player = play('wrong.mp3')
  188.     running = True
  189.     while running:
  190.         for i in range(1,3):
  191.             ALL_on()
  192.             sleep(0.1)
  193.             ALL_off()
  194.             sleep(0.1)
  195.         strText = "Incorrect!!"
  196.         text = font_large.render(strText, 1, black)
  197.         screen.fill(red)
  198.         screen.blit(text, (display_width/2-len(strText), display_height/2))
  199.         playing = set([1,2,3,4])
  200.         state = player.get_state()
  201.         pygame.display.update()
  202.         pygame.event.clear()
  203.         if state not in playing:
  204.             running = False    
  205. def correct(gate):
  206.     correctFlash(gate)
  207. def wrong():
  208.     wrongFlash()
  209. def waitF(wait):
  210.     i = 0
  211.     broken = 0
  212.     global INA
  213.     global INB
  214.     global INC
  215.     global IND
  216.     startTime = time.time()
  217.     while broken == 0:
  218.         for event in pygame.event.get():
  219.             if event.type == pygame.QUIT:
  220.                 crashed = True
  221.             if event.type == pygame.KEYDOWN:
  222.                 if event.key == pygame.K_ESCAPE:
  223.                     quitF()
  224.                 if event.key == pygame.K_LEFT:
  225.                     #print('left')
  226.                     INA = 1
  227.                     pygame.event.clear()
  228.                     broken = 1
  229.                 elif event.key == pygame.K_RIGHT:
  230.                     #print('right')  
  231.                     INB = 1
  232.                     pygame.event.clear()
  233.                     broken = 1
  234.                 elif event.key == pygame.K_UP:
  235.                     #print('up')
  236.                     INC = 1
  237.                     pygame.event.clear()
  238.                     broken = 1
  239.                 elif event.key == pygame.K_DOWN:
  240.                     #print('down')
  241.                     IND = 1
  242.                     pygame.event.clear()
  243.                     broken = 1
  244.         timeSinceStart = time.time()-startTime
  245.         timeRemaining = wait - timeSinceStart
  246.         strText = "Time Remaining: " +format(timeRemaining,'.2f')+"S"
  247.         strText1 = "Tries Remaining: "+str(chances)
  248.         text = font_large.render(strText, 1, black)
  249.         text1= font_large.render(strText1, 1, black)
  250.         screen.fill(white)
  251.         screen.blit(text, (0 , display_height/2))
  252.         screen.blit(text1, (0 , display_height/2-64))
  253.         pygame.display.update()
  254.         #has time passed yet?
  255.         if time.time()-startTime >= wait:
  256.             broken = 1
  257. def waitF2(wait):
  258.     i = 0
  259.     broken = 0
  260.     global INA
  261.     global INB
  262.     global INC
  263.     global IND
  264.     global INE
  265.     global INF
  266.     startTime = time.time()
  267.     while broken == 0:
  268.         for event in pygame.event.get():
  269.             if event.type == pygame.QUIT:
  270.                 crashed = True
  271.             if event.type == pygame.KEYDOWN:
  272.                 if event.key == pygame.K_ESCAPE:
  273.                     quitF()
  274.                 if event.key == pygame.K_LEFT:
  275.                     #print('left')
  276.                     INA = 1
  277.                     pygame.event.clear()
  278.                     broken = 1
  279.                 elif event.key == pygame.K_RIGHT:
  280.                     #print('right')
  281.                     INB = 1
  282.                     pygame.event.clear()
  283.                     broken = 1
  284.                 elif event.key == pygame.K_UP:
  285.                     #print('up')
  286.                     INC = 1
  287.                     pygame.event.clear()
  288.                     broken = 1
  289.                 elif event.key == pygame.K_DOWN:
  290.                     #print('down')
  291.                     IND = 1
  292.                     pygame.event.clear()
  293.                     broken = 1
  294.                 elif event.key == pygame.K_SPACE:
  295.                     INE = 1
  296.                     pygame.event.clear()
  297.                     broken = 1
  298.                 elif event.key == pygame.K_w:
  299.                     INF = 1
  300.                     pygame.event.clear()
  301.                     broken = 1
  302.         timeSinceStart = time.time()-startTime
  303.         timeRemaining = wait - timeSinceStart
  304.         strText = "Time Remaining: " +format(timeRemaining,'.2f')+"S"
  305.         strText1 = "Tries Remaining: "+str(chances)
  306.         text = font_large.render(strText, 1, black)
  307.         text1= font_large.render(strText1, 1, black)
  308.         screen.fill(white)
  309.         screen.blit(text, (0 , display_height/2))
  310.         screen.blit(text1, (0 , display_height/2-64))
  311.         pygame.display.update()
  312.         #has time passed yet?
  313.         if time.time()-startTime >= wait:
  314.             broken = 1
  315. def waitF3(wait):
  316.     i = 0
  317.     broken = 0
  318.     global INA
  319.     global INB
  320.     global INC
  321.     global IND
  322.     global INE
  323.     global INF
  324.     global ING
  325.     startTime = time.time()
  326.     while broken == 0:
  327.         for event in pygame.event.get():
  328.             if event.type == pygame.QUIT:
  329.                 crashed = True
  330.             if event.type == pygame.KEYDOWN:
  331.                 if event.key == pygame.K_ESCAPE:
  332.                     quitF()
  333.                 if event.key == pygame.K_LEFT:
  334.                     #print('left')
  335.                     INA = 1
  336.                     pygame.event.clear()
  337.                     broken = 1
  338.                 elif event.key == pygame.K_RIGHT:
  339.                     #print('right')
  340.                     INB = 1
  341.                     pygame.event.clear()
  342.                     broken = 1
  343.                 elif event.key == pygame.K_UP:
  344.                     #print('up')
  345.                     INC = 1
  346.                     pygame.event.clear()
  347.                     broken = 1
  348.                 elif event.key == pygame.K_DOWN:
  349.                     #print('down')
  350.                     IND = 1
  351.                     pygame.event.clear()
  352.                     broken = 1
  353.                 elif event.key == pygame.K_SPACE:
  354.                     INE = 1
  355.                     pygame.event.clear()
  356.                     broken = 1
  357.                 elif event.key == pygame.K_w:
  358.                     INF = 1
  359.                     pygame.event.clear()
  360.                     broken = 1
  361.                 elif event.key == pygame.K_a:
  362.                     ING = 1
  363.                     pygame.event.clear()
  364.                     broken = 1
  365.         timeSinceStart = time.time()-startTime
  366.         timeRemaining = wait - timeSinceStart
  367.         strText = "Time Remaining: " +format(timeRemaining,'.2f')+"S"
  368.         strText1 = "Tries Remaining: "+str(chances)
  369.         text = font_large.render(strText, 1, black)
  370.         text1= font_large.render(strText1, 1, black)
  371.         screen.fill(white)
  372.         screen.blit(text, (0 , display_height/2))
  373.         screen.blit(text1, (0 , display_height/2-64))
  374.         pygame.display.update()
  375.         #has time passed yet?
  376.         if time.time()-startTime >= wait:
  377.             broken = 1
  378. def inputTimeG():
  379.     running = True
  380.     num = 1
  381.     confirm = 0
  382.     while running:
  383.         for event in pygame.event.get():
  384.                 if event.type == pygame.KEYDOWN:
  385.                     if event.key == pygame.K_ESCAPE:
  386.                         quitF()
  387.                     if event.key == pygame.K_LEFT:
  388.                         pass
  389.                     elif event.key == pygame.K_RIGHT:
  390.                         pass
  391.                     elif event.key == pygame.K_UP:
  392.                         num = num+1
  393.                     elif event.key == pygame.K_DOWN:
  394.                         confirm = 1
  395.         if num > 9:
  396.             num = 1
  397.         if confirm == 1:
  398.             return(num)
  399.             running = False
  400.         strText = "How many seconds do you need to think about this?"
  401.         strText2 = "1 to 9 Seconds (Press Up to cycle number, down to confirm): "+str(num)
  402.         text = font.render(strText, 1, black)
  403.         text2 = font.render(strText2, 1, black)
  404.         screen.fill(white)
  405.         screen.blit(text, (len(strText) , display_height/2))
  406.         screen.blit(text2, (len(strText2), display_height/2+32))
  407.         pygame.display.update()
  408.     screen.fill(white)
  409.     pygame.display.update()
  410. def play(filename):
  411.     vlcI = vlc.Instance()
  412.     player = vlcI.media_player_new()
  413.     media = vlcI.media_new(filename)
  414.     player.set_media(media)
  415.     player.play()
  416.     playing = set([1,2,3,4])
  417.     sleep(0.25)
  418.     return player
  419. def restart():
  420.     os.system('bash restart_code.sh &')
  421.     quitF()
  422. def scoreDisplay(PScore):
  423.     while True:
  424.         for event in pygame.event.get():
  425.                 if event.type == pygame.KEYDOWN:
  426.                     if event.key == pygame.K_ESCAPE:
  427.                         quitF()
  428.                     if event.key == pygame.K_LEFT:
  429.                         restart()
  430.                     elif event.key == pygame.K_RIGHT:
  431.                         restart()
  432.                     elif event.key == pygame.K_UP:
  433.                         restart()
  434.                     elif event.key == pygame.K_DOWN:
  435.                         restart()
  436.                     elif event.key == pygame.K_SPACE:
  437.                             restart()
  438.                     elif event.key == pygame.K_w:
  439.                         restart()
  440.                     elif event.key == pygame.K_e:
  441.                         restart()
  442.    
  443.         strText = "Touch Any Fruit To Continue"
  444.         strText2 = "Your Final Score Was: "+str(PScore)
  445.         text = font.render(strText, 1, black)
  446.         text2 = font.render(strText2, 1, black)
  447.         screen.fill(white)
  448.         screen.blit(text, (len(strText) , display_height/2))
  449.         screen.blit(text2, (len(strText2), display_height/2+32))
  450.         pygame.display.update()
  451. def gameLoopDifficultyOne(wait):
  452.     print('1')
  453.     global chances
  454.     global OP_old
  455.     global INA
  456.     global INB
  457.     global INC
  458.     global IND
  459.     global score
  460.    
  461.     while True:
  462.         lightsDefault()
  463.         chances=chances-1
  464.         #print("You have",chances,"chances left")
  465.         #OP= random.randint(1, 4)
  466.         OP = 1
  467.         while OP == OP_old:
  468.             OP= random.randint(1, 8)
  469.         #print(OP)
  470.         OP_old = OP
  471.    
  472.         if OP==1 or OP==5: # For an AND column
  473.             AND_on()
  474.             waitF(wait)
  475.             if INA != 0:
  476.                 correct('and')
  477.                 score=score+10
  478.                 sleep(.25)
  479.                 INA = 0
  480.             elif INB == 1 or INC == 1 or IND == 1:
  481.                 INA = 0
  482.                 INB = 0
  483.                 INC = 0
  484.                 IND = 0
  485.                 wrong()
  486.            
  487.         elif OP==2 or OP==6: # For an OR column
  488.             OR_on()
  489.             waitF(wait)
  490.             if INB != 0:
  491.                 correct('OR')
  492.                 score=score+10
  493.                 sleep(.25)
  494.                 INB = 0
  495.             elif INA == 1 or INC == 1 or IND == 1:
  496.                 INA = 0
  497.                 INB = 0
  498.                 INC = 0
  499.                 IND = 0
  500.                 wrong()
  501.        
  502.         elif OP==3 or OP==7: # For a NAND column
  503.             NAND_on()
  504.             waitF(wait)
  505.             if INC !=0:
  506.                 correct('NAND')
  507.                 score=score+10
  508.                 sleep(.25)
  509.                 INC = 0
  510.             elif INA == 1 or INB == 1 or IND == 1:
  511.                 INA = 0
  512.                 INB = 0
  513.                 INC = 0
  514.                 IND = 0
  515.                 wrong()
  516.            
  517.         elif OP==4 or OP==8:# For a NOR column
  518.             NOR_on()
  519.             waitF(wait)
  520.             if IND !=0:
  521.                 correct('NOR')
  522.                 score=score+10
  523.                 sleep(.25)
  524.                 IND = 0
  525.             elif INA == 1 or INB == 1 or INC == 1:
  526.                 INA = 0
  527.                 INB = 0
  528.                 INC = 0
  529.                 IND = 0
  530.                 wrong()
  531.  
  532.         if chances==0:
  533.             getFinalScore(score,1,wait)
  534.             print ("Your Final Score is:", score/wait, ", Game Over")
  535.             ALL_off()
  536.             break
  537.         screen.fill(white)
  538.         pygame.display.update()
  539. def gameLoopDifficultyTwo(wait):
  540.     print('2')
  541.     global chances
  542.     global OP_old
  543.     global INA
  544.     global INB
  545.     global INC
  546.     global IND
  547.     global INE
  548.     global INF
  549.     global score
  550.    
  551.     while True:
  552.         lightsDefault()
  553.         chances=chances-1
  554.         #print("You have",chances,"chances left")
  555.         OP= random.randint(1, 6)
  556.         #OP = 1
  557.         while OP == OP_old:
  558.             OP= random.randint(1, 6)
  559.         #print(OP)
  560.         OP_old = OP
  561.    
  562.         if OP==1: # For an AND column
  563.             AND_on()
  564.             waitF2(wait)
  565.             if INA != 0:
  566.                 correct('and')
  567.                 score=score+10
  568.                 sleep(.25)
  569.                 INA = 0
  570.             elif INB == 1 or INC == 1 or IND == 1 or INE == 1 or INF == 1:
  571.                 INA = 0
  572.                 INB = 0
  573.                 INC = 0
  574.                 IND = 0
  575.                 INE = 0
  576.                 INF = 0
  577.                 wrong()
  578.            
  579.         elif OP==2: # For an OR column
  580.             OR_on()
  581.             waitF2(wait)
  582.             if INB != 0:
  583.                 correct('OR')
  584.                 score=score+10
  585.                 sleep(.25)
  586.                 INB = 0
  587.             elif INA == 1 or INC == 1 or IND == 1 or INE == 1 or INF == 1:
  588.                 INA = 0
  589.                 INB = 0
  590.                 INC = 0
  591.                 IND = 0
  592.                 INE = 0
  593.                 INF = 0
  594.                 wrong()
  595.        
  596.         elif OP==3: # For a NAND column
  597.             NAND_on()
  598.             waitF2(wait)
  599.             if INC !=0:
  600.                 correct('NAND')
  601.                 score=score+10
  602.                 sleep(.25)
  603.                 INC = 0
  604.             elif INA == 1 or INB == 1 or IND == 1 or INE == 1 or INF == 1:
  605.                 INA = 0
  606.                 INB = 0
  607.                 INC = 0
  608.                 IND = 0
  609.                 INE = 0
  610.                 INF = 0
  611.                 wrong()
  612.            
  613.         elif OP==4:# For a NOR column
  614.             NOR_on()
  615.             waitF2(wait)
  616.             if IND !=0:
  617.                 correct('NOR')
  618.                 score=score+10
  619.                 sleep(.25)
  620.                 IND = 0
  621.             elif INA == 1 or INB == 1 or INC == 1 or INE == 1 or INF == 1:
  622.                 INA = 0
  623.                 INB = 0
  624.                 INC = 0
  625.                 IND = 0
  626.                 INE = 0
  627.                 INF = 0
  628.                 wrong()
  629.         elif OP==5:# For a XOR column
  630.             XOR_on()
  631.             waitF2(wait)
  632.             if INE !=0:
  633.                 correct('XOR')
  634.                 score=score+10
  635.                 sleep(.25)
  636.                 INE = 0
  637.             elif INA == 1 or INB == 1 or INC == 1 or IND == 1 or INF == 1:
  638.                 INA = 0
  639.                 INB = 0
  640.                 INC = 0
  641.                 IND = 0
  642.                 INE = 0
  643.                 INF = 0
  644.                 wrong()
  645.         elif OP==6:# For a XNOR column
  646.             XNOR_on()
  647.             waitF2(wait)
  648.             if INF !=0:
  649.                 correct('XNOR')
  650.                 score=score+10
  651.                 sleep(.25)
  652.                 INE = 0
  653.             elif INA == 1 or INB == 1 or INC == 1 or IND == 1 or INE == 1:
  654.                 INA = 0
  655.                 INB = 0
  656.                 INC = 0
  657.                 IND = 0
  658.                 INE = 0
  659.                 INF = 0
  660.                 wrong()
  661.         if chances==0:
  662.             getFinalScore(score,2,wait)
  663.             print ("Your Final Score is:", score/wait, ", Game Over")
  664.             ALL_off()
  665.             break
  666.         screen.fill(white)
  667.         pygame.display.update()
  668. def gameLoopDifficultyThree(wait):
  669.     print('3')
  670.     global chances
  671.     global OP_old
  672.     global INA
  673.     global INB
  674.     global INC
  675.     global IND
  676.     global INE
  677.     global INF
  678.     global ING
  679.     global score
  680.    
  681.     while True:
  682.         lightsDefault()
  683.         chances=chances-1
  684.         #print("You have",chances,"chances left")
  685.         OP= random.randint(1, 7)
  686.         #OP = 1
  687.         while OP == OP_old:
  688.             OP= random.randint(1, 7)
  689.         #print(OP)
  690.         OP_old = OP
  691.    
  692.         if OP==1: # For an AND column
  693.             AND_on()
  694.             waitF3(wait)
  695.             if INA != 0:
  696.                 correct('and')
  697.                 score=score+10
  698.                 sleep(.25)
  699.                 INA = 0
  700.             elif INB == 1 or INC == 1 or IND == 1 or INE == 1 or INF == 1 or ING == 1:
  701.                 INA = 0
  702.                 INB = 0
  703.                 INC = 0
  704.                 IND = 0
  705.                 INE = 0
  706.                 INF = 0
  707.                 wrong()
  708.            
  709.         elif OP==2: # For an OR column
  710.             OR_on()
  711.             waitF3(wait)
  712.             if INB != 0:
  713.                 correct('OR')
  714.                 score=score+10
  715.                 sleep(.25)
  716.                 INB = 0
  717.             elif INA == 1 or INC == 1 or IND == 1 or INE == 1 or INF == 1 or ING == 1:
  718.                 INA = 0
  719.                 INB = 0
  720.                 INC = 0
  721.                 IND = 0
  722.                 INE = 0
  723.                 INF = 0
  724.                 ING = 0
  725.                 wrong()
  726.        
  727.         elif OP==3: # For a NAND column
  728.             NAND_on()
  729.             waitF3(wait)
  730.             if INC !=0:
  731.                 correct('NAND')
  732.                 score=score+10
  733.                 sleep(.25)
  734.                 INC = 0
  735.             elif INA == 1 or INB == 1 or IND == 1 or INE == 1 or INF == 1 or ING == 1:
  736.                 INA = 0
  737.                 INB = 0
  738.                 INC = 0
  739.                 IND = 0
  740.                 INE = 0
  741.                 INF = 0
  742.                 ING = 0
  743.                 wrong()
  744.            
  745.         elif OP==4:# For a NOR column
  746.             NOR_on()
  747.             waitF3(wait)
  748.             if IND !=0:
  749.                 correct('NOR')
  750.                 score=score+10
  751.                 sleep(.25)
  752.                 IND = 0
  753.             elif INA == 1 or INB == 1 or INC == 1 or INE == 1 or INF == 1 or ING == 1:
  754.                 INA = 0
  755.                 INB = 0
  756.                 INC = 0
  757.                 IND = 0
  758.                 INE = 0
  759.                 INF = 0
  760.                 ING = 0
  761.                 wrong()
  762.         elif OP==5:# For a XOR column
  763.             XOR_on()
  764.             waitF3(wait)
  765.             if INE !=0:
  766.                 correct('XOR')
  767.                 score=score+10
  768.                 sleep(.25)
  769.                 INE = 0
  770.             elif INA == 1 or INB == 1 or INC == 1 or IND == 1 or INF == 1 or ING == 1:
  771.                 INA = 0
  772.                 INB = 0
  773.                 INC = 0
  774.                 IND = 0
  775.                 INE = 0
  776.                 INF = 0
  777.                 ING = 0
  778.                 wrong()
  779.         elif OP==6:# For a XNOR column
  780.             XNOR_on()
  781.             waitF3(wait)
  782.             if INF !=0:
  783.                 correct('XNOR')
  784.                 score=score+10
  785.                 sleep(.25)
  786.                 INE = 0
  787.             elif INA == 1 or INB == 1 or INC == 1 or IND == 1 or INE == 1 or ING == 1:
  788.                 INA = 0
  789.                 INB = 0
  790.                 INC = 0
  791.                 IND = 0
  792.                 INE = 0
  793.                 INF = 0
  794.                 ING = 0
  795.                 wrong()
  796.         elif OP==7:# For a Gibberish column
  797.             Gibberish_on()
  798.             waitF3(wait)
  799.             if ING !=0:
  800.                 correct('Gibberish')
  801.                 score=score+10
  802.                 sleep(.25)
  803.                 INE = 0
  804.             elif INA == 1 or INB == 1 or INC == 1 or IND == 1 or INE == 1:
  805.                 INA = 0
  806.                 INB = 0
  807.                 INC = 0
  808.                 IND = 0
  809.                 INE = 0
  810.                 INF = 0
  811.                 ING = 0
  812.                 wrong()
  813.         if chances==0:
  814.             getFinalScore(score,3,wait)
  815.             print ("Your Final Score is:", score/wait, ", Game Over")
  816.             ALL_off()
  817.             break
  818.         screen.fill(white)
  819.         pygame.display.update()
  820. def menu(wait):
  821.     menuPos=1
  822.     while True:
  823.         confirmed = 0
  824.         for event in pygame.event.get():
  825.             if event.type == pygame.KEYDOWN:
  826.                 if event.key == pygame.K_DOWN:
  827.                     if menuPos != 3:
  828.                         menuPos = menuPos+1
  829.                 if event.key == pygame.K_UP:
  830.                     if menuPos != 1:
  831.                         menuPos = menuPos-1
  832.                 if event.key == pygame.K_SPACE:
  833.                     if confirmed != 1:
  834.                         confirmed = 1
  835.                 if event.key == pygame.K_ESCAPE:
  836.                     quitF()
  837.         screen.fill(white)
  838.         if menuPos == 1:
  839.             text2 = font_large.render(">> Lunatic Mode", 1, blue)
  840.             screen.blit(text2,(50,10))
  841.             text2 = font_large.render("   Normal Mode", 1, black)
  842.             screen.blit(text2,(50,120))
  843.             text2 = font_large.render("   Easy Mode", 1, black)
  844.             screen.blit(text2,(50,230))
  845.         if menuPos == 2:
  846.             text2 = font_large.render("   Lunatic Mode", 1, black)
  847.             screen.blit(text2,(50,10))
  848.             text2 = font_large.render(">> Normal Mode", 1, blue)
  849.             screen.blit(text2,(50,120))
  850.             text2 = font_large.render("   Easy Mode", 1, black)
  851.             screen.blit(text2,(50,230))
  852.         if menuPos == 3:
  853.             text2 = font_large.render("   Lunatic Mode", 1, black)
  854.             screen.blit(text2,(50,10))
  855.             text2 = font_large.render("   Normal Mode", 1, black)
  856.             screen.blit(text2,(50,120))
  857.             text2 = font_large.render(">> Easy Mode", 1, blue)
  858.             screen.blit(text2,(50,230))
  859.         if confirmed == 1:
  860.             print(menuPos)
  861.             if menuPos == 3:
  862.                 gameLoopDifficultyOne(wait)
  863.             elif menuPos == 2:
  864.                 gameLoopDifficultyTwo(wait)
  865.             elif menuPos == 1:
  866.                 gameLoopDifficultyThree(wait)
  867.         pygame.display.update()
  868.  
  869.  
  870. lightsDefault()
  871. wait = 9
  872. #gameLoopDifficultyOne(wait)
  873. menu(wait)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement