本文整理汇总了Python中shape.Shape.rotate方法的典型用法代码示例。如果您正苦于以下问题:Python Shape.rotate方法的具体用法?Python Shape.rotate怎么用?Python Shape.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shape.Shape
的用法示例。
在下文中一共展示了Shape.rotate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Tetris
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import rotate [as 别名]
class Tetris(object):
W = 12 # the width of play board
H = 20 # the height of play board
TILEW = 20 # the pixel width/height of a tile
START = (100, 40) # the playboard lefttop on background
SPACE = 1000 # shape will fall after xxx ms(level 1)
def __init__(self, screen):
self.stat = "game"
self.WIDTH = self.TILEW * self.W
self.HEIGHT = self.TILEW * self.H
self.screen = screen
self.pause = False
# the array save current situation
# same as screen cood
self.board = []
for i in xrange(self.H):
line = [ None ] * self.W
self.board.append(line)
# will display
self.level = 1
self.killed = 0
self.score = 0
# after this time, shape falls
self.time = self.SPACE * 0.9 ** (self.level - 1)
# save the elapsed time after last fail
self.elapsed = 0
# used for judge pressed firstly or for a long time
self.pressing = 0
# the moving shape
self.shape = Shape(self.START,
(self.WIDTH, self.HEIGHT), (self.W, self.H))
self.shape.set_board(self.board)
self.board_image = pygame.Surface((self.WIDTH, self.HEIGHT))
# draw the background once
self.screen.blit(pygame.image.load(
util.file_path("background.jpg")).convert(), (0, 0))
self.display_info()
def update(self, elapse):
for e in pygame.event.get():
if e.type == KEYDOWN:
self.pressing = 1
self.move(e.key == K_UP, e.key == K_DOWN,
e.key == K_LEFT, e.key == K_RIGHT)
if e.key == K_ESCAPE:
self.stat = 'menu'
elif e.key == K_SPACE:
self.pause = not self.pause
elif e.type == KEYUP and self.pressing:
self.pressing = 0
elif e.type == QUIT:
self.stat = 'quit'
if self.pause:
self.draw()
return self.stat
if self.pressing:
pressed = pygame.key.get_pressed()
self.move(pressed[K_UP], pressed[K_DOWN],
pressed[K_LEFT], pressed[K_RIGHT])
self.elapsed += elapse
if self.elapsed >= self.time:
self.next()
self.elapsed = self.elapsed - self.time
self.draw()
return self.stat
def move(self, u, d, l, r):
if not (u or d or l or r):
return
# pressed for the first time
# pressed for a long time
if self.pressing == 1 or self.pressing > 10:
if u: self.shape.rotate()
elif d: self.next() #self.shape.move(0, 1) is bad
elif l: self.shape.move(-1, 0)
elif r: self.shape.move(1, 0)
self.draw()
self.pressing += 1
def check_line(self):
self.add_to_board()
filled = []
for i in xrange(self.H-1, -1, -1):
line = self.board[i]
sum = 0
for t in line:
sum += 1 if t else 0
if sum == self.W:
filled.append(i)
elif sum == 0:
break
if i == 0 and sum !=0:
self.game_over()
self.create_board_image() # used for killing animation
self.kill_line(filled)
self.create_board_image() # used for update
def kill_line(self, filled=[]):
if len(filled) == 0:
return
#.........这里部分代码省略.........
示例2: test_rotate
# 需要导入模块: from shape import Shape [as 别名]
# 或者: from shape.Shape import rotate [as 别名]
def test_rotate(self):
shape = Shape([Vec2D(1, 1), Vec2D(1, 3)], Vec2D(1, 2))
shape2 = Shape([Vec2D(1, 1), Vec2D(1, 3)], Vec2D(1, 2))
must_be_equal(set(shape2), set(shape.rotate(4)))