Advertisement
Guest User

Professor Liar

a guest
Dec 4th, 2012
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.45 KB | None | 0 0
  1. import os
  2. import time
  3. import random
  4.  
  5. def loadDecks(source=os.getcwd()+"\decks.txt"): #assumes the deck is named "deck.txt"
  6.     file=open(source,"r")                       #and is in same directory as the script
  7.     deck1=[]
  8.     deck2=[]
  9.     line=file.readline().strip()
  10.     while line!="%":
  11.         deck1+=[line]
  12.         line=file.readline().strip()
  13.     line=file.readline().strip()
  14.     while line!="%":#% is a sentinal value
  15.         deck2+=[line]
  16.         line=file.readline().strip()
  17.     file.close()
  18.     return [deck1,deck2]
  19.  
  20. def makeTopic(deck1, deck2):
  21.     topic=random.choice(deck2)
  22.     nounnum=topic.count("_") #the 4 line blanks are replaced with one line blanks
  23.     nouns=[]
  24.     while len(nouns)<nounnum:
  25.         newnoun=random.choice(deck1)
  26.         if newnoun not in nouns:
  27.             nouns+=[newnoun]
  28.     phrase=''
  29.     y=0
  30.     if(topic[0]=="_"):
  31.         phrase=nouns[-1]
  32.         nouns.pop()
  33.         y=1
  34.     for x in range(1,len(topic)):
  35.         if topic[x]=="_":
  36.             phrase=phrase+topic[y:x]+nouns[-1]
  37.             nouns.pop()
  38.             y=x+1
  39.     phrase=phrase+topic[y:]
  40.     print(phrase)
  41.  
  42. def roundTimeout(t):
  43.     print("Press Ctrl+C if the current player fails")
  44.     try:
  45.         print("time:",t)
  46.         cyc=0
  47.         while t>.5:
  48.             time.sleep(.5)
  49.             t-=.5
  50.             cyc+=1
  51.             if cyc==20:
  52.                 cyc=0
  53.                 print("time:",t)
  54.         time.sleep(t)
  55.         print(" ")
  56.         print("Time up! 1 point awarded!")
  57.         print(" ")
  58.         return 1
  59.     except:
  60.         print(" ")
  61.         print("Current player has failed. No points awarded")
  62.         print(" ")
  63.         return 0
  64.    
  65. def play(players,points,roundlength,deck1,deck2):
  66.     score=[]
  67.     turn=0
  68.     for x in range(players):
  69.         score+=[0]
  70.     while max(score)<points:
  71.         print("player",turn+1,"'s turn")
  72.         print("press enter when ready")
  73.         input()
  74.         makeTopic(deck1,deck2)
  75.         score[turn]+=roundTimeout(roundlength)
  76.         turn+=1
  77.         if(turn>players-1):
  78.             turn = 0
  79.         print(" player  |  score")
  80.         for x in range(len(score)):
  81.             print("   %i     |    %i  "%(x+1,score[x]))
  82.         print(" ")
  83.     turn-=1
  84.     if turn<0:
  85.         turn=players-1
  86.     print("player",turn+1,"wins!!!")
  87.     print("press enter to exit")
  88.     input()
  89.  
  90.  
  91. decks=loadDecks()
  92. n=int(input("number of players? "))
  93. print(" ")
  94. play(n,5,90.0,decks[0],decks[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement