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

activity 3 submission #23

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
71 changes: 50 additions & 21 deletions server.py
Original file line number Diff line number Diff line change
@@ -79,10 +79,13 @@ 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):
"""
Welcome a client to the game.
@@ -108,9 +111,11 @@ def get_input(self):
:return: None
"""

# TODO: YOUR CODE HERE
msg = b''
while b'\n' not in msg:
msg += self.client_connection.recv(32)

pass
self.input_buffer += msg[:-1].decode()

def move(self, argument):
"""
@@ -132,10 +137,31 @@ def move(self, argument):
:param argument: str
:return: None
"""

# TODO: YOUR CODE HERE

pass
argument = argument.lower()
start = self.room
if self.room == 0:
if argument == "north":
self.room = 3
elif argument == "east":
self.room = 2
elif argument == "west":
self.room = 1
elif self.room == 1:
if argument == "east":
self.room = 0
elif self.room == 2:
if argument == "west":
self.room = 0
elif self.room == 3:
if argument == "south":
self.room = 0
else:
self.output_buffer = "Boy did you get lost! {}".format(self.room_description(self.room))
return None
if self.room != start:
self.output_buffer = "You move {}. {}".format(argument, self.room_description(self.room))
else:
self.output_buffer = "Invalid choice {}! {}".format(argument, self.room_description(self.room))

def say(self, argument):
"""
@@ -151,9 +177,7 @@ def say(self, argument):
:return: None
"""

# TODO: YOUR CODE HERE

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

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

# TODO: YOUR CODE HERE

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

def route(self):
"""
@@ -183,9 +206,14 @@ def route(self):
:return: None
"""

# TODO: YOUR CODE HERE
if self.input_buffer == "quit":
self.quit(None)

pass
elif self.input_buffer.startswith('say'):
self.say(self.input_buffer.split('say ')[1])
elif self.input_buffer.startswith('move'):
self.move(self.input_buffer.split('move ')[1])
self.input_buffer = ""

def push_output(self):
"""
@@ -197,9 +225,10 @@ def push_output(self):
:return: None
"""

# TODO: YOUR CODE HERE

pass
self.client_connection.sendall(b"OK! " + self.output_buffer.encode() + b"\n")
#Clear buffer after sending.
#TODO: add try/except to only clear buffer on successful send.
self.output_buffer = ""

def serve(self):
self.connect()