本文整理汇总了Python中shape.Shape.move_down方法的典型用法代码示例。如果您正苦于以下问题:Python Shape.move_down方法的具体用法?Python Shape.move_down怎么用?Python Shape.move_down使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shape.Shape
的用法示例。
在下文中一共展示了Shape.move_down方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import move_down [as 别名]
class Board:
def __init__(self, window, width=10, height=16, xinit=2, yinit=2, tile_width=15):
self.tiles = Tiles(tile_width, window)
self.window = window
self.height = height
self.xinit = xinit
self.yinit = yinit
self.width = width
self.total_lines = 0
self.board = [[0 for j in range(width)] for i in range(height)]
self.shape = None
self._draw()
self.clear()
def add_shape(self):
assert not self.shape
sh, col = random.choice(shape_color)
self.shape = Shape(sh, self.window, col, self.width/2, 0, self.xinit, self.yinit)
if self.collides(self.shape):
raise GameOver()
self.shape.draw()
def eat_shape(self):
self.shape.erase()
for x,y in self.shape.shape:
self.board[y+self.shape.y][x+self.shape.x] = 1
self.shape = None
def frame(self, pressed_keys):
if not self.shape:
return
shapex = self.shape.x
shapey = self.shape.y
shape_shape = deepcopy(self.shape.shape)
self.shape.update_pos(pressed_keys)
if self.collides(self.shape):
self.shape.x = shapex
self.shape.y = shapey
self.shape.shape = shape_shape
else:
self.shape.draw()
def collides(self, shape):
for x,y in shape.shape:
x += shape.x
y += shape.y
if x < 0 or x >= self.width:
return True
if y >= self.height or y < 0:
return True
if self.board[y][x] == 1:
return True
return False
def collides_bottom(self, shape):
for x,y in shape.shape:
x += shape.x
y += shape.y
if y+1 >= self.height:
return True
if self.board[y+1][x]:
return True
return False
def tick(self):
self._erase()
if not self.shape:
self.add_shape()
elif not self.collides_bottom(self.shape):
self.shape.erase()
self.shape.move_down()
self.shape.draw()
elif self.collides_bottom(self.shape):
self.eat_shape()
self.check_lines()
self._draw()
def check_lines(self):
for i in range(self.height):
if self.check_line(self.board[i]):
self.board.pop(i)
self.total_lines += 1
print self.total_lines
self.board = [[0 for i in range(self.width)]] + self.board
def check_line(self, line):
for i in line:
if not i:
return False
return True
def _draw(self, draw_f=Tiles.square):
for y in range(self.height):
for x in range(self.width):
if self.board[y][x]:
draw_f(self.tiles, x+self.xinit, y+self.yinit)
def _erase(self):
#.........这里部分代码省略.........