diff --git a/server.py b/server.py index d0d46c4..8e247d0 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 trampolines", + "You are in the room with a ball pit", + "You are in the room full of kittens", + "You are in the room with anime posters plastering the walls", + ][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() def move(self, argument): """ @@ -133,9 +138,25 @@ 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 - pass + if self.room == 3 and argument == "south": + self.room = 0 + + self.output_buffer = self.room_description(self.room) def say(self, argument): """ @@ -151,9 +172,8 @@ def say(self, argument): :return: None """ - # TODO: YOUR CODE HERE + self.output_buffer = 'You say, "{}".'.format(argument) - pass 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,16 @@ def route(self): :return: None """ - # TODO: YOUR CODE HERE + received = self.input_buffer.split(' ') - pass + command = received.pop(0).strip() + arguments = ' '.join(received).strip() + + { + 'quit': self.quit, + 'move': self.move, + 'say': self.say, + }[command](arguments) def push_output(self): """ @@ -197,9 +223,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()