This is an old revision of the document!
Labyrinth Klasse
Aufgabe 1
- Öffnen Sie das Verzeichnis
labyrinthmit VS-Code (File → Open Folder). - Legen Sie im Verzeichnis
labyrintheine neue Dateiaufgabe1.pyan und kopieren Sie folgendes Python-Programm:
- aufgab1.py
from laby import Laby l = Laby(4,3) print(l) for dir in range(4): l[1,1].zustand(dir, True) print("Jetzt offen:") print(l)
- Führen Sie das Programm aus.
- Studieren Sie das Programm und verstehen Sie es.
- Studieren Sie die Datei
zelle.py, insbesondere wie die Richtungsangaben funktionieren und die Methodenachbar. - Passen Sie das Programm so an, dass folgende Ausgabe entsteht:
+---+---+---+---+---+ | | | | | | +---+---+ +---+---+ | | | | | | +---+---+ +---+---+ | | +---+---+ +---+---+ | | | | | | +---+---+ +---+---+ | | | | | | +---+---+---+---+---+
- Hinweis: Das Programm kann sehr kompakt geschrieben mit der Methode einer Zelle
nachbar(dir)
Aufgabe 2
- Testen und verstehen Sie das Programm
aufgabe2.py(ebenfalls im Verzeichnislabyrinthzu speichern):
- aufgabe2.py
from laby import Laby l = Laby(10,5) for x in range(l.breite-1): l[x,0].zustand(0, True) print(l)
- Erweitern Sie das Programm so , dass folgendes Labyrinth produziert wird:
+---+---+---+---+---+---+---+---+---+---+ | | +---+---+---+---+---+---+---+---+---+---+ | | +---+---+---+---+---+---+---+---+---+---+ | | +---+---+---+---+---+---+---+---+---+---+ | | +---+---+---+---+---+---+---+---+---+---+ | | +---+---+---+---+---+---+---+---+---+---+