import os
import time
import random
def loadDecks(source=os.getcwd()+"\decks.txt"): #assumes the deck is named "deck.txt"
file=open(source,"r") #and is in same directory as the script
deck1=[]
deck2=[]
line=file.readline().strip()
while line!="%":
deck1+=[line]
line=file.readline().strip()
line=file.readline().strip()
while line!="%":#% is a sentinal value
deck2+=[line]
line=file.readline().strip()
file.close()
return [deck1,deck2]
def makeTopic(deck1, deck2):
topic=random.choice(deck2)
nounnum=topic.count("_") #the 4 line blanks are replaced with one line blanks
nouns=[]
while len(nouns)<nounnum:
newnoun=random.choice(deck1)
if newnoun not in nouns:
nouns+=[newnoun]
phrase=''
y=0
if(topic[0]=="_"):
phrase=nouns[-1]
nouns.pop()
y=1
for x in range(1,len(topic)):
if topic[x]=="_":
phrase=phrase+topic[y:x]+nouns[-1]
nouns.pop()
y=x+1
phrase=phrase+topic[y:]
print(phrase)
def roundTimeout(t):
print("Press Ctrl+C if the current player fails")
try:
print("time:",t)
cyc=0
while t>.5:
time.sleep(.5)
t-=.5
cyc+=1
if cyc==20:
cyc=0
print("time:",t)
time.sleep(t)
print(" ")
print("Time up! 1 point awarded!")
print(" ")
return 1
except:
print(" ")
print("Current player has failed. No points awarded")
print(" ")
return 0
def play(players,points,roundlength,deck1,deck2):
score=[]
turn=0
for x in range(players):
score+=[0]
while max(score)<points:
print("player",turn+1,"'s turn")
print("press enter when ready")
input()
makeTopic(deck1,deck2)
score[turn]+=roundTimeout(roundlength)
turn+=1
if(turn>players-1):
turn = 0
print(" player | score")
for x in range(len(score)):
print(" %i | %i "%(x+1,score[x]))
print(" ")
turn-=1
if turn<0:
turn=players-1
print("player",turn+1,"wins!!!")
print("press enter to exit")
input()
decks=loadDecks()
n=int(input("number of players? "))
print(" ")
play(n,5,90.0,decks[0],decks[1])