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

Initial commit #11

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
46 changes: 28 additions & 18 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ def room_description(self, room_number):
:return: str
"""

# TODO: YOUR CODE HERE

pass
descriptions = ["You are in the room with the unicorn stampede.",
"You are in the room of no forgiveness.",
"You are in the anti-matter collision room.",
"You are in the blink realm of a portal loop."]
return descriptions[room_number]

def greet(self):
"""
Expand All @@ -108,9 +110,11 @@ def get_input(self):
:return: None
"""

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

pass
self.input_buffer = message.decode()

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

# TODO: YOUR CODE HERE
move_dict = {0: {'north': 3, 'west': 1, 'east': 2},
1: {'east': 0}, 2: {'west': 0}, 3: {'south': 0}}

pass
try:
self.room = move_dict[self.room][argument]
self.output_buffer = self.room_description(self.room)
except:
self.output_buffer = f"Can't go {argument} from here traveler."\
" Try another direction!"

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

# TODO: YOUR CODE HERE

pass
self.output_buffer = f'You say, "{argument}"'

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

# TODO: YOUR CODE HERE

pass
self.done = True
self.output_buffer = "Go with fortitude, traveler."

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

# TODO: YOUR CODE HERE
command = self.input_buffer.split(' ')
action = command.pop(0).strip('\n')
arg = ' '.join(command).strip('\n')

pass
try:
{'move': self.move, 'say': self.say, 'quit': self.quit}[action](arg)
except:
self.output_buffer = "Can't do that here, traveler. Try another command."

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