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
评论列表
文章目录