Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Hacksaar
Haxotel
Commits
e74dbd75
Commit
e74dbd75
authored
Aug 01, 2014
by
Ralf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
small fixes; leave verbs; exception handling
parent
8204abe0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
6 deletions
+15
-6
game.py
game.py
+1
-1
player.py
player.py
+14
-5
No files found.
game.py
View file @
e74dbd75
...
...
@@ -27,7 +27,7 @@ class Game:
def
removePlayer
(
self
,
player
):
assert
player
in
self
.
players
player
.
close
()
self
.
sel
.
unregister
(
player
.
close
()
)
self
.
players
.
remove
(
player
)
assert
player
not
in
self
.
players
# this ensure the player was in only once
...
...
player.py
View file @
e74dbd75
...
...
@@ -4,6 +4,7 @@ from labyrinth import directions as directionOffsets
goVerbs
=
[
'go'
,
'walk'
]
sayVerbs
=
[
'say'
,
'talk'
,
'scream'
]
leaveVerbs
=
[
'leave'
,
'quit'
,
'exit'
,
'suicide'
]
class
Player
(
Thing
):
def
__init__
(
self
,
game
,
conn
):
...
...
@@ -13,12 +14,13 @@ class Player(Thing):
self
.
conn
=
conn
# low-level functions
def
send
(
self
,
data
):
def
send
(
self
,
data
,
end
=
'
\n
'
):
assert
type
(
data
)
==
str
send_async
(
self
.
conn
,
(
data
+
"
\n
"
).
encode
(
'utf-8'
))
send_async
(
self
.
conn
,
(
data
+
end
).
encode
(
'utf-8'
))
def
close
(
self
):
# only to be called by Game - it has to remove us from its list
self
.
conn
.
close
()
return
self
.
conn
def
read
(
self
,
conn
,
mask
):
assert
self
.
conn
==
conn
,
"The player's connection changed?"
...
...
@@ -29,7 +31,10 @@ class Player(Thing):
while
pos
>=
0
:
cmd
=
self
.
buffer
[:
pos
]
self
.
buffer
=
self
.
buffer
[
pos
+
1
:]
self
.
readCmd
(
cmd
.
decode
(
'utf-8'
))
try
:
self
.
readCmd
(
cmd
.
decode
(
'utf-8'
))
except
UnicodeDecodeError
:
self
.
send
(
"These are bad bytes..."
)
# maybe we got several lines?
pos
=
self
.
buffer
.
find
(
b
'
\n
'
)
else
:
...
...
@@ -59,7 +64,6 @@ class Player(Thing):
self
.
send
(
"Sorry, you cannot go there"
)
return
self
.
game
.
labyrinth
.
moveThing
(
self
,
target
)
return
elif
verb
in
sayVerbs
:
msg
=
" "
.
join
(
words
[
1
:])
for
dx
,
dy
in
[(
0
,
0
)]
+
directionOffsets
.
values
():
...
...
@@ -67,7 +71,12 @@ class Player(Thing):
if
isinstance
(
thing
,
Player
)
and
thing
!=
self
:
thing
.
send
(
"You hear someone saying: "
+
msg
)
self
.
send
(
"You say: "
+
msg
)
elif
verb
in
leaveVerbs
:
self
.
send
(
"Good Bye!"
)
self
.
game
.
removePlayer
(
self
)
else
:
self
.
send
(
"I don't know what you are talking about"
)
def
afterMove
(
self
,
oldField
):
desc
=
self
.
game
.
labyrinth
.
getDescription
(
self
.
field
)
self
.
send
(
desc
)
self
.
send
(
desc
,
end
=
""
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment