Ejemplo n.º 1
0
def watch(file):
    import json, importlib, pygame, continuousEngine
    pygame.init()
    with open(file) as f:
        info = json.loads(f.read())

    name = info['type']
    game = continuousEngine.game_class(name)(*info['args'])
    def _f(_=None):
        game.future = [info['state']]+info['history'][:0:-1]
        game.load_state(info['history'][0])
    game.keyPress[game.keys.resetGame] = _f
    _f()


    game.attemptMove = lambda _: False

    continuousEngine.GameInfo(game,
        lambda _: [
            ('file', file),
            ('game', name),
            ('turn', game.turn),
            (None, None),
            *((t, info['players'][t]) for t in game.teams),
            *([] if game.future else [('winner',info['winner']), ('ending',info['ending'])])
        ]
    )

    print(f'turns: {len(game.future)}')
    print(f'winner: {info["winner"]}')
    if info['ending'] == 'error': print('game ended in error')

    game.run()
Ejemplo n.º 2
0
 def create_game(self, name, id, args):
     if id in self.list_games():
         print('game {} already exists'.format(id), flush=True)
         return
     game = continuousEngine.game_class(name)(*args, headless=True)
     self.games[id] = {"game_type": name, "players": [], "game": game}
     return id
Ejemplo n.º 3
0
 async def attempt_joining(id, t):
     await NetworkGame(await asyncio.get_running_loop().run_in_executor(None, continuousEngine.game_class(game), *args)).join(s, id, t, username)
Ejemplo n.º 4
0
 async def attempt_joining(id, t):
     send(s, {"action":"gameargs", "id":id})
     gargs, gkwargs = await receive(s)
     timectrl = gkwargs['timectrl']
     gkwargs['timectrl']=None
     await NetworkGame(await asyncio.get_running_loop().run_in_executor(None, functools.partial(continuousEngine.game_class(game), *gargs, **gkwargs)), timectrl).join(s, id, t, username)