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

created adventure game socket server #9

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
63 changes: 44 additions & 19 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"
game_name = "Realms of Seattle"

def __init__(self, port=50000):
self.input_buffer = ""
Expand Down Expand Up @@ -79,9 +79,17 @@ def room_description(self, room_number):
:return: str
"""

# TODO: YOUR CODE HERE
descriptions = [
"You're in... Costco? Everyone around you is scavenging toilet paper. " +
"You just came for the $1.50 hotdog combo, didn't you?",
"You're at UW and there are Cherry Blossom trees all around you. You only " +
"have 4 rooms to live in the rest of your life, so this isn't a bad option.",
"You found yourself in a room with all the delicacies Pike's place has to offer. " +
"People are flinging fish, kombucha is on tap, and there's a bottomless supply of" +
"... Beecher's Mac & Cheese? Heavenly.",
"You're in the rain room. Yep - that's a thing here in Seattle."]

pass
return descriptions[room_number]

def greet(self):
"""
Expand All @@ -92,7 +100,7 @@ def greet(self):

:return: None
"""
self.output_buffer = "Welcome to {}! {}".format(
self.output_buffer = "Welcome to {}!\n{}".format(
self.game_name,
self.room_description(self.room)
)
Expand All @@ -108,9 +116,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().strip('\n')

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

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

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

def say(self, argument):
"""
Expand All @@ -151,9 +173,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,9 +187,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 +202,16 @@ def route(self):
:return: None
"""

# TODO: YOUR CODE HERE
command = self.input_buffer.split(" ")
action = command.pop(0)
command = " ".join(command)

pass
if action == "say":
self.say(command)
if action == "move":
self.move(command)
if action == "quit":
self.quit(command)

def push_output(self):
"""
Expand All @@ -197,9 +223,8 @@ def push_output(self):
:return: None
"""

# TODO: YOUR CODE HERE
self.client_connection.sendall(b"OK! " + self.output_buffer.encode() + b"\n")

pass

def serve(self):
self.connect()
Expand Down