コード例 #1
0
 def render_JSON(self, request):
     request.setHeader("content-type", "application/json")
     game = IGame(self)
     player = request.getSession()
     return json.dumps({
         'room': self.name,
         'game': game.__class__.__name__,
         'data': game.render_JSON(request),
         'you': player.name,
         'your_score': player.score,
     })
コード例 #2
0
ファイル: GameRoom.py プロジェクト: isnok/mpmf
 def render_JSON(self, request):
     request.setHeader("content-type", "application/json")
     game = IGame(self)
     player = request.getSession()
     return json.dumps({
         'room': self.name,
         'game': game.__class__.__name__,
         'data': game.render_JSON(request),
         'you': player.name,
         'your_score': player.score,
     })
コード例 #3
0
    def render(self, request):
        if request.args:
            self.gotArgs(request)
            IGame(self).gotArgs(request)

        if hasattr(request, 'wantsJSON'):
            return self.render_JSON(request)
        else:
            return self.render_HTML(request)
コード例 #4
0
    def render_HTML(self, request):
        if request.args:
            head = '<head><meta http-equiv="refresh" content="1; url=/play/%s" ></head>' % self.name
        else:
            head = '<head><meta http-equiv="refresh" content="1" ></head>'

        game = IGame(self)
        room = IGameRoom(self)
        player = request.getSession()
        text = ["Hello %s, welcome to %s." % (player.name, self.name)]
        text.append('You can <a href="/">go back</a> or play a game.<br>')
        text.append('You have %s points.' % player.score)
        text.append('People in this room: %s' % [p.name for p in room.players])
        text.append("This game is called %r." % game.title)
        text.append("Try it yourself, it's fun!")
        text.append('')
        text.append("<pre>%s</pre>" % game.render_HTML(request))

        body = "<body>%s</body>" % "<br>".join(text)
        return "<html>%s%s</html>" % (head, body)
コード例 #5
0
ファイル: GameRoom.py プロジェクト: isnok/mpmf
    def render_HTML(self, request):
        if request.args:
            head = '<head><meta http-equiv="refresh" content="1; url=/play/%s" ></head>' % self.name
        else:
            head = '<head><meta http-equiv="refresh" content="1" ></head>'

        game = IGame(self)
        room = IGameRoom(self)
        player = request.getSession()
        text = [ "Hello %s, welcome to %s." % (player.name, self.name) ]
        text.append('You can <a href="/">go back</a> or play a game.<br>')
        text.append('You have %s points.' % player.score)
        text.append('People in this room: %s' % [p.name for p in room.players])
        text.append("This game is called %r." % game.title)
        text.append("Try it yourself, it's fun!")
        text.append('')
        text.append("<pre>%s</pre>" % game.render_HTML(request))

        body = "<body>%s</body>" % "<br>".join(text)
        return "<html>%s%s</html>" % (head, body)
コード例 #6
0
ファイル: BaseRunner.py プロジェクト: isnok/mpmf
 def update(self, data):
     name = data['game']
     if not name == self.ongoing:
         self.switchGame(name)
     game = IGame(self)
     game.update(data)
     game.handle()
コード例 #7
0
 def link(tup):
     name, room = tup
     title = IGame(room).title
     names = [p.name for p in room.players]
     return '<a href="/play/%s">%s: %s</a> - %d player(s): %s' % (
         name, name, title, len(names), ", ".join(names))
コード例 #8
0
 def stopService(self):
     log.msg("Room close: %s" % self.name)
     IGame(self).stopService()
     return Service.stopService(self)
コード例 #9
0
 def startService(self):
     log.msg("Room open: %s" % self.name)
     IGame(self).startService()
     Service.startService(self)
コード例 #10
0
 def chainload(self, game):
     room = self.original
     room.setAdapter(IGame, game)
     IGame(room).startService()
     self.stopService()