示例#1
0
    def pos_post(self,aid):
        move = int(request.POST.get('move',0))
        log.debug('move: %s'%move)
        if move not in [1,2,4,8]:
            raise HTTPClientError('bad move')
        avatar = Session.query(Avatar).filter(Avatar.name==aid).one()
        current_path = Session.query(Tile).filter(sa.and_(
                            Tile.maze == avatar.maze,
                            Tile.x == avatar.x, Tile.y == avatar.y)).one()
        if not move & current_path.shape:
            raise HTTPClientError('cannot go that way')

        pre_tiles = get_tiles(avatar)[0]

        avatar.x += shape_vector[move][0]
        avatar.y += shape_vector[move][1]
        Session.commit()

        post_tiles, others = get_tiles(avatar)

        visible = [tile for tile in post_tiles if tile not in pre_tiles]

        ret = {'tiles':visible, 'avatar':avatar, 'others':others,
                'maze':avatar.maze}
        return simplejson.dumps(ret, indent=2, default=custom_encode)
示例#2
0
def save(name, width, height, cleared):
    from paste.deploy import appconfig
    from pylons import config

    from resthack.model import Tile, Maze
    from resthack.model.meta import Session

    from resthack.config.environment import load_environment

    conf = appconfig('config:development.ini', relative_to='.')
    load_environment(conf.global_conf, conf.local_conf)

    # make maze
    maze = Maze(name=name,width=width,height=height)
    # make tile objects and store them

    for x,y in cleared:
        shape = 0
        if (x,y-1) in cleared: shape += 1
        if (x+1,y) in cleared: shape += 2
        if (x,y+1) in cleared: shape += 4
        if (x-1,y) in cleared: shape += 8
        Session.add(Tile(x=x, y=y, shape=shape, maze=maze))
    Session.commit()