Henry spricht wieder.

Boxsack ist benutzbar.
This commit is contained in:
Olli Graf
2022-06-20 18:00:34 +02:00
parent e1bf16aa96
commit 740833541b
5 changed files with 94 additions and 14 deletions

View File

@@ -2,6 +2,7 @@
import logging import logging
from ActionBasics import ActionBasics from ActionBasics import ActionBasics
import HilfeModul
class ActionModul(ActionBasics): class ActionModul(ActionBasics):
@@ -14,6 +15,8 @@ class ActionModul(ActionBasics):
def __init__(self, world): def __init__(self, world):
super().__init__(world) super().__init__(world)
self.hilfemodul = HilfeModul.HilfeModul(world)
def warte(self): def warte(self):
print('Du wartest') print('Du wartest')
@@ -144,7 +147,9 @@ class ActionModul(ActionBasics):
self.world.printText('graböffnung') self.world.printText('graböffnung')
self.world.aktuellerRaum.ausgaenge[self.world.SUED] = self.world.RAUM_GRAB self.world.aktuellerRaum.ausgaenge[self.world.SUED] = self.world.RAUM_GRAB
self.ausDemInventar(item) self.ausDemInventar(item)
else: elif self.isItem(item,self.world.ITEM_BOXSACK):
self.schlage(parsedCommand)
else:
self.setFehler('Nichts passiert.') self.setFehler('Nichts passiert.')
@@ -346,9 +351,7 @@ class ActionModul(ActionBasics):
item = self.world.findItemInAktuellerRaum(parsedCommand.gegenstand) item = self.world.findItemInAktuellerRaum(parsedCommand.gegenstand)
if item != None: if item != None:
#alter Code! pass
if item.id == 8:
self.world.stdscr.addstr('Du ziehst den Hebel und es passiert.... nichts!')
else: else:
self.setFehler('Das sehe ich hier nicht.') self.setFehler('Das sehe ich hier nicht.')
@@ -510,10 +513,7 @@ class ActionModul(ActionBasics):
self.setFehler(f'{parsedCommand.gegenstand} ist nicht im Raum.') self.setFehler(f'{parsedCommand.gegenstand} ist nicht im Raum.')
def hilfe(self,parsedCommand): def hilfe(self,parsedCommand):
if parsedCommand.gegenstand == 'befehle': self.hilfemodul.hilfe(parsedCommand.gegenstand)
self.world.printBefehle()
else:
self.world.printText('hilfe')
def geheNachItem(self,parsedCommand): def geheNachItem(self,parsedCommand):
item = self.world.findItemInAktuellerRaum(parsedCommand.gegenstand) item = self.world.findItemInAktuellerRaum(parsedCommand.gegenstand)
@@ -556,6 +556,9 @@ class ActionModul(ActionBasics):
self.geheNach(richtung) self.geheNach(richtung)
elif richtung == 'rauf': elif richtung == 'rauf':
self.rauf() self.rauf()
self.geheNach(richtung)
elif richtung == 'runter':
self.runter()
else: else:
self.geheNachItem(parsedCommand) self.geheNachItem(parsedCommand)

View File

@@ -1,10 +1,61 @@
import logging import logging
import FileReader
class HilfeModul(): class HilfeModul():
def isBlank(self,str):
if str != None and len(str.strip()) == 0:
return True
return False
def __init__(self, world): def __init__(self, world):
self.world = world self.world = world
def hilfe(self, command): def readTxt(self, datei):
logging.debug(f'öffne Hilfedatei {datei}')
reader = FileReader.FileReader(datei)
lines = reader.lines()
reader = None
# reader.close()
return lines
def hilfe(self, command):
generalHelp = True
if not self.isBlank(command):
helptxt = self.findHilfetext(command)
logging.debug(f'Hilfetext: {helptxt}')
if helptxt != None:
lines = self.readTxt(helptxt)
logging.debug(f'lines: {lines}')
self.world.printHilfe(lines)
generalHelp = False
if generalHelp:
if command == 'befehle':
self.world.printBefehle()
else:
self.world.printText('hilfe')
def findHilfetext(self, command):
logging.debug(f'suche Hilfetext zu {command}')
for cmdid in range(0,len(self.world.befehle)):
if str(cmdid) in self.world.befehle:
befehl = self.world.befehle[str(cmdid)]
logging.debug(f'cmdid= {cmdid}')
# logging.debug(f'vergleiche {befehl.name.lower()} mit {command.lower()}')
if befehl.name.lower() == command.lower():
logging.debug(f'gefundener Befehl: {befehl.name}')
return f'ascii/hilfe/cmd-{befehl.key}.txt'
return None

View File

@@ -21,6 +21,20 @@ class World:
self.waitForCR() self.waitForCR()
self.printRaum() self.printRaum()
def printHilfe(self,lines):
self.clearScreen()
s = self.stdscr
s.addstr(1,0, lines[0])
s.addstr(3,0, lines[2], curses.color_pair(2)) # Befehl
s.addstr(4,0, lines[3]) #Parameter
s.addstr(5,0, lines[4]) # siehe auch
s.addstr(8,0, lines[7]) #Text 1
s.addstr(9,0, lines[8]) #Text 2
if len(lines) == 10 :
s.addstr(10,0, lines[9]) #Text 3
self.waitForCR()
def printKarte(self): def printKarte(self):
self.clearScreen() self.clearScreen()
s = self.stdscr s = self.stdscr

View File

@@ -30,6 +30,17 @@ class WorldParser():
logging.error(f'keine Beschreibung für Item {itemid} - {item.name}') logging.error(f'keine Beschreibung für Item {itemid} - {item.name}')
raise ValueError('Text ' +textid + ' fehlt') raise ValueError('Text ' +textid + ' fehlt')
for raumid in self.world.raumliste:
raum = self.world.raumliste[raumid]
textid = 'raum-' +raumid
if textid in self.world.raumliste:
pass
else:
logging.warn(f' keine Beschreibung für Raum {raumid} - {raum.name}')
def parseWorld(self,filename): def parseWorld(self,filename):
@@ -83,6 +94,9 @@ class WorldParser():
key = befehl.attrib['key'] key = befehl.attrib['key']
command = Befehl(name,id,key) command = Befehl(name,id,key)
if id in self.world.befehle:
raise ValueError(f'doppelte Befehl-Id {id}')
self.world.befehle[id] = command self.world.befehle[id] = command
# Adjektive # Adjektive
for adj in root.findall('adjektive/adjektiv'): for adj in root.findall('adjektive/adjektiv'):

View File

@@ -288,7 +288,7 @@ Du stehst in der Küche. In der Ecke steht ein Kühlschrank.
<commandset> <commandset>
<command name='quit' id='0' key='0' /> <command name='quit' id='0' key='0' />
<command name='ende' id='0' key='0' /> <command name='ende' id='43' key='0' />
<command name='geh' id='1' key='1' /> <command name='geh' id='1' key='1' />
<command name='gehe' id='27' key='1' /> <command name='gehe' id='27' key='1' />
<command name='nimm' id='2' key='2' /> <command name='nimm' id='2' key='2' />
@@ -306,10 +306,8 @@ Du stehst in der Küche. In der Ecke steht ein Kühlschrank.
<command name='verliere' id='15' key='14' /> <command name='verliere' id='15' key='14' />
<command name='warte' id='16' key='15' /> <command name='warte' id='16' key='15' />
<command name='drücke' id='17' key='16' /> <command name='drücke' id='17' key='16' />
<command name='ende' id='18' key='0' />
<command name='schaue' id='18' key='3' /> <command name='schaue' id='18' key='3' />
<command name='ziehe' id='19' key='17' /> <command name='ziehe' id='19' key='17' />
<command name='benutze' id='20' key='18' />
<command name='stelle' id='21' key='19' /> <command name='stelle' id='21' key='19' />
<command name='stell' id='22' key='19' /> <command name='stell' id='22' key='19' />
<command name='öffne' id='23' key='20' /> <command name='öffne' id='23' key='20' />
@@ -319,7 +317,7 @@ Du stehst in der Küche. In der Ecke steht ein Kühlschrank.
<command name='schlage' id='29' key='24' /> <command name='schlage' id='29' key='24' />
<command name='boxe' id='30' key='24' /> <command name='boxe' id='30' key='24' />
<command name='norden' id='31' key='5' /> <command name='norden' id='31' key='5' />
<command name='süd' id='32' key='7' /> <command name='süden' id='32' key='7' />
<command name='westen' id='33' key='8' /> <command name='westen' id='33' key='8' />
<command name='sprich' id='34' key='25' /> <command name='sprich' id='34' key='25' />
<command name='leere' id='35' key='26' /> <command name='leere' id='35' key='26' />
@@ -593,7 +591,7 @@ Du stehst in der Küche. In der Ecke steht ein Kühlschrank.
Die Liste der möglichen Befehle erhälst du mit "hilfe befehle". Die Liste der möglichen Befehle erhälst du mit "hilfe befehle".
Die Aufgabe gibt dir jemand im Spiel. Die Aufgabe gibt dir jemand im Spiel.
</text> </text>
<text id='geist'> <text id='npc-4'>
Ich bin der Geist deines Großonkels Henry. Mein ganzes Leben habe ich damit verbracht, das Himmelsgrab der Azteken zu finden, wie zuvor Ich bin der Geist deines Großonkels Henry. Mein ganzes Leben habe ich damit verbracht, das Himmelsgrab der Azteken zu finden, wie zuvor
mein Vater. mein Vater.
Leider erfolglos. Die Karte, die ich mir mühsam aus Hinweisen erstellt hatte, wurde mir von einem hinterlistigen Zwerg entwendet. Leider erfolglos. Die Karte, die ich mir mühsam aus Hinweisen erstellt hatte, wurde mir von einem hinterlistigen Zwerg entwendet.