Dodany slownik z wartosciami roslin

This commit is contained in:
Pikusia 2019-05-31 15:01:29 +02:00
parent 29632d3693
commit 89d699dbd5
3 changed files with 26 additions and 1 deletions

View File

@ -41,8 +41,10 @@ class Plant():
pass
def get_stats(self):
return {"ttl": self.ttl, "is_alive": self.is_alive, "hydration": self.hydration, "soil_level": self.soil_level,
"ready": self.ready }
#np. touple'a z info czy żyje, ile ma wody i nawozu
raise NotImplementedError("Please Implement this method")
def get_symbol(self):
if not self.is_alive:

13
env.py
View File

@ -96,6 +96,14 @@ def look_at_plats(field, location):
wsp = []
def send_stats(field, location):
x = location[0]
y = location[1]
stats = field[x][y]
str_stats = str(stats["ttl"]) + " " + str(stats["is_alive"]) + " " + str(stats["hydration"]) + " " \
+ str(stats["soil_level"]) + " " + str(stats["ready"]) + "\n"
return str_stats
if __name__ == "__main__":
@ -121,6 +129,11 @@ if __name__ == "__main__":
elif message[0] == "look":
tractor.move()
writer.write(("OK\n").encode())
elif message[0] == "get_stats":
x = message[1]
y = message[2]
stats = send_stats(field, (x, y)).encode()
writer.write(stats)
print_field(field, tractor)

View File

@ -191,6 +191,16 @@ class Tractor:
"tutaj trzeba zapytac env z jakimi roslinami sie styka traktor i je obsłuzyc"
pass
async def get_stats(self, location):
reader, writer = await asyncio.open_connection('127.0.0.1', 8888)
writer.write(("stats " + str(location[0]) + " " + str(location[1]) + "\n").encode())
data = await reader.readline()
parsed_data = data.decode().split()
time.sleep(self.sleep_time)
writer.close()
return {"ttl": parsed_data[0], "is_alive": parsed_data[1], "hydration": parsed_data[2], "soil_level": parsed_data[3],
"ready": parsed_data[4]}
if __name__ == "__main__":
start = (0,0)