In [48]:
f = 'usrattack.txt'
text = open(f)
text = text.read()
text = [string.strip(text).replace("star", "").replace(" ", "").replace('\t','')]
In [26]:
print text
In [29]:
text_file = open("usrattack.txt", "w")
text_file.write("%s" % text)
text_file.close()
In [22]:
In [24]:
Out[24]:
In [6]:
import os.path
import sys
import random
import string
from time import sleep
class NewUsr(object):
def __init__(self, name, age):
self.name = name
self.age = age
def UsrData():
pass
class AIDict(object):
def importData(self, filename1, filename2):
usrtxt = open(filename1)
usrtxt = usrtxt.read()
self.usrKeywords = usrtxt.split('\n')
del(self.usrKeywords[-1])
aitxt= open(filename2)
aitxt = aitxt.read()
self.aiResponse = aitxt.split('\n')
del(self.aiResponse[-1])
class Scene(object):
def __init__(self, storytxt, usrtxt, failtxt):
self.storytxt = storytxt
self.usrtxt = usrtxt
self.failtxt = failtxt
def printline(self, textfile, x):
txt = open(textfile)
txt = txt.read()
txt = txt.split('-')
self.txt = txt
return self.txt[x]
def randline(self, textfile):
lines = open(textfile)
lines = lines.read()
lines = lines.split('-')
line = lines[random.randint(0,len(lines))]
return line
def printslow(self, textfile, x, y):
txt = open(textfile)
txt = txt.read()
txt = txt.split('-')
self.txt = txt
i = x
for line in self.txt[x:y]:
if self.txt[i] != None:
print self.txt[i]
i += 1
sleep(2)
pass
lives = [1,2,3]
usr = NewUsr('Laura Kraft', 30)
runAway = AIDict()
runAway.importData('usrRun.txt','aiRunresponse.txt')
attack = AIDict()
attack.importData('usrAttack.txt', 'aiAttackresponse.txt')
usrAction = [attack.usrKeywords, runAway.usrKeywords]
aiLines = [attack.aiResponse, runAway.aiResponse]
start = Scene('mainentry.txt','','')
date = Scene('dateEntry.txt', 'quotes.txt','datefail.txt')
job = Scene('','','')
fridge = Scene('','','')
In [53]:
usrinput = str(raw_input('In one word, what do you do? > ')).lower()
for i in range(0,len(usrAction)):
print 'In the for loop for the %r time' % i
if usrinput in usrAction[i]:
print 'usrinput in usrAction[%r] is True' % i
print aiLines[i][random.randint(0,len(aiLines[i]))]
break
print 'broke out of the loop'
In [60]:
usrinput = raw_input('what do you do? > ').lower()
# punctuation = '! @ # $ % ^ * ( ) _ - + = ~ ` ? " \' . , / \\'.split(' ')
usrinput = usrinput.split(' ')
for word in usrinput:
for i in range(0,len(usrAction)):
print 'in the loop for the %r time' % i
if word in usrAction[i]:
print 'usrinput in usrAction[%r] True' % i
print aiLines[i][random.randint(0,(len(aiLines[i][:])-1))]
break
print 'broke out of inner loop'
print 'broke out of the outer loop'
In [26]:
len(aiLines[1][-1])
Out[26]:
In [29]:
aiLines[1][64]
In [30]:
aiLines[1][2]
Out[30]:
In [31]:
len(aiLines[1][:])
Out[31]:
In [33]:
aiLines[1][4]
Out[33]:
In [39]:
print aiLines[i][random.randint(0,(len(aiLines[i][:])-1))]
In [61]:
usrinput = str(raw_input('In one word, what do you do? > ')).lower()
for i in range(0,len(usrAction)):
print 'in the loop for the %r time' % i
if usrinput in usrAction[i]:
print 'usrinput in usrAction[%r] is True' % i
print aiLines[i][random.randint(0,(len(aiLines[i][:])-1))]
In [62]:
print aiLines
In [12]:
usrinput = raw_input('what do you do? > ').lower()
usrinput = usrinput.split(' ')
keywords = False
for word in usrinput:
for i in range(0,len(usrAction)):
print 'in the loop for the %r time' % i
if word in usrAction[i]:
keywords = True
print 'usrinput in usrAction[%r] True' % i
print aiLines[i][random.randint(0,(len(aiLines[i][:])-1))]
print 'broke out of inner loop'
if keywords == False:
print date.printline(date.storytxt, -1)
sleep(2)
print date.randline(date.usrtxt)
sleep(2)
date.printslow(date.failtxt, 0, -1)
In [68]:
int
Out[68]:
In [69]:
10 is int
Out[69]:
In [3]:
print """
Welcome to NIGHTMARE()
It will be unpleasant...
"""
name = str(raw_input("Enter Usr Name > "))
age = 0
while int(age) not in range(1, 200):
age = str(raw_input("Enter your age > "))
if int(age) < 18:
print "Sorry this game is not age appropriate."
sys.exit(0)
lives = 0
while int(lives) not in range(1,11):
lives = raw_input("""
On a scale from one to ten,\n
how terrible would you like this game to be?
\n (10 being really terrible) > """)
lives = range(1, int(lives))
print lives
In [5]:
print name, aiLines[1][1]
In [7]:
lives = range(1, int(lives))
print lives
In [ ]: