Dateien von pykerker übernommen.
This commit is contained in:
149
ActionModul.py
Normal file
149
ActionModul.py
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
class ActionModul:
|
||||||
|
|
||||||
|
def isBlank(self,str):
|
||||||
|
if str and len(str.strip()) == 0:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def __init__(self, world):
|
||||||
|
|
||||||
|
self.world = world
|
||||||
|
|
||||||
|
def warte(self):
|
||||||
|
print('Du wartest')
|
||||||
|
|
||||||
|
|
||||||
|
def inventar(self):
|
||||||
|
|
||||||
|
self.world.stdscr.addstr(12,0,'Du besitzt folgende Gegenstände:')
|
||||||
|
zeile=13
|
||||||
|
for itemid in self.world.inventar:
|
||||||
|
item = self.world.inventar[itemid]
|
||||||
|
self.world.stdscr.addstr(zeile,0,item.name)
|
||||||
|
zeile = zeile +1
|
||||||
|
|
||||||
|
def verliere(self,parsedCommand):
|
||||||
|
item = self.world.findItemImInventar(parsedCommand.gegenstand);
|
||||||
|
|
||||||
|
|
||||||
|
if item != None:
|
||||||
|
del self.world.inventar[item.id]
|
||||||
|
self.world.aktuellerRaum.items[item.id] = item
|
||||||
|
else:
|
||||||
|
self.setFehler("Diesen Gegenstand besitzt du nicht.")
|
||||||
|
|
||||||
|
def setFehler(self,text):
|
||||||
|
self.world.fehler =text
|
||||||
|
|
||||||
|
|
||||||
|
def stelle(self,parsedCommand):
|
||||||
|
item = self.world.findItemImInventar(parsedCommand.gegenstand);
|
||||||
|
|
||||||
|
if item != None:
|
||||||
|
logging.debug('stelle() item.id=' + str(item.id))
|
||||||
|
if item.id == '6':
|
||||||
|
self.world.aktuellerRaum.ausgaenge[self.world.NORD] = '5'
|
||||||
|
self.verliere(parsedCommand)
|
||||||
|
self.world.printText('1')
|
||||||
|
else:
|
||||||
|
self.setFehler("Diesen Gegenstand besitzt du nicht.")
|
||||||
|
|
||||||
|
def untersuche(self,parsedCommand):
|
||||||
|
logging.debug('untersuche() suche nach Gegenstand:' + parsedCommand.gegenstand)
|
||||||
|
item = self.world.findItemImInventarOderAktuellerRaum(parsedCommand.gegenstand)
|
||||||
|
|
||||||
|
if item != None:
|
||||||
|
if item.id == '10':
|
||||||
|
schluessel = self.world.findRaumItemById('11')
|
||||||
|
logging.debug('mache Gegenstand ' + schluessel.name + ' sichtbar')
|
||||||
|
schluessel.sichtbar = True
|
||||||
|
self.world.printText('2')
|
||||||
|
else:
|
||||||
|
self.world.printText('item-' + item.id)
|
||||||
|
else:
|
||||||
|
self.setFehler("diesen Gegenstand sehe ich hier nicht.")
|
||||||
|
|
||||||
|
def ziehe(self,parsedCommand):
|
||||||
|
item = self.world.findIteminAktuellerRaum(parsedCommand.gegenstand)
|
||||||
|
|
||||||
|
if item != None:
|
||||||
|
if item.id == 8:
|
||||||
|
self.world.stdscr.addstr('Du ziehst den Hebel und es passiert.... nichts!')
|
||||||
|
else:
|
||||||
|
self.setFehler("diesen Gegenstand sehe ich hier nicht.")
|
||||||
|
|
||||||
|
def nimm(self,parsedCommand):
|
||||||
|
item = self.world.findIteminAktuellerRaum(parsedCommand.gegenstand)
|
||||||
|
|
||||||
|
if item != None:
|
||||||
|
if item.imobil:
|
||||||
|
text = self.world.msg[item.pickupmsg]
|
||||||
|
|
||||||
|
if self.isBlank(item.pickupmsg):
|
||||||
|
self.setFehler('Das kannst du nicht mitnehmen')
|
||||||
|
else:
|
||||||
|
text = self.world.msg[item.pickupmsg]
|
||||||
|
self.setFehler(text)
|
||||||
|
else:
|
||||||
|
del self.world.aktuellerRaum.items[item.id]
|
||||||
|
self.world.inventar[item.id] = item
|
||||||
|
else:
|
||||||
|
self.setFehler("diesen Gegenstand sehe ich hier nicht.")
|
||||||
|
|
||||||
|
|
||||||
|
def gehe(self):
|
||||||
|
richtung = self.world.parsedCommand.gegenstand
|
||||||
|
print("gehe nach " + richtung)
|
||||||
|
|
||||||
|
if richtung == 'nord':
|
||||||
|
self.nord()
|
||||||
|
|
||||||
|
def geheNach(self,richtung):
|
||||||
|
raum = self.world.aktuellerRaum
|
||||||
|
|
||||||
|
if raum.ausgaenge[richtung]:
|
||||||
|
ausgang = raum.sucheRaumAusgang(richtung)
|
||||||
|
print("gefundener Ausgang: " + ausgang)
|
||||||
|
if ausgang != None:
|
||||||
|
raum = self.world.sucheRaum(ausgang)
|
||||||
|
print("gefundener Raum "+ raum.name)
|
||||||
|
else:
|
||||||
|
self.setFehler("In diese Richtung gibt's keine Ausgang!")
|
||||||
|
|
||||||
|
if raum != None:
|
||||||
|
self.world.aktuellerRaum = raum
|
||||||
|
else:
|
||||||
|
self.setFehler("In diese Richtung gibt's keine Ausgang!")
|
||||||
|
else:
|
||||||
|
self.setFehler("In diese Richtung kannst du nicht gehen")
|
||||||
|
|
||||||
|
def nord(self):
|
||||||
|
self.geheNach(self.world.NORD)
|
||||||
|
|
||||||
|
def sued(self):
|
||||||
|
self.geheNach(self.world.SUED)
|
||||||
|
|
||||||
|
def west(self):
|
||||||
|
self.geheNach(self.world.WEST)
|
||||||
|
|
||||||
|
def ost(self):
|
||||||
|
self.geheNach(self.world.OST)
|
||||||
|
|
||||||
|
def rauf(self):
|
||||||
|
self.geheNach(self.world.RAUF)
|
||||||
|
|
||||||
|
def runter(self):
|
||||||
|
self.geheNach(self.world.RUNTER)
|
||||||
|
|
||||||
|
def about(self):
|
||||||
|
print("Kerker Version " + self.world.VERSION)
|
||||||
|
self.world.waitForCR
|
||||||
|
|
||||||
|
def raumaction(self):
|
||||||
|
raumid = self.world.aktuellerRaum.id
|
||||||
|
|
||||||
|
print('Raumaction für Raum: ' + raumid)
|
||||||
|
|
||||||
|
|
9
ParsedCommand.py
Normal file
9
ParsedCommand.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
class ParsedCommand:
|
||||||
|
def __init__(self):
|
||||||
|
self.commandid = ''
|
||||||
|
self.verb = None
|
||||||
|
self.gegenstand = None
|
||||||
|
self.gegenstand2 = None
|
||||||
|
self.objekt = None
|
||||||
|
self.key = '-1'
|
||||||
|
|
172
World.py
Normal file
172
World.py
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
import WorldParser
|
||||||
|
import ParsedCommand
|
||||||
|
import ActionModul
|
||||||
|
import curses
|
||||||
|
from curses import wrapper
|
||||||
|
import logging
|
||||||
|
from os import system, name
|
||||||
|
|
||||||
|
|
||||||
|
class World:
|
||||||
|
|
||||||
|
def clearScreen(self):
|
||||||
|
self.stdscr.clear()
|
||||||
|
|
||||||
|
def printText(self,textid):
|
||||||
|
self.clearScreen()
|
||||||
|
self.stdscr.addstr(1,0,self.texte[textid].name)
|
||||||
|
self.waitForCR()
|
||||||
|
self.printRaum()
|
||||||
|
|
||||||
|
def waitForCR(self):
|
||||||
|
self.stdscr.addstr(0,0,'Taste für Weiter',curses.color_pair(1))
|
||||||
|
self.stdscr.getch()
|
||||||
|
|
||||||
|
|
||||||
|
def printRaum(self):
|
||||||
|
raum = self.aktuellerRaum
|
||||||
|
self.clearScreen()
|
||||||
|
|
||||||
|
if self.fehler != None and self.fehler != '':
|
||||||
|
self.stdscr.addstr(self.fehler,curses.color_pair(1))
|
||||||
|
|
||||||
|
self.stdscr.addstr(3,0,'aktueller Raum: ' + raum.name,curses.color_pair(3))
|
||||||
|
self.stdscr.addstr(4,0,raum.beschreibung)
|
||||||
|
self.stdscr.addstr(7,0,'Gegenstände: ' + str(raum.labelsGegenstaende()),curses.color_pair(2))
|
||||||
|
self.stdscr.addstr(8,0,'Personen: ' + str(raum.labelsPersonen()),curses.color_pair(2))
|
||||||
|
|
||||||
|
|
||||||
|
aus = raum.ausgaenge
|
||||||
|
self.stdscr.addstr(9,0,'mögliche Richtungen: ')
|
||||||
|
r = []
|
||||||
|
if aus[self.NORD] != '-1':
|
||||||
|
r.append('Norden')
|
||||||
|
if aus[self.OST] != '-1':
|
||||||
|
r.append('Osten')
|
||||||
|
if aus[self.WEST] != '-1':
|
||||||
|
r.append('Westen')
|
||||||
|
if aus[self.SUED] != '-1':
|
||||||
|
r.append('Süden')
|
||||||
|
if aus[self.RAUF] != '-1':
|
||||||
|
r.append('Rauf')
|
||||||
|
if aus[self.RUNTER] != '-1':
|
||||||
|
r.append('Runter')
|
||||||
|
|
||||||
|
richtungen =''
|
||||||
|
ixri = 0
|
||||||
|
win = curses.newwin(7,35,7,85)
|
||||||
|
win.box()
|
||||||
|
win.addstr('Ausgänge:')
|
||||||
|
for ri in r:
|
||||||
|
richtungen = richtungen + ri
|
||||||
|
win.addstr(ixri+1,1,ri)
|
||||||
|
if ixri +1 < len(r):
|
||||||
|
richtungen = richtungen + ', '
|
||||||
|
ixri = ixri +1
|
||||||
|
self.stdscr.addstr(9,22,richtungen)
|
||||||
|
self.stdscr.refresh()
|
||||||
|
win.refresh()
|
||||||
|
|
||||||
|
def sucheRaum(self,id):
|
||||||
|
for raumid in self.raumliste:
|
||||||
|
raum = self.raumliste[raumid]
|
||||||
|
if raum.id == id:
|
||||||
|
return raum
|
||||||
|
return None
|
||||||
|
|
||||||
|
def findItemImInventarOderAktuellerRaum(self,itemname):
|
||||||
|
item = self.findItemImInventar(itemname)
|
||||||
|
|
||||||
|
if item == None:
|
||||||
|
item = self.findIteminAktuellerRaum(itemname)
|
||||||
|
return item
|
||||||
|
|
||||||
|
|
||||||
|
def findIteminAktuellerRaum(self,itemname):
|
||||||
|
raum = self.aktuellerRaum
|
||||||
|
|
||||||
|
for itemid in raum.items:
|
||||||
|
item = raum.items[itemid]
|
||||||
|
logging.debug('raum.id=' + raum.id)
|
||||||
|
logging.debug('item.raumid=' + item.raumid)
|
||||||
|
logging.debug('findItemInAktuellerRaum() ' + itemname + '-' + item.name)
|
||||||
|
if item.raumid == raum.id and item.name == itemname:
|
||||||
|
return item
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def findRaumItemById(self,id):
|
||||||
|
raum = self.aktuellerRaum
|
||||||
|
|
||||||
|
for itemid in raum.items:
|
||||||
|
item = raum.items[itemid]
|
||||||
|
if item.raumid == raum.id and item.id == id:
|
||||||
|
return item
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def findItemImInventar(self,itemname):
|
||||||
|
|
||||||
|
for itemid in self.inventar:
|
||||||
|
if self.inventar[itemid].name == itemname:
|
||||||
|
return self.inventar[itemid]
|
||||||
|
return None
|
||||||
|
|
||||||
|
def ermittleBefehlId(self,befehl):
|
||||||
|
for id in self.befehle:
|
||||||
|
name = self.befehle[id].name
|
||||||
|
if name == befehl:
|
||||||
|
return id
|
||||||
|
return None
|
||||||
|
|
||||||
|
def removeSortouts(self,words):
|
||||||
|
w = []
|
||||||
|
for word in words:
|
||||||
|
if word not in self.sortouts:
|
||||||
|
w.append(word)
|
||||||
|
return w
|
||||||
|
|
||||||
|
|
||||||
|
def parseInput(self,input):
|
||||||
|
words = input.split(' ')
|
||||||
|
words = self.removeSortouts(words)
|
||||||
|
parsedCommand = ParsedCommand.ParsedCommand()
|
||||||
|
befehlid = self.ermittleBefehlId(words[0])
|
||||||
|
|
||||||
|
if befehlid != None:
|
||||||
|
befehl = self.befehle[befehlid]
|
||||||
|
parsedCommand.commandid = befehl.id
|
||||||
|
parsedCommand.key = befehl.key
|
||||||
|
|
||||||
|
if len(words) > 1:
|
||||||
|
parsedCommand.gegenstand = words[1]
|
||||||
|
if len(words) > 2:
|
||||||
|
parsedCommand.gegenstand2 = words[2]
|
||||||
|
|
||||||
|
return parsedCommand
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.raumliste = {}
|
||||||
|
self.msg = {}
|
||||||
|
self.personen = {}
|
||||||
|
self.bewegungen = {}
|
||||||
|
self.gegenstaende = {}
|
||||||
|
self.befehle = {}
|
||||||
|
self.inventar = {}
|
||||||
|
self.objekte = {}
|
||||||
|
self.sortouts = []
|
||||||
|
self.texte = {}
|
||||||
|
self.aktuellerRaum = None
|
||||||
|
self.parsedCommand = None
|
||||||
|
self.NOEXIT = '-1'
|
||||||
|
self.NORD = '0'
|
||||||
|
self.OST = '1'
|
||||||
|
self.SUED = '2'
|
||||||
|
self.WEST = '3'
|
||||||
|
self.RAUF = '4'
|
||||||
|
self.RUNTER = '5'
|
||||||
|
self.VERSION = '0.5'
|
||||||
|
self.fehler = ''
|
||||||
|
parser = WorldParser.WorldParser(self)
|
||||||
|
parser.parseWorld('world.xml')
|
||||||
|
|
120
WorldParser.py
Normal file
120
WorldParser.py
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
from data.Raum import Raum, Befehl, Gegenstand,Person,TextNode
|
||||||
|
import io
|
||||||
|
import logging
|
||||||
|
|
||||||
|
class WorldParser():
|
||||||
|
|
||||||
|
def __init__(self,world):
|
||||||
|
self.neuerRaum = None
|
||||||
|
self.world = world
|
||||||
|
self.textCount = 0
|
||||||
|
|
||||||
|
def parseWorld(self,filename):
|
||||||
|
tree = ET.parse(filename)
|
||||||
|
root = tree.getroot()
|
||||||
|
|
||||||
|
for item in root.findall('ebene/raum'):
|
||||||
|
id = item.attrib['id']
|
||||||
|
name = item.attrib['name']
|
||||||
|
beschreibung = ''
|
||||||
|
# Beschreibung
|
||||||
|
for text in item.iter():
|
||||||
|
if text != None and text.text != None:
|
||||||
|
beschreibung = beschreibung + text.text.strip()
|
||||||
|
# Ausgaenge
|
||||||
|
raum = Raum(name,id, beschreibung)
|
||||||
|
ausgaenge = item.findall('ausgang')
|
||||||
|
|
||||||
|
for ausgang in ausgaenge:
|
||||||
|
dir = ausgang.attrib['dir']
|
||||||
|
nachRaum = ausgang.attrib['nachRaum']
|
||||||
|
|
||||||
|
print('Raum: ' + raum.name + '- dir=' + dir + ',nachRaum=' + nachRaum)
|
||||||
|
if dir == 'Nord':
|
||||||
|
raum.ausgaenge[self.world.NORD] = nachRaum
|
||||||
|
elif dir == 'Sued':
|
||||||
|
raum.ausgaenge[self.world.SUED] = nachRaum
|
||||||
|
elif dir == 'West':
|
||||||
|
raum.ausgaenge[self.world.WEST] = nachRaum
|
||||||
|
elif dir == 'Ost':
|
||||||
|
raum.ausgaenge[self.world.OST] = nachRaum
|
||||||
|
elif dir == 'Rauf':
|
||||||
|
raum.ausgaenge[self.world.RAUF] = nachRaum
|
||||||
|
elif dir == 'Runter':
|
||||||
|
raum.ausgaenge[self.world.RUNTER] = nachRaum
|
||||||
|
|
||||||
|
|
||||||
|
self.world.raumliste[id] = raum
|
||||||
|
startr = root.find('startraum')
|
||||||
|
print(startr)
|
||||||
|
print(startr.attrib['id'])
|
||||||
|
startraum = self.world.sucheRaum(startr.attrib['id'])
|
||||||
|
self.world.aktuellerRaum = startraum
|
||||||
|
print('Startraum gefunden.')
|
||||||
|
print(startraum)
|
||||||
|
|
||||||
|
#Befehle
|
||||||
|
for befehl in root.findall('commandset/command'):
|
||||||
|
name = befehl.attrib['name']
|
||||||
|
id = befehl.attrib['id']
|
||||||
|
key = befehl.attrib['key']
|
||||||
|
command = Befehl(name,id,key)
|
||||||
|
|
||||||
|
self.world.befehle[id] = command
|
||||||
|
|
||||||
|
# Sortouts
|
||||||
|
for sortout in root.findall('sortouts/sortout'):
|
||||||
|
name = sortout.attrib['name']
|
||||||
|
self.world.sortouts.append(name)
|
||||||
|
# Messages
|
||||||
|
for msg in root.findall('messages/pickup'):
|
||||||
|
id = msg.attrib['id']
|
||||||
|
text = msg.attrib['text']
|
||||||
|
self.world.msg[id] = text
|
||||||
|
|
||||||
|
# Gegenstände
|
||||||
|
for item in root.findall('items/item'):
|
||||||
|
name = item.attrib['name']
|
||||||
|
id = item.attrib['id']
|
||||||
|
msgid = item.attrib['msgid']
|
||||||
|
raumid = item.attrib['raum']
|
||||||
|
gegenstand = Gegenstand(name,id,raumid)
|
||||||
|
imobil = item.attrib['imobil']
|
||||||
|
visible = item.attrib['visible']
|
||||||
|
raum = self.world.sucheRaum(raumid)
|
||||||
|
gegenstand.raum = raum.id
|
||||||
|
gegenstand.imobil = imobil.lower() in ['true','True','1']
|
||||||
|
logging.debug('itemid= ' + id + ',visible= ' + visible)
|
||||||
|
gegenstand.sichtbar = visible.lower() not in ['false','False','0']
|
||||||
|
logging.debug('Gegenstand ' + gegenstand.name + ' ist sichtbar: ' + str(gegenstand.sichtbar))
|
||||||
|
gegenstand.pickupmsg = msgid
|
||||||
|
print('Item ' + gegenstand.name + ' - Pickup: ' + gegenstand.pickupmsg)
|
||||||
|
|
||||||
|
raum.items[id] = gegenstand
|
||||||
|
self.world.gegenstaende[id] = gegenstand
|
||||||
|
|
||||||
|
# Personen
|
||||||
|
for item in root.findall('personen/person'):
|
||||||
|
name = item.attrib['name']
|
||||||
|
id = item.attrib['id']
|
||||||
|
move = item.attrib['bewegung']
|
||||||
|
|
||||||
|
raumid = item.attrib['raum']
|
||||||
|
person = Person(name,id,raum)
|
||||||
|
self.world.personen[id] = person
|
||||||
|
raum = self.world.sucheRaum(raumid)
|
||||||
|
raum.personen[raumid] = person
|
||||||
|
|
||||||
|
# Texte
|
||||||
|
for item in root.findall('texte/text'):
|
||||||
|
id = item.attrib['id']
|
||||||
|
print('Id: ' + id+ ' Text ' + item.text)
|
||||||
|
textnode = TextNode(id,item.text)
|
||||||
|
self.world.texte[id] = textnode
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
88
data/Raum.py
Normal file
88
data/Raum.py
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
class SuperNode:
|
||||||
|
|
||||||
|
def __init__(self,name,id):
|
||||||
|
self.name = name
|
||||||
|
self.id = id
|
||||||
|
|
||||||
|
class Raum(SuperNode):
|
||||||
|
|
||||||
|
def __init__(self,name,id,beschreibung):
|
||||||
|
|
||||||
|
super().__init__(name,id)
|
||||||
|
self.items ={}
|
||||||
|
self.personen = {}
|
||||||
|
self.beschreibung=beschreibung
|
||||||
|
self.pickupmsg = ''
|
||||||
|
self.ausgaenge = {
|
||||||
|
'0': '-1', # Nord
|
||||||
|
'1': '-1', # West
|
||||||
|
'2': '-1', # Sued
|
||||||
|
'3': '-1', # Ost
|
||||||
|
'4': '-1', # Rauf
|
||||||
|
'5': '-1', # Runter
|
||||||
|
}
|
||||||
|
|
||||||
|
def sucheRaumAusgang(self,richtung):
|
||||||
|
nachRaum = self.ausgaenge[richtung]
|
||||||
|
return nachRaum
|
||||||
|
|
||||||
|
def labelsPersonen(self):
|
||||||
|
labels = []
|
||||||
|
|
||||||
|
for persid in self.personen:
|
||||||
|
labels.append(self.personen[persid].name)
|
||||||
|
|
||||||
|
return labels
|
||||||
|
|
||||||
|
def labelsGegenstaende(self):
|
||||||
|
labels =[]
|
||||||
|
|
||||||
|
for itemid in self.items:
|
||||||
|
item = self.items[itemid]
|
||||||
|
logging.debug('labelsGegenstaende(): Item ' + self.items[itemid].name + ' ist ' + str(item.sichtbar))
|
||||||
|
if item.sichtbar:
|
||||||
|
labels.append(item.name)
|
||||||
|
|
||||||
|
return labels
|
||||||
|
|
||||||
|
|
||||||
|
class Befehl(SuperNode):
|
||||||
|
def __init__(self,command,id,key):
|
||||||
|
super().__init__(command,id)
|
||||||
|
self.command = command
|
||||||
|
self.key = key
|
||||||
|
|
||||||
|
class Ausgang(SuperNode):
|
||||||
|
def __init__(name,id,nachRaum):
|
||||||
|
super(name,id)
|
||||||
|
self.nachRaum = nachRaum
|
||||||
|
self.richtung = name
|
||||||
|
|
||||||
|
class Gegenstand(SuperNode):
|
||||||
|
def __init__(self,name,id,raumid):
|
||||||
|
super().__init__(name,id)
|
||||||
|
self.raumid = raumid
|
||||||
|
self.zustand = 0
|
||||||
|
self.sichtbar = True
|
||||||
|
self.imobil = False
|
||||||
|
self.GESCHLOSSEN = 0
|
||||||
|
self.OFFEN = 1
|
||||||
|
self.zustand = self.GESCHLOSSEN
|
||||||
|
|
||||||
|
class Person(SuperNode):
|
||||||
|
def __init__(self, name,id,raum):
|
||||||
|
super().__init__(name,id)
|
||||||
|
self.raum = raum
|
||||||
|
self.bewegung = []
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
class TextNode(SuperNode):
|
||||||
|
def __init__(self,id, text):
|
||||||
|
super().__init__(text, id)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
BIN
data/Raum.pyc
Normal file
BIN
data/Raum.pyc
Normal file
Binary file not shown.
1
data/__init__.py
Normal file
1
data/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
BIN
data/__init__.pyc
Normal file
BIN
data/__init__.pyc
Normal file
Binary file not shown.
BIN
data/__pycache__/Raum.cpython-36.pyc
Normal file
BIN
data/__pycache__/Raum.cpython-36.pyc
Normal file
Binary file not shown.
BIN
data/__pycache__/Raum.cpython-38.pyc
Normal file
BIN
data/__pycache__/Raum.cpython-38.pyc
Normal file
Binary file not shown.
BIN
data/__pycache__/SuperNode.cpython-36.pyc
Normal file
BIN
data/__pycache__/SuperNode.cpython-36.pyc
Normal file
Binary file not shown.
BIN
data/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
data/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
BIN
data/__pycache__/__init__.cpython-38.pyc
Normal file
BIN
data/__pycache__/__init__.cpython-38.pyc
Normal file
Binary file not shown.
81
kerker.py
Executable file
81
kerker.py
Executable file
@@ -0,0 +1,81 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
import World
|
||||||
|
import ActionModul
|
||||||
|
import signal
|
||||||
|
import sys
|
||||||
|
import logging
|
||||||
|
import curses
|
||||||
|
from curses import wrapper
|
||||||
|
|
||||||
|
def verarbeiteBefehl(parsedCommand):
|
||||||
|
id = parsedCommand.key
|
||||||
|
|
||||||
|
logging.debug(' Befehlkey: ' + id)
|
||||||
|
if id == '0':
|
||||||
|
sys.exit()
|
||||||
|
elif id == '1':
|
||||||
|
actionmodul.gehe(parsedCommand)
|
||||||
|
elif id == '2':
|
||||||
|
actionmodul.nimm(parsedCommand)
|
||||||
|
elif id == '3':
|
||||||
|
actionmodul.untersuche(parsedCommand)
|
||||||
|
elif id == '5':
|
||||||
|
actionmodul.nord()
|
||||||
|
elif id == '6':
|
||||||
|
actionmodul.ost()
|
||||||
|
elif id == '7':
|
||||||
|
actionmodul.sued()
|
||||||
|
elif id == '8':
|
||||||
|
actionmodul.west()
|
||||||
|
elif id == '9':
|
||||||
|
actionmodul.rauf()
|
||||||
|
elif id == '10':
|
||||||
|
actionmodul.runter()
|
||||||
|
elif id == '12':
|
||||||
|
actionmodul.inventar()
|
||||||
|
world.waitForCR()
|
||||||
|
elif id == '13':
|
||||||
|
actionmodul.about()
|
||||||
|
elif id == '14':
|
||||||
|
print('verliere: ' + parsedCommand.gegenstand)
|
||||||
|
actionmodul.verliere(parsedCommand)
|
||||||
|
elif id == '15':
|
||||||
|
actionmodul.warte()
|
||||||
|
elif id == '17':
|
||||||
|
actionmodul.ziehe(parsedCommand)
|
||||||
|
elif id == '19':
|
||||||
|
actionmodul.stelle(parsedCommand)
|
||||||
|
elif id == '-1':
|
||||||
|
world.fehler = 'Ich verstehe diesen Befehl nicht'
|
||||||
|
else:
|
||||||
|
world.fehler = 'nicht implementierter Befehl'
|
||||||
|
|
||||||
|
def handle_SIGINT(sig,frame):
|
||||||
|
logging.debug("CTRL-C abgefangen")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
logging.basicConfig(filename='kerker.log', level=logging.DEBUG)
|
||||||
|
signal.signal(signal.SIGINT,handle_SIGINT)
|
||||||
|
world = World.World()
|
||||||
|
logging.debug('World initialisiert')
|
||||||
|
actionmodul = ActionModul.ActionModul(world)
|
||||||
|
|
||||||
|
def inputLoop(stdscr):
|
||||||
|
world.stdscr = stdscr
|
||||||
|
curses.echo()
|
||||||
|
curses.init_pair(1,curses.COLOR_RED, curses.COLOR_WHITE)
|
||||||
|
curses.init_pair(2,curses.COLOR_GREEN, curses.COLOR_BLACK)
|
||||||
|
curses.init_pair(3,curses.COLOR_YELLOW, curses.COLOR_BLACK)
|
||||||
|
commandid = ''
|
||||||
|
while commandid != '0':
|
||||||
|
world.printRaum()
|
||||||
|
stdscr.addstr(11,0,'Was nun? ')
|
||||||
|
command = stdscr.getstr(11,10,40).decode(encoding="utf-8")
|
||||||
|
command = command.rstrip()
|
||||||
|
parsedCommand = world.parseInput(command)
|
||||||
|
commandid = parsedCommand.commandid
|
||||||
|
verarbeiteBefehl(parsedCommand)
|
||||||
|
actionmodul.raumaction()
|
||||||
|
|
||||||
|
wrapper(inputLoop)
|
7
parser/ParsedCommand.py
Normal file
7
parser/ParsedCommand.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
class ParsedCommand():
|
||||||
|
def __init__(self):
|
||||||
|
self.commandid = -1
|
||||||
|
self.verb = None
|
||||||
|
self.gegenstand = None
|
||||||
|
self.objekt = None
|
||||||
|
|
150
world.xml
Normal file
150
world.xml
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
<welt>
|
||||||
|
<startraum id='1' />
|
||||||
|
<ebene id='1' name='Keller'>
|
||||||
|
<raum id='1' name='Folterkammer'>
|
||||||
|
<ausgang dir='Nord' nachRaum='3' />
|
||||||
|
<ausgang dir='Sued' nachRaum='2' />
|
||||||
|
<beschreibung> Im Raum steht eine Streckbank, mit der du vermutlich bald nähere Bekanntschaft machen wirst.
|
||||||
|
An der Wand steht eine geöffnete eiserne Jungfrau mit furchterregenden spitzen, rostigen Dornen.</beschreibung>
|
||||||
|
</raum>
|
||||||
|
<raum id='2' name='Instrumentenraum'>
|
||||||
|
<ausgang dir='Nord' nachRaum='1' />
|
||||||
|
<beschreibung>
|
||||||
|
Hier lagern die Folterinstrumente. Du erkennst verschiede Zangen, Ketten, spitze Gegenstände und einige Utensilien, von denen du gar nicht wissen willst, welchen Zweck sie haben.
|
||||||
|
|
||||||
|
</beschreibung>
|
||||||
|
</raum>
|
||||||
|
<raum id='3' name='Gang'>
|
||||||
|
<ausgang dir='Sued' nachRaum='1' />
|
||||||
|
<!-- <ausgang dir='Nord' nachRaum='5' />-->
|
||||||
|
<ausgang dir='West' nachRaum='4' />
|
||||||
|
<beschreibung>
|
||||||
|
Der Gang verläuft von Süd nach Nord. Im Norden versperrt ein massives Gittertor den Weg.
|
||||||
|
</beschreibung>
|
||||||
|
</raum>
|
||||||
|
<raum id='4' name='Wachraum'>
|
||||||
|
<ausgang dir='Ost' nachRaum='3' />
|
||||||
|
<beschreibung>
|
||||||
|
Der Aufenthaltsraum der Wächter, hier stehen ein Tisch und vier Stühle.
|
||||||
|
An der Wand steht ein Gestell für Schwerter.
|
||||||
|
</beschreibung>
|
||||||
|
</raum>
|
||||||
|
<raum id='5' name='Treppenhaus'>
|
||||||
|
<ausgang dir='Rauf' nachRaum='10' />
|
||||||
|
<beschreibung>
|
||||||
|
Treppenhaus im Keller
|
||||||
|
</beschreibung>
|
||||||
|
</raum>
|
||||||
|
<raum id='10' name='Treppenhaus Kerkerebene'>
|
||||||
|
<ausgang dir='Runter' nachRaum='5' />
|
||||||
|
<ausgang dir='Sued' nachRaum='11' />
|
||||||
|
<beschreibung>
|
||||||
|
Treppenhaus in der Kerkerebene. Eine Tür führt nach Süden. Über der Tür hängt ein Hinweisschild.
|
||||||
|
</beschreibung>
|
||||||
|
</raum>
|
||||||
|
<raum id='11' name='Zellblockgang'>
|
||||||
|
<ausgang dir='Nord' nachRaum='10' />
|
||||||
|
<ausgang dir='Ost' nachRaum='12' />
|
||||||
|
<beschreibung>
|
||||||
|
Vom Gang im Zellblock führt eine Tür nach Osten in die Kerkerzelle. Über der Tür hängt ein Hinweisschild.
|
||||||
|
</beschreibung>
|
||||||
|
</raum>
|
||||||
|
<raum id='12' name='Kerkerzelle'>
|
||||||
|
<ausgang dir='West' nachRaum='11' />
|
||||||
|
<beschreibung>
|
||||||
|
Vom Gang im Zellblock führt eine Tür nach Osten in die Kerkerzelle.
|
||||||
|
</beschreibung>
|
||||||
|
</raum>
|
||||||
|
</ebene>
|
||||||
|
|
||||||
|
<commandset>
|
||||||
|
<command name='quit' id='0' key='0' />
|
||||||
|
<command name='ende' id='0' key='0' />
|
||||||
|
<command name='geh' id='1' key='1' />
|
||||||
|
<command name='nimm' id='2' key='2' />
|
||||||
|
<command name='untersuche' id='3' key='3' />
|
||||||
|
<command name='benutze' id='4' key='4' />
|
||||||
|
<command name='nord' id='5' key='5' />
|
||||||
|
<command name='ost' id='6' key='6' />
|
||||||
|
<command name='osten' id='7' key='6' />
|
||||||
|
<command name='süd' id='8' key='7' />
|
||||||
|
<command name='west' id='9' key='8' />
|
||||||
|
<command name='rauf' id='10' key='9' />
|
||||||
|
<command name='runter' id='11' key='10' />
|
||||||
|
<command name='gehe' id='12' key='11' />
|
||||||
|
<command name='inventar' id='13' key='12' />
|
||||||
|
<command name='about' id='14' key='13' />
|
||||||
|
<command name='verliere' id='15' key='14' />
|
||||||
|
<command name='warte' id='16' key='15' />
|
||||||
|
<command name='drücke' id='17' key='16' />
|
||||||
|
<command name='ende' id='18' key='0' />
|
||||||
|
<command name='schaue' id='18' key='3' />
|
||||||
|
<command name='ziehe' id='19' key='17' />
|
||||||
|
<command name='benutze' id='20' key='18' />
|
||||||
|
<command name='stelle' id='21' key='19' />
|
||||||
|
<command name='stell' id='22' key='19' />
|
||||||
|
|
||||||
|
</commandset>
|
||||||
|
<sortouts>
|
||||||
|
<sortout name='der' />
|
||||||
|
<sortout name='die' />
|
||||||
|
<sortout name='das' />
|
||||||
|
<sortout name='mit' />
|
||||||
|
<sortout name='aus' />
|
||||||
|
<sortout name='den' />
|
||||||
|
<sortout name='in' />
|
||||||
|
<sortout name='und' />
|
||||||
|
</sortouts>
|
||||||
|
<items>
|
||||||
|
<item name='Schwert' id='1' raum='1' imobil='false' msgid='0' visible='true' />
|
||||||
|
<item name='Seil' id='2' raum='2' imobil='false' msgid='0' visible='true' />
|
||||||
|
<item name='Streckbank' id='3' raum='1' imobil='true' msgid='4' visible='true' />
|
||||||
|
<item name='eiserne Jungfrau' id='4' raum='1' imobil='true' msgid='3' visible='true' />
|
||||||
|
<item name='Schwertgestell' id='5' raum='3' imobil='true' msgid='3' visible='true' />
|
||||||
|
<item name='Fackel' id='6' raum='4' imobil='false' msgid='3' visible='true' />
|
||||||
|
<item name='Fackelhalter' id='7' raum='3' imobil='false' msgid='3' visible='true' />
|
||||||
|
<item name='Hebel' id='8' raum='3' imobil='false' msgid='3' visible='true' />
|
||||||
|
<item name='Gittertor' id='9' raum='3' imobil='true' msgid='5' visible='true' />
|
||||||
|
<item name='Schreibtisch' id='10' raum='4' imobil='true' msgid='3' visible='true' />
|
||||||
|
<item name='Schlüssel' id='11' raum='4' imobil='false' msgid='3' visible='false' />
|
||||||
|
<item name='Schild' id='12' raum='10' imobil='true' msgid='6' visible='true' />
|
||||||
|
</items>
|
||||||
|
<personen>
|
||||||
|
<person name='Kerkermeister' id='1' raum='1' bewegung='0'/>
|
||||||
|
<person name='Wärter' id='2' raum='2' bewegung='0' />
|
||||||
|
<person name='Folterknecht' id='3' raum='2' bewegung='1' />
|
||||||
|
<person name='Geist' id='4' raum='3' bewegung='0' />
|
||||||
|
<person name='Maus' id='4' raum='2' bewegung='0' />
|
||||||
|
</personen>
|
||||||
|
<messages>
|
||||||
|
<pickup text='Das ist zu schwer' id='1' />
|
||||||
|
<pickup text='Daran sind soviel Körperflüssigkeiten runtergelaufen, du möchtest das nicht anfassen' id='2' />
|
||||||
|
<pickup text='Das ist fest mit der Wand verschraubt' id ='3' />
|
||||||
|
<pickup text='Daran hebst du dir nur nen Bruch' id='4' />
|
||||||
|
<pickup text='Egal, wie stark du an dem Tor rüttelst, es bewegt sich nicht.' id='5' />
|
||||||
|
<pickup text='Das hängt viel zu hoch. Zu kommst nicht dran.' id='6' />
|
||||||
|
</messages>
|
||||||
|
<bewegungen>
|
||||||
|
<bewegung id='0' value='' />
|
||||||
|
<bewegung id='1' value='1,3' />
|
||||||
|
</bewegungen>
|
||||||
|
<texte>
|
||||||
|
<text id='1'>
|
||||||
|
Als du die Fackel in den Fackelhalter stellst, kippt der Halter zur Seite. Hinter der Wand hörst du Seilzüge und Zahnräder
|
||||||
|
anlaufen. Über den verborgenen Mechanismus wird das Gittertor in die Höhe gezogen und der Weg nach Norden ist frei.
|
||||||
|
</text>
|
||||||
|
<text id='2'>
|
||||||
|
In einer Schreibtischschublade findest du einen Schlüssel.
|
||||||
|
</text>
|
||||||
|
<text id='item-11'>
|
||||||
|
Der Schlüssel ist etwa 10cm lang und hat eine ringförmige Reide. Der Bart hat drei Zacken und zwei Kerben.
|
||||||
|
</text>
|
||||||
|
<text id='item-12'>
|
||||||
|
Zellblock 11-38
|
||||||
|
</text>
|
||||||
|
<text id='item-9'>
|
||||||
|
Das Tor besteht aus schmideeisernen Stäben, die geschmiedete Querträger halten. Das Tor ist an den Seiten in Führungsschienen
|
||||||
|
eingelassen. Auf der rechten Seite befindet sich etwa in der Mitte ein Schloss. Hinter dem Tor scheint ein Treppenhaus zu sein.
|
||||||
|
</text>
|
||||||
|
</texte>
|
||||||
|
</welt>
|
Reference in New Issue
Block a user