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

completed, including a minor fix to the client that wasn't asked for ... #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@

print(response)

if response.startswith("OK! Goodbye"):
exit(-1)

my_message = input("> ").encode('utf-8') + b'\n'
client_socket.sendall(my_message)
63 changes: 45 additions & 18 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Server(object):
each room have a unique description.
"""

game_name = "Realms of Venture"


def __init__(self, port=50000):
self.input_buffer = ""
Expand All @@ -55,6 +55,8 @@ def __init__(self, port=50000):

self.room = 0

self.game_name = "Realms of Venture"

def connect(self):
self.socket = socket.socket(
socket.AF_INET,
Expand All @@ -79,9 +81,11 @@ def room_description(self, room_number):
:return: str
"""

# TODO: YOUR CODE HERE
return ["You are in room 0.",
"You are in room 1.",
"You are in room 2.",
"You are in room 3."][room_number]

pass

def greet(self):
"""
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()

pass

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

# TODO: YOUR CODE HERE
if self.room == 0:
if argument == "west":
self.room = 1
elif argument == "east":
self.room = 2
elif argument == "north":
self.room = 3
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

self.output_buffer = self.room_description(self.room)

pass

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

# TODO: YOUR CODE HERE

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


def quit(self, argument):
"""
Quits the client from the server.
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,9 +204,17 @@ def route(self):
:return: None
"""

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

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

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

pass

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