Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 44 additions & 16 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -108,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

Expand All @@ -133,9 +140,26 @@ def move(self, argument):
:return: None
"""

# TODO: YOUR CODE HERE

if self.room == 0 and argument == "north":
self.room = 3

pass
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):
"""
Expand All @@ -151,9 +175,7 @@ def say(self, argument):
:return: None
"""

# TODO: YOUR CODE HERE

pass
self.output_buffer = 'You say, "{}"'.format(argument)

def quit(self, argument):
"""
Expand All @@ -167,9 +189,8 @@ def quit(self, argument):
:return: None
"""

# TODO: YOUR CODE HERE

pass
self.done = True
self.output_buffer = "Goodbye!"

def route(self):
"""
Expand All @@ -183,7 +204,16 @@ def route(self):
:return: None
"""

# TODO: YOUR CODE HERE
received = self.input_buffer.split(" ")

command = received.pop(0)
arguments = " ".join(received)

{
'quit': self.quit,
'move': self.move,
'say': self.say,
}[command.lower()](arguments)

pass

Expand All @@ -197,9 +227,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()
Expand Down