Files
pytomb/tomb.py
Olli Graf 8bd0897af1 Endgame
2022-06-13 17:56:35 +02:00

221 lines
6.0 KiB
Python
Executable File

#!/usr/bin/python3
# Hauptprogramm - Eingabeschleife und Dispatching
import World
import ActionModul
import TestModule
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 == '4':
actionmodul.benutze(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 == '20':
actionmodul.oeffne(parsedCommand)
elif id == '21':
actionmodul.klettere(parsedCommand)
elif id == '22':
actionmodul.fange(parsedCommand)
elif id == '23':
actionmodul.hilfe(parsedCommand)
elif id == '24':
actionmodul.schlage(parsedCommand)
elif id == '25':
actionmodul.sprich(parsedCommand)
elif id == '26':
actionmodul.leere(parsedCommand)
elif id == '27':
actionmodul.fuelle(parsedCommand)
elif id == '28':
actionmodul.wirf(parsedCommand)
elif id == '29':
actionmodul.gib(parsedCommand)
elif id == '30':
actionmodul.entzuende(parsedCommand)
elif id == '31':
actionmodul.loesche(parsedCommand)
elif id == '32':
actionmodul.spring(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(
format='%(asctime)-15s [%(levelname)s] %(funcName)s: %(message)s',
filename='tomb.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)
curses.init_pair(4,curses.COLOR_WHITE, curses.COLOR_BLUE)
curses.init_pair(5,curses.COLOR_WHITE, curses.COLOR_GREEN)
commandid = ''
while commandid != '0':
world.printRaum()
actionmodul.clearFehler()
stdscr.addstr(11,0,'Was nun? ')
command = stdscr.getstr(11,10,40).decode(encoding="utf-8")
world.schrittzaehler = world.schrittzaehler +1
command = command.rstrip()
if command.startswith('debug:'):
debugcommand = command.split(':',1)
logging.debug(f'debugcommand: {debugcommand}')
if debugcommand[1] == 'items':
debug_Items()
elif debugcommand[1] == 'inventar':
debug_Inventar()
elif debugcommand[1] == 'personen':
debug_Personen()
elif debugcommand[1] == 'karte':
world.printKarte()
commandid = '0'
elif debugcommand[1] == 'weg':
logging.debug(f'gelaufener Weg: {world.weg}')
elif debugcommand[1] == 'unvisited':
debug_NonVisited()
elif command.startswith('auto:'):
command = command.rstrip()
if command.startswith('auto:'):
debugcommand = command.split(':',1)
logging.debug(f'debugcommand: {debugcommand}')
testmodul = TestModule.TestModule(world)
if(debugcommand[1] == 'truhe'):
testmodul.testOeffneTruhe()
elif debugcommand[1] == 'teich':
testmodul.testTeich()
elif debugcommand[1] == 'ranke':
testmodul.testRanke()
elif debugcommand[1] == 'tal':
testmodul.testTal()
elif debugcommand[1] =='baumhaus':
testmodul.testBaumhaus()
elif debugcommand[1] == 'stier':
testmodul.testStier()
elif debugcommand[1] == 'hafen':
testmodul.testHafen()
elif debugcommand[1] == 'insel':
testmodul.testInsel()
elif debugcommand[1] == 'klippe':
testmodul.testKlippe()
elif debugcommand[1] == 'statue':
testmodul.testStatue()
elif debugcommand[1] == 'mauer':
testmodul.testMauer()
world.fehler = ''
else:
actionmodul.clearFehler()
parsedCommand = world.parseInput(command)
commandid = parsedCommand.commandid
verarbeiteBefehl(parsedCommand)
actionmodul.raumaction()
def debug_NonVisited():
logging.debug('nicht entdeckte Räume:')
for raumid in world.raumliste:
raum = world.raumliste[raumid]
if not raum.entdeckt:
logging.debug(f'{raum.id} - {raum.name}')
def debug_Personen():
logging.debug('Personen im aktuellen Raum')
for pid in world.aktuellerRaum.personen:
person = world.personen[pid]
logging.debug(f'Id: {person.id} - Name: {person.name}')
def debug_Items():
logging.debug('liste Items im aktuellen Raum')
logging.debug(world.aktuellerRaum.items)
count = 0
for itemid in world.aktuellerRaum.items:
item = world.aktuellerRaum.items[itemid]
logging.debug(f'count= {count}')
# logging.debug(f'Itemtyp: {type(item)}')
logging.debug(f'Item-IdId:{item.id} - Item-Name:{item.name} - sichtbar= {item.sichtbar}')
count = count +1
def debug_Inventar():
logging.debug('liste Items')
logging.debug(world.inventar)
count = 0
for itemid in world.inventar:
item = world.inventar[itemid]
logging.debug(f'count= {count}')
logging.debug(f'Itemtyp: {type(item)}')
# logging.debug(f'Item-IdId:{item.id} - Item-Name:{item.name}')
count = count +1
def main():
wrapper(inputLoop)
if __name__ == '__main__':
main()