Commit 21a0f291 authored by Constantin's avatar Constantin
Browse files


parent 674ea1c3
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(('', 1234))
self.sock.bind(('', port))
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.sel.register(conn, selectors.EVENT_READ,
# class for the labyrinth
from enum import Enum
from functools import reduce
class Labyrinth:
class GroundType(Enum):
......@@ -58,8 +59,22 @@ class Labyrinth:
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
\ No newline at end of file
thing.field = newField
return True
def createThing (self, thing, field):
thing.field = field
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment