Skip to content
Open
Show file tree
Hide file tree
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
Binary file added __pycache__/server.cpython-37.pyc
Binary file not shown.
70 changes: 50 additions & 20 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,14 @@ def room_description(self, room_number):
:return: str
"""

# TODO: YOUR CODE HERE

pass
return [
"You are in the room with the red wallpaper.",
"You are in the room with the white wallpaper.",
"You are in the room with the blue wallpaper.",
"You are in the room with the star wallpaper.",
][room_number]


def greet(self):
"""
Welcome a client to the game.
Expand All @@ -108,9 +112,12 @@ 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

def move(self, argument):
"""
Expand All @@ -133,9 +140,27 @@ 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

pass
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 +176,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,10 +190,9 @@ def quit(self, argument):
:return: None
"""

# TODO: YOUR CODE HERE

pass

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

def route(self):
"""
Examines `self.input_buffer` to perform the correct action (move, quit, or
Expand All @@ -183,9 +205,19 @@ def route(self):
:return: None
"""

# TODO: YOUR CODE HERE

received = self.input_buffer.split(" ")

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

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



def push_output(self):
"""
Expand All @@ -197,10 +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()
self.greet()
Expand Down