From 740833541b877e4cd67cee0eb88c337bd1bbbe9c Mon Sep 17 00:00:00 2001 From: Olli Graf Date: Mon, 20 Jun 2022 18:00:34 +0200 Subject: [PATCH] Henry spricht wieder. Boxsack ist benutzbar. --- ActionModul.py | 19 ++++++++++-------- HilfeModul.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++- World.py | 14 +++++++++++++ WorldParser.py | 14 +++++++++++++ world.xml | 8 +++----- 5 files changed, 94 insertions(+), 14 deletions(-) diff --git a/ActionModul.py b/ActionModul.py index c7916ac..6f4d0aa 100644 --- a/ActionModul.py +++ b/ActionModul.py @@ -2,6 +2,7 @@ import logging from ActionBasics import ActionBasics +import HilfeModul class ActionModul(ActionBasics): @@ -14,6 +15,8 @@ class ActionModul(ActionBasics): def __init__(self, world): super().__init__(world) + self.hilfemodul = HilfeModul.HilfeModul(world) + def warte(self): print('Du wartest') @@ -144,7 +147,9 @@ class ActionModul(ActionBasics): self.world.printText('graböffnung') self.world.aktuellerRaum.ausgaenge[self.world.SUED] = self.world.RAUM_GRAB self.ausDemInventar(item) - else: + elif self.isItem(item,self.world.ITEM_BOXSACK): + self.schlage(parsedCommand) + else: self.setFehler('Nichts passiert.') @@ -346,9 +351,7 @@ class ActionModul(ActionBasics): item = self.world.findItemInAktuellerRaum(parsedCommand.gegenstand) if item != None: - #alter Code! - if item.id == 8: - self.world.stdscr.addstr('Du ziehst den Hebel und es passiert.... nichts!') + pass else: self.setFehler('Das sehe ich hier nicht.') @@ -510,10 +513,7 @@ class ActionModul(ActionBasics): self.setFehler(f'{parsedCommand.gegenstand} ist nicht im Raum.') def hilfe(self,parsedCommand): - if parsedCommand.gegenstand == 'befehle': - self.world.printBefehle() - else: - self.world.printText('hilfe') + self.hilfemodul.hilfe(parsedCommand.gegenstand) def geheNachItem(self,parsedCommand): item = self.world.findItemInAktuellerRaum(parsedCommand.gegenstand) @@ -556,6 +556,9 @@ class ActionModul(ActionBasics): self.geheNach(richtung) elif richtung == 'rauf': self.rauf() + self.geheNach(richtung) + elif richtung == 'runter': + self.runter() else: self.geheNachItem(parsedCommand) diff --git a/HilfeModul.py b/HilfeModul.py index fa035b8..45876c7 100644 --- a/HilfeModul.py +++ b/HilfeModul.py @@ -1,10 +1,61 @@ import logging +import FileReader class HilfeModul(): + def isBlank(self,str): + if str != None and len(str.strip()) == 0: + return True + return False + def __init__(self, world): self.world = world + 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): - \ No newline at end of file + 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 \ No newline at end of file diff --git a/World.py b/World.py index d6573b0..1fac69b 100644 --- a/World.py +++ b/World.py @@ -21,6 +21,20 @@ class World: self.waitForCR() 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): self.clearScreen() s = self.stdscr diff --git a/WorldParser.py b/WorldParser.py index 3c879a8..758e4ea 100644 --- a/WorldParser.py +++ b/WorldParser.py @@ -30,6 +30,17 @@ class WorldParser(): logging.error(f'keine Beschreibung für Item {itemid} - {item.name}') 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): @@ -83,6 +94,9 @@ class WorldParser(): key = befehl.attrib['key'] command = Befehl(name,id,key) + if id in self.world.befehle: + raise ValueError(f'doppelte Befehl-Id {id}') + self.world.befehle[id] = command # Adjektive for adj in root.findall('adjektive/adjektiv'): diff --git a/world.xml b/world.xml index 574be11..613009d 100644 --- a/world.xml +++ b/world.xml @@ -288,7 +288,7 @@ Du stehst in der Küche. In der Ecke steht ein Kühlschrank. - + @@ -306,10 +306,8 @@ Du stehst in der Küche. In der Ecke steht ein Kühlschrank. - - @@ -319,7 +317,7 @@ Du stehst in der Küche. In der Ecke steht ein Kühlschrank. - + @@ -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 Aufgabe gibt dir jemand im Spiel. - + 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. Leider erfolglos. Die Karte, die ich mir mühsam aus Hinweisen erstellt hatte, wurde mir von einem hinterlistigen Zwerg entwendet.