From 2110696e8d53d4198bf2838909e427b22ec6ea16 Mon Sep 17 00:00:00 2001 From: Ian Mayther Date: Mon, 26 Apr 2021 21:21:25 -0700 Subject: [PATCH 1/3] Preliminary methods completed --- server.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/server.py b/server.py index d0d46c4..3114692 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 cat with the un-ending gaze", + "You are in the room that is full of people, one of whom has, farted.", + "You are in the room with a window that doesn't open, but isn't fully closed", + "You are in the room with Professor Plum and the candlestick." + ][room_number] def greet(self): """ @@ -133,9 +136,8 @@ def move(self, argument): :return: None """ - # TODO: YOUR CODE HERE - - pass + self.done = True + self.output_buffer = "Goodbye!" def say(self, argument): """ @@ -151,9 +153,7 @@ def say(self, argument): :return: None """ - # TODO: YOUR CODE HERE - - pass + self.output_buffer = 'You say, "{}"'.format(argument) def quit(self, argument): """ @@ -197,9 +197,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() From bdee37b21aca37ee8c9c94fe0dfaf86dddcae229 Mon Sep 17 00:00:00 2001 From: Ian Mayther Date: Tue, 27 Apr 2021 21:01:19 -0700 Subject: [PATCH 2/3] Got quit to quit --- server.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server.py b/server.py index 3114692..058f5b6 100644 --- a/server.py +++ b/server.py @@ -167,9 +167,8 @@ def quit(self, argument): :return: None """ - # TODO: YOUR CODE HERE - - pass + self.done = True + self.output_buffer = "Goodbye!" def route(self): """ @@ -183,7 +182,14 @@ def route(self): :return: None """ - # TODO: YOUR CODE HERE + choice = self.client_connection.recv(16) #.decode('utf8') + print(type(choice)) + print(choice) + + selection = choice.decode('utf8') + + if selection.strip() == 'quit': + self.quit('quit') pass From 67261e2f4080dd48537ac25eaa1460f56180e82c Mon Sep 17 00:00:00 2001 From: Ian Mayther Date: Thu, 29 Apr 2021 05:45:31 -0700 Subject: [PATCH 3/3] Added lower() command to the route dictionary --- server.py | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/server.py b/server.py index 058f5b6..782d7e4 100644 --- a/server.py +++ b/server.py @@ -111,7 +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) + + self.input_buffer = received.decode().strip() pass @@ -136,8 +140,26 @@ def move(self, argument): :return: None """ - self.done = True - self.output_buffer = "Goodbye!" + + 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) def say(self, argument): """ @@ -182,14 +204,16 @@ def route(self): :return: None """ - choice = self.client_connection.recv(16) #.decode('utf8') - print(type(choice)) - print(choice) + received = self.input_buffer.split(" ") - selection = choice.decode('utf8') + command = received.pop(0) + arguments = " ".join(received) - if selection.strip() == 'quit': - self.quit('quit') + { + 'quit': self.quit, + 'move': self.move, + 'say': self.say, + }[command.lower()](arguments) pass