added "info" and "wear" use functions, and fixed many bugs related to storing things by ID.

This commit is contained in:
Patrick Marsee 2019-05-28 14:23:15 -04:00
parent 1b41c46105
commit 8355dccb33
4 changed files with 165 additions and 44 deletions

View file

@ -56,6 +56,7 @@ class GameShell(Shell):
self.registerAlias('run', ['go', '-r'])
self.gameBase.registerIO('container', self.container)
self.gameBase.registerIO('dialog', self.dialog)
self.gameBase.registerIO('info', self.info)
# Helper functions
@ -212,6 +213,9 @@ If -l is given, a map legend will be printed under the map."""
ret.append("Player name:{0:.>68}".format(self.gameBase.playerName))
ret.append("Player position:{0:.>64}".format("{0}{1}".format(self.gameBase.numberToLetter(self.gameBase.playerx), self.gameBase.playery)))
ret.append("Prev. position:{0:.>65}".format("{0}{1}".format(self.gameBase.numberToLetter(self.gameBase.prevx), self.gameBase.prevy)))
ret.append("Inventory:")
for i in self.gameBase.playerInv:
ret.append("{0:<8}: {1}".format(i, self.gameBase.playerInv[i].name))
ret.append("Things:\nID Name X Y")
for i in self.gameBase.level.things:
j = self.gameBase.level.things[i]
@ -224,7 +228,7 @@ If -l is given, a map legend will be printed under the map."""
return
def inv(self, args):
print('\n'.join([i for i in self.gameBase.playerInv]))
print('\n'.join([self.gameBase.playerInv[i].name for i in self.gameBase.playerInv]))
def container(self, inv, cont):
"""container IO"""
@ -236,7 +240,7 @@ If -l is given, a map legend will be printed under the map."""
longestLen = len(i)
longestStr = i
if longestLen > 0:
print('{{0:<{0}}}{1}'.format(longestLen+2, "Container:").format("Inv:"))
print('{{0:<{0}}}{1}'.format(max(6, longestLen+2), "Container:").format("Inv:"))
i = 0
invKeys = tuple(inv.keys())
while i < len(invKeys) and i < len(cont):
@ -264,7 +268,7 @@ If -l is given, a map legend will be printed under the map."""
thing = ' '.join(instr[1:])
for i in range(len(cont)):
if thing == cont[i].name:
inv[cont[i].name] = cont[i]
inv[cont[i].thingID] = cont[i]
del cont[i]
timeSpent += 0.5
print("{0} taken.".format(thing))
@ -273,15 +277,36 @@ If -l is given, a map legend will be printed under the map."""
# store something in the container
if instr[1] == "the":
del instr[1]
thing = ' '.join(instr[1:])
if thing in inv:
cont.append(inv[thing])
del inv[thing]
print("{0} stored.".format(thing))
timeSpent += 0.5
thingName = ' '.join(instr[1:])
for i in inv:
thing = inv[i].name
if thing == thingName:
cont.append(inv[i])
del inv[i]
print("{0} stored.".format(thing))
timeSpent += 0.5
break # so that all things with the same name don't get stored
instr = input("Take, store, or exit: ")
return inv, cont, timeSpent
def info(self, items):
"""IO for collections of information"""
charsRead = 0
for i in items:
print(' ', i)
instr = input("Choose an item to view, or exit: ")
while instr != 'exit':
if instr in items:
print(_tw.fill(items[instr], width = TERM_SIZE))
charsRead += len(items[instr])
else:
print('{} not here.'.format(instr))
input('<strike RETURN>')
for i in items:
print(' ', i)
instr = input("Choose an item to view, or exit: ")
return charsRead / 27 # based on average 250 words per minute, and word length of 5.5 + 1 for space.
def dialog(self, dialogObj):
if 'opener' in dialogObj:
print(_tw.fill(dialogObj['opener'], width = TERM_SIZE))