From d04b249577bcfc4caa95df2e8e4d1471fd832a21 Mon Sep 17 00:00:00 2001 From: Tom Date: Fri, 8 May 2020 14:00:55 -0700 Subject: [PATCH] finished activity --- server.py | 75 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/server.py b/server.py index d0d46c4..825a3db 100644 --- a/server.py +++ b/server.py @@ -78,10 +78,16 @@ def room_description(self, room_number): :param room_number: int :return: str """ - - # TODO: YOUR CODE HERE - - pass + + room_desc = [ + "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_desc_output = room_desc[room_number] + + return room_desc_output def greet(self): """ @@ -108,10 +114,13 @@ def get_input(self): :return: None """ - # TODO: YOUR CODE HERE - - pass - + received = b'' + + while b'\n' not in received: + received += self.client_connection.recv(16) + + self.input_buffer = received.decode().strip() + def move(self, argument): """ Moves the client from one room to another. @@ -132,10 +141,26 @@ def move(self, argument): :param argument: str :return: None """ + + if self.room == 0 and argument == "north": + self.room = 3 - # TODO: YOUR CODE HERE + if self.room == 0 and argument == "west": + self.room = 1 - pass + 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): """ @@ -151,9 +176,7 @@ def say(self, argument): :return: None """ - # TODO: YOUR CODE HERE - - pass + self.output_buffer = 'You say, "{}"'.format(argument) def quit(self, argument): """ @@ -167,7 +190,8 @@ def quit(self, argument): :return: None """ - # TODO: YOUR CODE HERE + self.done = True + self.output_buffer = "Goodbye!" pass @@ -182,10 +206,18 @@ def route(self): :return: None """ - - # TODO: YOUR CODE HERE - - pass + + recieved = self.input_buffer.split(" ") + + command = recieved.pop(0) + arguments = " ".join(recieved) + + { + 'quit': self.quit, + 'move': self.move, + 'say': self.say + }[command](arguments) + def push_output(self): """ @@ -197,9 +229,8 @@ 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() @@ -212,4 +243,4 @@ def serve(self): self.push_output() self.client_connection.close() - self.socket.close() + self.socket.close() \ No newline at end of file