lolamontes69

memoryGame.py Friday night entertainment

Oct 19th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 13.18 KB | None | 0 0
  1. """ Note uses espeak to vocalize """
  2.  
  3. from random import randint
  4. import subprocess
  5. import os as os
  6. from time import sleep
  7.  
  8. def execute_unix(inputcommand):
  9.    p = subprocess.Popen(inputcommand, stdout=subprocess.PIPE, shell=True)
  10.    (output, err) = p.communicate()
  11.    return output
  12.  
  13. # Expanding phrase
  14. def memoryGame():
  15.     answer=""
  16.     wordlist = ['frog','sheep','cow','cat','tofu','cuddle','kiss','shark','elvis','you','me','is','then','on','with']
  17.     c = "Just repeat everything I say. And try not to make any typing errors or you will be sucked to death by homosexual robots."
  18.     b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  19.     print c
  20.     execute_unix(b)
  21.     sleep(2)
  22.     count = 0
  23.     while 1:
  24.         ch=randint(1,len(wordlist))
  25.         if count==0: answer+=wordlist[ch-1]
  26.         else: answer+=' '+wordlist[ch-1]
  27.         b = 'espeak -ven+f3 -k5 -s140 --punct="<characters>" "%s" 2>>/dev/null' % answer
  28.         execute_unix(b)
  29.         print "\n\n\n     ",answer
  30.         sleep(2)
  31.         os.system('clear')
  32.         c = "What did I just say?"
  33.         b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  34.         execute_unix(b)
  35.         print c
  36.         guess = str(raw_input('Enter guess >'))
  37.         count+=1
  38.         if guess!=answer:
  39.             c = "The answer was %s, you goofed on Round %s . Homosexual robots have been dispatched." % (answer, count)
  40.             b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  41.             print c
  42.             execute_unix(b)
  43.             sleep(1)
  44.             break
  45.         elif guess==answer:
  46.             c = "Good. Next."
  47.             b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  48.             print c
  49.             execute_unix(b)
  50.             sleep(1)
  51.             os.system('clear')
  52.  
  53. # Multiple phrases of expanding length
  54. def memoryGame1():
  55.     answer=""
  56.     pleng=5
  57.     wordlist = ['frog','sheep','cow','cat','tofu','cuddle','kiss','shark','elvis','you','me','is','then','on','with']
  58.     c = "Just repeat everything I say. And try not to make any typing errors or you will be sucked to death by homosexual robots."
  59.     b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  60.     print c
  61.     execute_unix(b)
  62.     sleep(2)
  63.     count = 0
  64.     while 1:
  65.         answer=""
  66.         count1=0
  67.         for a in range(pleng):
  68.             ch=randint(1,len(wordlist))
  69.             if count1==0: answer+=wordlist[ch-1]
  70.             else: answer+=' '+wordlist[ch-1]
  71.             count1+=1
  72.         b = 'espeak -ven+f3 -k5 -s140 --punct="<characters>" "%s" 2>>/dev/null' % answer
  73.         execute_unix(b)
  74.         print "\n\n\n     ",answer
  75.         sleep(2)
  76.         os.system('clear')
  77.         c = "What did I just say?"
  78.         b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  79.         execute_unix(b)
  80.         print c
  81.         guess = str(raw_input('Enter guess >'))
  82.         count+=1
  83.         if count%8==0: pleng += 1
  84.         if guess!=answer:
  85.             c = "The answer was %s, you goofed on Round %s . Homosexual robots have been dispatched." % (answer, count)
  86.             b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  87.             print c
  88.             execute_unix(b)
  89.             sleep(1)
  90.             break
  91.         elif guess==answer:
  92.             c = "Good. Next."
  93.             b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  94.             print c
  95.             execute_unix(b)
  96.             sleep(1)
  97.             os.system('clear')
  98.  
  99. # Multiple phrases of random length(3,8)
  100. def memoryGame2():
  101.     answer=""
  102.     wordlist = ['frog','sheep','cow','cat','tofu','cuddle','kiss','shark','elvis','you','me','is','then','on','with']
  103.     c = "Just repeat everything I say. And try not to make any typing errors or you will be sucked to death by homosexual robots."
  104.     b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  105.     print c
  106.     execute_unix(b)
  107.     sleep(2)
  108.     count = 0
  109.     while 1:
  110.         answer=""
  111.         count1=0
  112.         pleng=randint(3,8)
  113.         for a in range(pleng):
  114.             ch=randint(1,len(wordlist))
  115.             if count1==0: answer+=wordlist[ch-1]
  116.             else: answer+=' '+wordlist[ch-1]
  117.             count1+=1
  118.         b = 'espeak -ven+f3 -k5 -s140 --punct="<characters>" "%s" 2>>/dev/null' % answer
  119.         execute_unix(b)
  120.         print "\n\n\n     ",answer
  121.         sleep(2)
  122.         os.system('clear')
  123.         c = "What did I just say?"
  124.         b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  125.         execute_unix(b)
  126.         print c
  127.         guess = str(raw_input('Enter guess >'))
  128.         count+=1
  129.         if guess!=answer:
  130.             c = "The answer was %s, you goofed on Round %s . Homosexual robots have been dispatched." % (answer, count)
  131.             b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  132.             print c
  133.             execute_unix(b)
  134.             sleep(1)
  135.             break
  136.         elif guess==answer:
  137.             c = "Good. Next."
  138.             b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  139.             print c
  140.             execute_unix(b)
  141.             sleep(1)
  142.             os.system('clear')
  143.  
  144. def memoryGame3():
  145.     word=""; answer=""; range1=1
  146.     wordlist = ['frog','sheep','cow','cat','tofu','cuddle','kiss','shark','elvis','you','me','is','then','on','with']
  147.     c = "I am going to say a word, then another one. I want you to repeat the word I said before it each time. Try not to make any typing errors, or you will be sucked to death by homosexual robots."
  148.     b = 'espeak -ven+f3 -k5 -s180 --punct="<characters>" "%s" 2>>/dev/null' % c
  149.     print c
  150.     execute_unix(b)
  151.     sleep(2)
  152.     count = 0
  153.     while 1:
  154.         if count==0:
  155.             ch=randint(1,len(wordlist))
  156.             answer=wordlist[ch-1]
  157.             b = 'espeak -ven+f3 -k5 -s140 --punct="<characters>" "%s" 2>>/dev/null' % answer
  158.             execute_unix(b)
  159.             print "\n\n\n     ",answer
  160.             sleep(1)
  161.             os.system('clear')
  162.             count+=1
  163.         elif count!=0:
  164.             word=""
  165.             count1=0
  166.             for a in range(range1):
  167.                 ch=randint(1,len(wordlist))
  168.                 if count1==0:
  169.                     word+=wordlist[ch-1]
  170.                     count1+=1
  171.                 else: word+=' '+wordlist[ch-1]
  172.             b = 'espeak -ven+f3 -k5 -s140 --punct="<characters>" "%s" 2>>/dev/null' % word
  173.             execute_unix(b)
  174.             print "\n\n\n     ",word
  175.             sleep(2)
  176.             os.system('clear')
  177.             c = "What did I say before?"
  178.             b = 'espeak -ven+f3 -k5 -s180 --punct="<characters>" "%s" 2>>/dev/null' % c
  179.             execute_unix(b)
  180.             print c
  181.             guess = str(raw_input('Enter guess >'))
  182.             count+=1
  183.             if count % 3 == 0: range1+=1
  184.             if guess!=answer:
  185.                 c = "The answer was %s, you goofed on Round %s . Homosexual robots have been dispatched." % (answer, count)
  186.                 b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  187.                 print c
  188.                 execute_unix(b)
  189.                 sleep(1)
  190.                 break
  191.             elif guess==answer:
  192.                 c = "Good. Next."
  193.                 b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  194.                 print c
  195.                 execute_unix(b)
  196.                 sleep(1)
  197.                 os.system('clear')
  198.                 answer=word
  199.  
  200. # Repeat words in reverse order.
  201. def memoryGame4():
  202.     wordlist = ['frog','sheep','cow','cat','tofu','cuddle','kiss','shark','elvis','you','me','is','then','on','with']
  203.     c = "Just reverse the word order of everything I say. And try not to make any typing errors or you will be sucked to death by homosexual robots."
  204.     b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  205.     print c; execute_unix(b); sleep(2)
  206.     while 1:
  207.         say=""; count = 0
  208.         for a in range(2):
  209.             ch=randint(1,len(wordlist))
  210.             if count==0: say+=wordlist[ch-1]; count+=1
  211.             else: say+=' '+wordlist[ch-1]
  212.         b = 'espeak -ven+f3 -k5 -s140 --punct="<characters>" "%s" 2>>/dev/null' % say
  213.         execute_unix(b)
  214.         print "\n\n\n     ",say
  215.         ans = say.split(); ans.reverse(); answer = ' '.join(ans)
  216.         sleep(2); os.system('clear')
  217.         c = "Repeat the words in reverse order?"
  218.         b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  219.         execute_unix(b); print c
  220.         guess = str(raw_input('Enter guess >'))
  221.         if guess!=answer:
  222.             c = "The answer was %s, you dun goofed. Homosexual robots have been dispatched." % answer
  223.             b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  224.             print c; execute_unix(b); sleep(1)
  225.             break
  226.         elif guess==answer:
  227.             c = "Good. Next."
  228.             b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  229.             print c; execute_unix(b); sleep(1)
  230.             os.system('clear')
  231.  
  232. # repeat the phrase literally backwards
  233. def memoryGame5():
  234.     wordlist = ['frog','sheep','cow','cat','tofu','cuddle','kiss','shark','elvis','you','me','is','then','on','with']
  235.     c = "Just repeat everything I say backwards. And try not to make any typing errors or you will be sucked to death by homosexual robots."
  236.     b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  237.     print c; execute_unix(b); sleep(2)
  238.     while 1:
  239.         say=""; count = 0
  240.         for a in range(2):
  241.             ch=randint(1,len(wordlist))
  242.             if count==0: say+=wordlist[ch-1]; count+=1
  243.             else: say+=' '+wordlist[ch-1]
  244.         b = 'espeak -ven+f3 -k5 -s140 --punct="<characters>" "%s" 2>>/dev/null' % say
  245.         execute_unix(b)
  246.         print "\n\n\n     ",say
  247.         answer = say[::-1]
  248.         sleep(2); os.system('clear')
  249.         c = "Repeat the words backwards?"
  250.         b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  251.         execute_unix(b); print c
  252.         guess = str(raw_input('Enter guess >'))
  253.         if guess!=answer:
  254.             c = "The answer was %s, you dun goofed. Homosexual robots have been dispatched." % answer
  255.             b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  256.             print c; execute_unix(b); sleep(1)
  257.             break
  258.         elif guess==answer:
  259.             c = "Good. Next."
  260.             b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  261.             print c; execute_unix(b); sleep(1)
  262.             os.system('clear')
  263.  
  264. # Remember the first phrase forget the others.
  265. def memoryGame6():
  266.     os.system('clear')
  267.     answer=""
  268.     pleng=5
  269.     wordlist = ['frog','sheep','cow','cat','tofu','cuddle','kiss','shark','elvis','you','me','is','then','on','with']
  270.     c = "Just repeat the first phrase I say and forget the ones after it. Try not to make any typing errors or you will be sucked to death by homosexual robots."
  271.     b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  272.     print c
  273.     execute_unix(b)
  274.     sleep(2)
  275.     count = 0
  276.     while 1:
  277.         c = "Remember this phrase."
  278.         b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  279.         print c
  280.         execute_unix(b)
  281.         sleep(2)
  282.         answer=""
  283.         count1=0
  284.         for a in range(pleng):
  285.             ch=randint(1,len(wordlist))
  286.             if count1==0: answer+=wordlist[ch-1]
  287.             else: answer+=' '+wordlist[ch-1]
  288.             count1+=1
  289.         b = 'espeak -ven+f3 -k5 -s140 --punct="<characters>" "%s" 2>>/dev/null' % answer
  290.         execute_unix(b)
  291.         print "\n\n\n     ",answer
  292.         sleep(2)
  293.         os.system('clear')
  294.         for f in range(4):
  295.             fanswer=""
  296.             count1=0
  297.             for a in range(pleng):
  298.                 ch=randint(1,len(wordlist))
  299.                 if count1==0: fanswer+=wordlist[ch-1]; count1+=1
  300.                 else: fanswer+=' '+wordlist[ch-1]
  301.             b = 'espeak -ven+f3 -k5 -s140 --punct="<characters>" "%s" 2>>/dev/null' % fanswer
  302.             execute_unix(b)
  303.             print "\n\n\n     ",fanswer
  304.             sleep(2)
  305.         c = "What did I ask you to remember?"
  306.         b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  307.         execute_unix(b)
  308.         print c
  309.         guess = str(raw_input('Enter guess >'))
  310.         count+=1
  311.         if count%8==0: pleng += 1
  312.         if guess!=answer:
  313.             c = "The answer was %s, you goofed on Round %s . Homosexual robots have been dispatched." % (answer, count)
  314.             b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  315.             print c
  316.             execute_unix(b)
  317.             sleep(1)
  318.             break
  319.         elif guess==answer:
  320.             c = "Good. Next."
  321.             b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  322.             print c
  323.             execute_unix(b)
  324.             sleep(1)
  325.             os.system('clear')
Advertisement
Add Comment
Please, Sign In to add comment