Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding lesson 03 activity files #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
66 changes: 43 additions & 23 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 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_number]

def greet(self):
"""
Expand All @@ -108,9 +111,11 @@ 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()

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

# TODO: YOUR CODE HERE

pass
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):
"""
Expand All @@ -151,9 +172,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 @@ -166,10 +185,8 @@ def quit(self, argument):
:param argument: str
:return: None
"""

# TODO: YOUR CODE HERE

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

def route(self):
"""
Expand All @@ -182,10 +199,15 @@ def route(self):

:return: None
"""

# TODO: YOUR CODE HERE

pass
received = self.input_buffer.split(" ")

command = received.pop(0).strip('\n')
arguments = " ".join(received).strip('\n')
{
'quit': self.quit,
'move': self.move,
'say': self.say,
}[command](arguments)

def push_output(self):
"""
Expand All @@ -197,9 +219,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