From ef40421e132122beaf2f359d36474637c65bdf3e Mon Sep 17 00:00:00 2001 From: Andy Simpson Date: Mon, 12 Oct 2020 18:03:54 -0700 Subject: [PATCH 1/2] Initial Commit and Project Setup - AS --- .gitignore | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/.gitignore b/.gitignore index 3336d87..a7caffe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,133 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + # USER SPECIFIC/IDE FILES .idea/ From 56aae116ae01379e83f9bf5bb617a5599ea3df0a Mon Sep 17 00:00:00 2001 From: Andy Simpson Date: Mon, 12 Oct 2020 18:33:35 -0700 Subject: [PATCH 2/2] Updated Server.py - AS --- server.py | 66 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/server.py b/server.py index d0d46c4..f60ef65 100644 --- a/server.py +++ b/server.py @@ -79,9 +79,12 @@ def room_description(self, room_number): :return: str """ - # TODO: YOUR CODE HERE - - pass + return [ + "You are in the room with the white wallpaper.", + "You are in the room with the green wallpaper.", + "You are in the room with the brown wallpaper.", + "You are in the room with the mauve wallpaper.", + ][room_number] def greet(self): """ @@ -108,9 +111,11 @@ def get_input(self): :return: None """ - # TODO: YOUR CODE HERE + received = b'' + while b'\n' not in received: + received += self.client_connection.recv(16) - pass + self.input_buffer = received.decode().strip() def move(self, argument): """ @@ -133,9 +138,26 @@ def move(self, argument): :return: None """ - # TODO: YOUR CODE HERE + if self.room == 0 and argument == "north": + self.room = 3 + + if self.room == 0 and argument == "west": + self.room = 1 + + if self.room == 0 and argument == "east": + self.room = 2 + + if self.room == 1 and argument = "east": + self.room = 0 + + if self.room == 2 and argument == "west": + self.room = 0 + + if self.room == 3 and argument == "south": + self.room = 0 + + self.output_buffer = self.room_description(self.room) - pass def say(self, argument): """ @@ -151,9 +173,7 @@ def say(self, argument): :return: None """ - # TODO: YOUR CODE HERE - - pass + self.output_buffer = 'You say, "{}"'.format(argument) def quit(self, argument): """ @@ -167,9 +187,8 @@ def quit(self, argument): :return: None """ - # TODO: YOUR CODE HERE - - pass + self.done = True + self.output_buffer = "Goodbye!" def route(self): """ @@ -183,9 +202,22 @@ def route(self): :return: None """ - # TODO: YOUR CODE HERE + received = self.input_buffer.split(" ") - pass + command = received.pop(0) + arguments = " ".join(received) + + # If `self.input_buffer` was "say Is anybody here?", then: + # `command` should now be "say" and `arguments` should now be "Is anybody here?". + # + # If `self.input_buffer` was "move north", then: + # `command` should now be "move" and `arguments` should now be "north". + + { + 'quit': self.quit, + 'move': self.move, + 'say': self.say, + }[command](arguments) def push_output(self): """ @@ -197,9 +229,7 @@ def push_output(self): :return: None """ - # TODO: YOUR CODE HERE - - pass + self.client_connection.sendall(b"OK! " + self.output_buffer.encode() + b"\n") def serve(self): self.connect()