本文整理汇总了Python中block.Block.get_pic方法的典型用法代码示例。如果您正苦于以下问题:Python Block.get_pic方法的具体用法?Python Block.get_pic怎么用?Python Block.get_pic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类block.Block
的用法示例。
在下文中一共展示了Block.get_pic方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from block import Block [as 别名]
# 或者: from block.Block import get_pic [as 别名]
class Gameboard:
def __init__(self, first_tetro,scoreboard):
self.block_x = 4
self.block_y = 0
self.block = Block(first_tetro)
self.scoreboard = scoreboard
self.gameboard = []
for i in range (0,BOARD_CELL_HEIGHT):
new = []
for j in range (0,BOARD_CELL_WIDTH):
new.append(0)
self.gameboard.append(new)
def move_block(self, dir):
if(dir == LEFT and self.did_horiz_collide()[0] is not True):
self.block_x -= 1
if(dir == RIGHT and self.did_horiz_collide()[1] is not True ):
self.block_x += 1
def new_block(self,new_tetro):
self.block = Block(new_tetro)
self.block_x =4
self.block_y =0
def block_fall(self):
#self.print_gameboard()
#print(self.did_vert_collide())
if not self.did_vert_collide():
self.block_y += 1
return True
else:
self.add_to_board()
return False
def did_vert_collide(self,tetro=None):
if tetro is None:
tetro = self.block.get_pic()
rel_y = -1
for cell in tetro:
rel_y += 1
rel_x = -1
for val in cell:
rel_x +=1
x = self.block_x + rel_x
y = self.block_y + rel_y
if val > 0:
if y >= 15 or y < 0:
return True
if x < 0 or x > 9:
return True
else:
if self.gameboard[y+1][x] > 0:
return True
return False
def did_horiz_collide(self,tetro=None):
if tetro is None:
tetro = self.block.get_pic()
left,right = False,False
rel_y = -1
for cell in tetro:
rel_y += 1
rel_x = -1
for val in cell:
rel_x +=1
x = self.block_x + rel_x
y = self.block_y + rel_y
if val > 0:
if x <= 0:
left = True
elif self.gameboard[y][x-1] > 0:
left = True
if x >= 9:
right = True
elif self.gameboard[y][x+1] > 0:
right = True
return [left,right]
#Lowers all of the lines to replace a destroyed line.
def drop_board(self,max_row):
if max_row == 0:
return
for row in range(max_row,0,-1):
for col in range(0,BOARD_CELL_WIDTH):
self.gameboard[row][col] = self.gameboard[row-1][col]
#Clear the first row
self.destroy_line(0)
#Overwrites a line with 0's
def destroy_line(self,row):
for col in range(0, BOARD_CELL_WIDTH):
self.gameboard[row][col] = 0
self.drop_board(row)
#.........这里部分代码省略.........