本文整理汇总了Python中block.Block.tellAllPos方法的典型用法代码示例。如果您正苦于以下问题:Python Block.tellAllPos方法的具体用法?Python Block.tellAllPos怎么用?Python Block.tellAllPos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类block.Block
的用法示例。
在下文中一共展示了Block.tellAllPos方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from block import Block [as 别名]
# 或者: from block.Block import tellAllPos [as 别名]
class Game:
def __init__(self, row_size, col_size):
#設置
#橫列數
self.row_size = row_size
#直行數
self.col_size = col_size
#棋盤
self.board = []
#方塊
self.block = None
#得分
self.score = 0
for i in range(row_size):
li = [0] * col_size
self.board.append(li)
self.newBlock()
def draw(self):
#繪圖
# 把方塊和棋盤合到暫時棋盤
tmp_board = deepcopy(self.board)
all_pos = self.block.tellAllPos()
for row, col in all_pos:
tmp_board[row][col] = self.block.color_num
#清除螢幕
print('\n' * 25)
#印出暫時棋盤
print(' '*7,'我的俄羅斯方塊 分數:',self.score)
print(' '*7, end='')
for i in range(self.col_size) :
print( format(i,'2') , end='')
print()
for j, row in enumerate(tmp_board):
print(' '*4, format(j,'2') , end='')
for col in row :
if col >= 1:
print('■', end='')
else:
print('□', end='')
print()
print(' '*7, end='')
def newBlock(self):
#新方塊
self.block = Block(0, self.col_size//2)
for row, col in self.block.tellAllPos():
if self.board[row][col] > 0:
self.mergeBlock()
self.draw()
print("遊戲結束")
sys.exit()
def mergeBlock(self):
#合併方塊
for row, col in self.block.tellAllPos():
self.board[row][col] = self.block.color_num
#self.eraseBlock()
#self.newBlock()
def eraseBlock(self):
#消方塊
row_set = set()
for r, _ in self.block.tellAllPos():
row_set.add(r)
need_erased_row = []
for rs in row_set:
count = 0
for i in self.board[rs]:
if i : count+=1
if count == self.col_size: need_erased_row.append(rs)
row_num = len(need_erased_row)
if row_num:
self.draw()
sleep(0.4)
need_erased_row.sort()
need_erased_row.reverse()
for n in need_erased_row:
self.board.pop(n)
for _ in range(row_num):
#.........这里部分代码省略.........