示例#1
0
    def _render_head(board):
        meta = '<meta http-equiv="content-type" content="text/html; charset=UTF-8">'
        title = "<title>carcasonne board construction sample</title>"
        jquery = '<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>'

        images = []
        for tile in board.grid.values():
            if tile.rotation != 0:
                images.append(
                    '$("#%s").rotate(%s);'
                    % (
                        HtmlRenderer.tile_to_id(tile),
                        HtmlRenderer._rotation_to_deg(ROTATIONS.by_ordinal(tile.rotation)),
                    )
                )

        rotation = """<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
%s
});//]]>  
</script>""" % (
            "\n".join(images)
        )

        return "<head>\n%s\n%s\n%s\n%s\n</head>" % (meta, title, jquery, rotation)
示例#2
0
    def pos_to_tile_xy(pos, rotation):
        x = int(float(pos["x"]) / 100.0 * float(Renderer.tile_width))
        y = int(float(pos["y"]) / 100.0 * float(Renderer.tile_height))

        rot = ROTATIONS.by_ordinal(rotation)
        angle = int(rot[3:])
        x, y = Renderer.rotate(x, y, angle)

        return x, y
示例#3
0
    def _play_tile(self, tid, location, rotation):
        # remove location from playable locations
        if location in self.edges:
            self.edges.remove(location)

        # set actual values in the tile
        tile = self.boardtiles[tid]
        tile.location = location
        tile.rotation = rotation
        self.grid[location] = tile
        self.tilesleft.remove(tid)

        # keep track of playable locations
        for n in self.neighbours_for(location):
            # add all neighbours that aren't played tiles == empty locations
            if type(n) is not PlayedTile:
                self.edges.add(n)

        self._update_graphs(tid, location)

        logging.info("Played tile %s at location %s, rotated %s" % (tid, location, rotation))
        logging.debug("b.add_to_board('%s', %s, tile.ROTATIONS.%s))" % (tid, location, ROTATIONS.by_ordinal(rotation)))