display.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:defuse_division 作者: lelandbatey 项目源码 文件源码
def build_contents(cell, player):
    """
    Function build_contents returns a Glyph representing the contents of a
    cell, based on the state of that cell and the player who owns that cell.
    """
    x = ((1 + len(cell['contents'])) * cell['x']) + 1
    y = (2 * cell['y']) + 1
    rv = Glyph(x, y, cell['contents'])
    rv.attr = get_colorpair('black-white')

    # Probed cells show the number of cells they touch and an appropriate color
    if cell['probed']:
        mine_contacts = sum(
            [int(v == True) for _, v in cell['neighbors'].items()])
        # print(mine_contacts)
        rv.strng = " {} ".format(mine_contacts)
        rv.attr = contacts_color(mine_contacts)

    # If our cell's selected, mark it red
    if [cell['x'], cell['y']] == player['minefield']['selected']:
        # logging.error("Selected x,y: {} {}".format(cell['x'], cell['y']))
        rv.attr = get_colorpair('white-red')

    if not cell['probed']:
        rv.strng = Contents.empty
    if cell['flagged']:
        rv.strng = Contents.flag

    if not player['living']:
        if cell['contents'] == Contents.mine:
            rv.strng = Contents.mine
    return rv
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号