如何为我的二十一点游戏画一张扑克牌?
问题描述:
def box_lines(lines, width):
topBottomRow = "┌" + "-" * width + "┐"
# bottomRow = "└" + "-" * length + "┘"
middle = "\n".join("|" + x.ljust(width) + "|" for x in lines)
return "{0}\n{1}\n{0}".format(topBottomRow, middle)
def split_line(line, width):
return [line[i:i + width] for i in range(0, len(line), width)]
def split_msg(msg, width):
lines = msg.split("\n")
split_lines = [split_line(line, width) for line in lines]
return [item for sublist in split_lines for item in sublist]
def border_msg(msg, width):
return(box_lines(split_msg(msg, width), width))
print(border_msg("""♣
♣""", 20))
这就是我不断收到....如何为我的二十一点游戏画一张扑克牌?
┌--------------------┐
|♣ |
| |
| ♣|
┌--------------------┐
我不知道如何解决它。我正在尝试为我的oop blackjack游戏画一张卡片。卡片需要更长,并且我在代码中注释的底部符号需要用来制作完整的矩形。
答
这是你想要实现的东西吗?
def border_msg(color, height, width):
card_content_width = width - 2
lines = ['┌' + '-' * card_content_width + '┐']
lines.append('|' + color + ' ' * (card_content_width - 1) + '|')
lines.extend(['|' + ' ' * card_content_width + '|' for i in range(height - 4)])
lines.append('|' + ' ' * (card_content_width - 1) + color + '|')
lines.append('└' + '-' * card_content_width + '┘')
return '\n'.join(lines)
print(border_msg("♣", 10, 20))
上面的代码给你这样的卡:
┌------------------┐
|♣ |
| |
| |
| |
| |
| |
| |
| ♣|
└------------------┘
+0
这正是我所需要的样子!感谢您的帮助,我真的很感激。 –
应的卡是什么样子? – valtron
我只想要一张简单的纸牌。 –
问题是你没有使用底行?这就是为什么这些小角落被翻转的原因 - 您也在底部使用顶行。 – dashnick