In [48]:
f = 'usrattack.txt'
text = open(f)
text = text.read()
text = [string.strip(text).replace("star", "").replace(" ", "").replace('\t','')]


---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)
<ipython-input-48-864fa6ea1c0a> in <module>()
      2 
      3 f = 'usrattack.txt'
----> 4 text = open(f)
      5 text = text.read()
      6 text = [string.strip(text).replace("star", "").replace(" ", "").replace('\t','')]

IOError: [Errno 2] No such file or directory: 'usrattack.txt'

In [26]:
print text


['aggression\nbarrage\ncharge\nincursion\nintervention\nintrusion\ninvasion\noffensive\nonslaught\noutbreak\n\nraid\nrape\nskirmish\nstrike\nviolation\nadvance\nassailing\nblitz\nblitzkrieg\ndefilement\n\ndrive\nencounter\nencroachment\nforay\ninitiative\ninroad\nirruption\nmugging\noffense\nonrush\n\nonset\npush\nrush\nstorming\nthrust\nvolley\nassailment\ndirtydeed']

In [29]:
text_file = open("usrattack.txt", "w")
text_file.write("%s" % text)
text_file.close()

In [22]:



---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-22-cc07f6f3c434> in <module>()
----> 1 text.write(f)

AttributeError: 'str' object has no attribute 'write'

In [24]:



Out[24]:
str

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 one word, what do you do? > poop then run
In the for loop for the 0 time
In the for loop for the 1 time
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'


what do you do? > poop then RUN
in the loop for the 0 time
in the loop for the 1 time
broke out of inner loop
in the loop for the 0 time
in the loop for the 1 time
broke out of inner loop
in the loop for the 0 time
in the loop for the 1 time
usrinput in usrAction[1] True
The floor turns to lava and you are instantly incenerated!
broke out of inner loop
broke out of the outer loop

In [26]:
len(aiLines[1][-1])


Out[26]:
66

In [29]:
aiLines[1][64]


---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-29-0a61a1617d89> in <module>()
----> 1 aiLines[1][64]

IndexError: list index out of range

In [30]:
aiLines[1][2]


Out[30]:
'You realize that you are actually in a wormhole!'

In [31]:
len(aiLines[1][:])


Out[31]:
5

In [33]:
aiLines[1][4]


Out[33]:
"You can't do anything! Are you dreaming that you're dreaming!???!?"

In [39]:
print aiLines[i][random.randint(0,(len(aiLines[i][:])-1))]


The floor turns to lava and you are instantly incenerated!

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 one word, what do you do? > poop then run
in the loop for the 0 time
in the loop for the 1 time

In [62]:
print aiLines


[['You lash out but your arms dissolve into dust :0', 'Your efforts are futile', 'Your uncle burst out his chest with a dead octopus and attacks you', "You can't seem to do any damage!", 'You try to move but you feel as though you are tied down.'], ['You attempt to get away, but you have no feet!', 'The floor turns to lava and you are instantly incenerated!', 'You realize that you are actually in a wormhole!', "Wait, you're not dreaming, you are in a spaceship under deep sedation.", "You can't do anything! Are you dreaming that you're dreaming!???!?"]]

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)


what do you do? > run
in the loop for the 0 time
in the loop for the 1 time
usrinput in usrAction[1] True
You attempt to get away, but you have no feet!
broke out of inner loop

In [68]:
int


Out[68]:
int

In [69]:
10 is int


Out[69]:
False

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


Welcome to NIGHTMARE()
It will be unpleasant...

Enter Usr Name > poop
Enter your age > 19

    On a scale from one to ten,

    how terrible would you like this game to be?
    
 (10 being really terrible) > 3
[1, 2]

In [5]:
print name, aiLines[1][1]


poop The floor turns to lava and you are instantly incenerated!

In [7]:
lives = range(1, int(lives))
print lives


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-2463fdb4a080> in <module>()
----> 1 lives = range(1, int(lives))
      2 print lives

TypeError: int() argument must be a string or a number, not 'list'

In [ ]: