Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Hacksaar
Haxotel
Commits
21a0f291
Commit
21a0f291
authored
Jul 31, 2014
by
Constantin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changes
parent
674ea1c3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
6 deletions
+25
-6
game.py
game.py
+6
-2
labyrinth.py
labyrinth.py
+19
-4
No files found.
game.py
View file @
21a0f291
from
player
import
Player
import
selectors
import
socket
import
labyrinth
class
Game
:
def
__init__
(
self
):
def
__init__
(
self
,
labyrinthFileName
,
port
=
1234
):
self
.
players
=
[]
with
open
(
labyrinthFileName
,
'r'
)
as
f
:
self
.
labyrinth
=
labyrinth
.
Labyrinth
(
stream
=
f
)
self
.
sock
=
socket
.
socket
()
self
.
sock
.
bind
((
'0.0.0.0'
,
1234
))
self
.
sock
.
bind
((
'0.0.0.0'
,
port
))
self
.
sock
.
listen
(
100
)
self
.
sel
=
selectors
.
DefaultSelector
()
self
.
sel
.
register
(
self
.
sock
,
selectors
.
EVENT_READ
,
self
.
accept
)
...
...
@@ -14,6 +17,7 @@ class Game:
def
accept
(
self
,
sock
,
mask
):
assert
sock
==
self
.
sock
conn
,
addr
=
sock
.
accept
()
# Should be ready
player
=
Player
(
self
,
conn
)
self
.
players
.
append
(
player
)
self
.
sel
.
register
(
conn
,
selectors
.
EVENT_READ
,
player
.
read
)
...
...
labyrinth.py
View file @
21a0f291
# class for the labyrinth
from
enum
import
Enum
from
functools
import
reduce
class
Labyrinth
:
class
GroundType
(
Enum
):
...
...
@@ -58,8 +59,22 @@ class Labyrinth:
tiles
.
append
(
row
)
return
tiles
def
onThingMoved
(
self
,
thing
,
oldField
,
newField
):
assert
oldField
.
labyrinth
==
self
def
getTiles
(
self
):
return
reduce
(
lambda
x
,
y
:
x
+
y
,
self
.
tiles
)
def
getFreeTiles
(
self
):
return
filter
(
lambda
f
:
f
.
groundtype
==
Labyrinth
.
GroundType
.
FLOOR
and
len
(
f
.
things
==
0
)
,
self
.
getTiles
)
def
moveThing
(
self
,
thing
,
newField
):
if
thing
.
onMove
(
newField
)
==
False
:
return
False
assert
thing
.
field
.
labyrinth
==
self
assert
newField
.
labyrinth
==
self
oldField
.
_removeThing
(
thing
)
newField
.
_addThing
(
thing
)
\ No newline at end of file
thing
.
field
.
_removeThing
(
thing
)
thing
.
field
=
newField
newField
.
_addThing
(
thing
)
return
True
def
createThing
(
self
,
thing
,
field
):
thing
.
field
=
field
field
.
_addThing
(
thing
)
\ No newline at end of file
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