Exemplo n.º 1
0
class GameWorldService(service.Service):

    def __init__(self):
        self.clients = []
        self.game = Game()
        self.mob = Actor("eeeeeeewwwwwww")
        self.game.place(self.mob, (1,1))
        self.game.register(self.on_notify)
        reactor.callLater(1, self.tick)
    def tick(self):        
        self.mob.cue()
        reactor.callLater(0.5, self.tick)
    def on_notify(self, source, event):        
        self.ansiMap = renderANSI(self.game.map)
        #@TODO: clients should register directly with world
        for c in self.clients:
            c.on_notify(source, event)

    def getAnsiMap(self):
        return self.ansiMap
    def getAnsiFactory(self):
        f = protocol.ServerFactory()
        f.protocol = AnsiGameWorldProtocol
        f.service = self
        f.getAnsiMap = self.getAnsiMap
        return f
Exemplo n.º 2
0
 def __init__(self):
     self.clients = []
     self.game = Game()
     self.mob = Actor("eeeeeeewwwwwww")
     self.game.place(self.mob, (1, 1))
     self.game.register(self.on_notify)
     reactor.callLater(1, self.tick)
Exemplo n.º 3
0
class GameWorldService(service.Service):
    def __init__(self):
        self.clients = []
        self.game = Game()
        self.mob = Actor("eeeeeeewwwwwww")
        self.game.place(self.mob, (1, 1))
        self.game.register(self.on_notify)
        reactor.callLater(1, self.tick)

    def tick(self):
        self.mob.cue()
        reactor.callLater(0.5, self.tick)

    def on_notify(self, source, event):
        self.ansiMap = renderANSI(self.game.map)
        #@TODO: clients should register directly with world
        for c in self.clients:
            c.on_notify(source, event)

    def getAnsiMap(self):
        return self.ansiMap

    def getAnsiFactory(self):
        f = protocol.ServerFactory()
        f.protocol = AnsiGameWorldProtocol
        f.service = self
        f.getAnsiMap = self.getAnsiMap
        return f
Exemplo n.º 4
0
 def __init__(self):
     self.clients = []
     self.game = Game()
     self.mob = Actor("eeeeeeewwwwwww")
     self.game.place(self.mob, (1,1))
     self.game.register(self.on_notify)
     reactor.callLater(1, self.tick)
Exemplo n.º 5
0
    def test_observable(self):
        g = Game()
        a = Avatar()
        
        self.events = 0
        def observer(*args): self.events += 1
        g.register(observer)

        g.spawn(a, (5,5))
        a.walk(Map.SOUTH)
        assert self.events == 2
Exemplo n.º 6
0
class AvatarTest(unittest.TestCase):
    def setUp(self):
        self.g = Game()
        self.a = Avatar()
        self.g.spawn(self.a, (5, 5))

    def test_walk(self):
        assert self.g.locate(self.a) == (5, 5)
        self.a.walk(Map.NORTH)
        assert self.g.locate(self.a) == (5, 4)

    def test_walk_blocked(self):
        self.g.place(Wall(), (5, 4))
        self.a.walk(Map.NORTH)
        assert self.g.locate(self.a) == (5, 5)
Exemplo n.º 7
0
class AvatarTest(unittest.TestCase):

    def setUp(self):
        self.g = Game()
        self.a = Avatar()
        self.g.spawn(self.a, (5,5))
        
    def test_walk(self):
        assert self.g.locate(self.a) == (5,5)
        self.a.walk(Map.NORTH)
        assert self.g.locate(self.a) == (5,4)

    def test_walk_blocked(self):
        self.g.place(Wall(), (5,4))
        self.a.walk(Map.NORTH)
        assert self.g.locate(self.a) == (5,5)
Exemplo n.º 8
0
    def test_cue(self):
        g = Game()
        a = Actor("senw")
        g.place(a, (5,5))

        # it should go in a little circle:
        a.cue(); assert g.locate(a) == (5,6)
        a.cue(); assert g.locate(a) == (6,6)
        a.cue(); assert g.locate(a) == (6,5)
        a.cue(); assert g.locate(a) == (5,5)

        # and then it should repeat:
        a.cue(); assert g.locate(a) == (5,6)
Exemplo n.º 9
0
 def setUp(self):
     self.g = Game()
     self.a = Avatar()
     self.g.spawn(self.a, (5, 5))
Exemplo n.º 10
0
 def setUp(self):
     self.g = Game()
     self.a = Avatar()
     self.g.spawn(self.a, (5,5))