123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- import random as rd
- import time as t
- import sys
- import os
- xyPlayer= [1,1] # festlegen der Startposition des Spielers
- xSense = 0
- ySense = 0
- #lesen des Labs, fallls in .txt-Datei enthalten
- def re():
- Data = open("TestLab.txt","r") #festlegen des Dateipfades
- global Mat #Mat ist die Matrix, die koordinatenbezogen Informationen ueber das Lab vereint
- Mat = []
- for line in Data: #Auslesen des Labs und ueberfuehren in eine Matrix
- li = line.strip().split(" ")
- Mat.append(li)
- Data.close()
- def sense(xSense,ySense): #Spieler "tastet" nach begehbaren Feldern
- feldwert = Mat[xSense][ySense]
- print "Feldwert = {}".format(feldwert)
- if feldwert == "1":
- xyPlayer[0] = xSense
- xyPlayer[1] = ySense
- print "Neue Koordinaten: x-Koordinate: {0}; y-Koordinate: {1}".format(xyPlayer[0],xyPlayer[1])
- elif feldwert == "0":
- print "Bonk!"
- elif feldwert == "S":
- xyPlayer[0] = xSense
- xyPlayer[1] = ySense
- print "Sie sind wieder am Start!{0}Neue Koordinaten: x-Koordinate: {1}; y-Koordinate: {2}".format("\n",xyPlayer[0],xyPlayer[1])
- elif feldwert == "Z":
- xyPlayer[0] = xSense
- xyPlayer[1] = ySense
- print "Sie sind am Ziel angekommen!{0}Neue Koordinaten: x-Koordinate: {1}; y-Koordinate: {2}".format("\n",xyPlayer[0],xyPlayer[1])
- else:
- print "fehler"
- def schritt(dir,val):
- if dir == "xPlayer":
- xSense = int(xyPlayer[0]) + val
- ySense = int(xyPlayer[1])
- print "xSense = {}".format(xSense)
- print "ySense = {}".format(ySense)
- elif dir == "yPlayer":
- xSense = int(xyPlayer[0])
- ySense = int(xyPlayer[1]) + val
- print "xSense = {}".format(xSense)
- print "ySense = {}".format(ySense)
- sense(xSense,ySense)
- def movement():
- move = raw_input("Geben Sie eine Bewegungrichtung an! (WASD)")
- if move == "W":
- schritt("xPlayer",-1)
- elif move == "S":
- schritt("xPlayer",1)
- elif move == "A":
- schritt("yPlayer",-1)
- elif move == "D":
- schritt("yPlayer",1)
- re()
- print Mat
- while True:
- movement()
|