From 0ded3de76ec453c23bfc508ef5a598faf1626511 Mon Sep 17 00:00:00 2001 From: Olli Graf Date: Thu, 17 Feb 2022 06:34:28 +0100 Subject: [PATCH] tomb.py .gitignore --- .gitignore | 3 ++ tomb.py | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 .gitignore create mode 100755 tomb.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4414eae --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +tomb.log +__pycache__ +/data/__pycache__ diff --git a/tomb.py b/tomb.py new file mode 100755 index 0000000..91e2461 --- /dev/null +++ b/tomb.py @@ -0,0 +1,87 @@ +#!/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 == '20': + actionmodul.oeffne(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='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): + schrittzaehler = 0 + + 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() + actionmodul.clearFehler() + 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) + schrittzaehler = schrittzaehler +1 + actionmodul.raumaction() + +wrapper(inputLoop)