本文整理汇总了Python中piece.Piece.rotate方法的典型用法代码示例。如果您正苦于以下问题:Python Piece.rotate方法的具体用法?Python Piece.rotate怎么用?Python Piece.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类piece.Piece
的用法示例。
在下文中一共展示了Piece.rotate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: answer
# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import rotate [as 别名]
def answer(state_map, state_piece, x, dx, rad):
map_tmp = copy.deepcopy(const.map)
for i in range(len(state_map)):
if state_map[i] != 0:
map_tmp[state_map[i]][i] = 1
p_tmp = Piece(state_piece, x)
p_tmp.updateMap(map_tmp)
gain = 0
if dx>0:
for i in range(dx):
p_tmp.move('right')
else:
for i in range(-dx):
p_tmp.move('left')
for i in range(rad):
p_tmp.rotate('ccw')
p_tmp.drop()
for i in range(len(p_tmp.shape[0])):
for j in range(len(p_tmp.shape[0][i])):
if p_tmp.shape[0][i][j]:
map_tmp[p_tmp.y+i][p_tmp.x+j] = p_tmp.shape[1]
erasable = []
for i in range(len(map_tmp)-1):
flag_full = True
for j in range(1,len(map_tmp[i])-1):
if map_tmp[i][j] == 0 or map_tmp[i][j] == 8: flag_full = False
if flag_full:
erasable.append(i)
if len(erasable) == 0:
gain = 0
else:
gain = scores[min(len(erasable)-1, 3)]
for i in erasable:
for j in range(i-2):
map_tmp[i-j] = copy.deepcopy(map[i-j-1])
for i in range(len(map_tmp)):
for j in range(len(map_tmp[i])):
if map_tmp[i][j]!=0:
map_tmp[i][j] = 1
return [map_tmp, gain]
示例2: __init__
# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import rotate [as 别名]
class PtModel:
#class variables
FPS = 60
SCORE = [0, 40, 100, 300, 1200]
TIME = {
"fell": -100,
"moved": -100,
"rotated": -20,
"stopped_moving": -30,
"stopped_rotating":-30
}
INTERVAL = {
"move": 0.3,
"rotate": 0.3,
"gravity": 0.3
}
def __init__(self, gravity = 0.3):
self.view = PtView()
self.board = Board()
self.p = Piece(self.board)
self.p_next = Piece(self.board)
self.score = 0
self.line_erasable = []
self.interval = copy.deepcopy(PtModel.INTERVAL)
self.interval['gravity'] = gravity
self.time = copy.deepcopy(PtModel.TIME)
self.flag = {
'moving': True,
'rotating': True
}
self.view.renderNext(self.p_next.getShape(), self.p_next.getType())
def getKey(self):
pygame.event.pump()
keys = pygame.key.get_pressed()
# 移動のキーn
if self.isMovable():
if keys[K_LEFT]:
self.movePiece('left')
elif keys[K_RIGHT]:
self.movePiece('right')
elif keys[K_UP]:
self.movePiece('up')
elif keys[K_DOWN]:
self.movePiece('down')
if self.p.isGround() == False:
self.time['moved'] = time.clock()
else:
# 動くのをやめた時だけインターバル回復
# if self.flag['moving']:
self.flag['moving'] = False
self.time['stopped_moving'] = time.clock()
self.interval['move'] = PtModel.INTERVAL['move']
# 回転のキー
if self.isRotatable():
if keys[K_z]:
self.rotatePiece('ccw')
elif keys[K_x]:
self.rotatePiece('cw')
else:
# if self.flag['rotating']:
self.flag['rotating'] = False
self.time['stopped_rotating'] = time.clock()
self.interval['rotate'] = PtModel.INTERVAL['rotate']
def isMovable(self):
if (time.clock() - self.time['moved']) > self.interval['move']:
return True
if (time.clock() - self.time['stopped_moving'])< PtModel.INTERVAL['move']:
return True
return False
def isRotatable(self):
if (time.clock() - self.time['rotated']) > self.interval['rotate']:
return True
if (time.clock() - self.time['stopped_rotating'])< PtModel.INTERVAL['rotate']:
return True
return False
def movePiece(self, direction):
if direction == 'up':
self.p.drop()
else:
self.p.move(direction)
self.time['moved'] = time.clock()
if self.interval['move'] > 0.1:
self.interval['move'] *= 0.9
# self.flag['moving'] = True
def rotatePiece(self, radius):
self.p.rotate(radius)
self.time['rotated'] = time.clock()
if(self.interval['rotate']>0.1):
self.interval['rotate'] *= 0.9
# self.flag['rotating'] = True
#.........这里部分代码省略.........
示例3: rotate_piece
# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import rotate [as 别名]
def rotate_piece(piece, orientation):
new_piece = Piece()
new_piece._list = list(piece._list)
new_piece.rotate(orientation)
return new_piece
示例4: BlokusPiece
# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import rotate [as 别名]
class BlokusPiece(Widget):
"""
This object defines a Blokus piece widget
which includes as fields a "Piece" object
that includes the piece geometry, and a list
of "Block" widgets that instantiates that
geometry on the board.
methods:
update_blocks: move the blocks that make up the piece
so that they have the right relative positions.
update: Move the piece. If the piece is grabbed, move with
the cursor. If the piece is not grabbed, go to the setpoint
if it is not already there. The setpoint can be either a home
or a local grid point.
on_touch_down: Identifies when we are grabbing the piece
on_touch_up: Identifies when we release a piece.
on_touch_move: Identifies when we are dragging a piece.
flip: Flips piece by calling the Piece.flip method
rotate: Rotates piece by calling the Piece.rotate method.
"""
pieceID = NumericProperty(0)
playerID = NumericProperty(0)
rotation = NumericProperty(0)
parity = NumericProperty(1)
def __init__(self, d=0,
corner_offset=(0,0),
move_increment=.2,
stop_tolerance=.1,
**kwargs):
super(BlokusPiece, self).__init__(**kwargs)
self.piece = Piece(
self.pieceID,
self.playerID,
rotation=self.rotation,
parity=self.parity)
self.d = int(d)
self.corner_offset = corner_offset
self.increment = move_increment
self.tolerance = stop_tolerance
with self.canvas:
self.blocks = []
self.rel_pos = []
self.grabbed = False # use this to indicate whether or not i'm holding the piece
self.enabled = True
self.go_to_setpoint = False
self.home = (0, 0)
self.setpoint = (0, 0)
self.wait = (0, 0)
size = self.piece.geometry.shape
self.size = (self.d * size[0], self.d * size[1])
for i in range(size[0]):
for j in range(size[1]):
if self.piece.geometry[i, j] == 1:
block = Block(playerID=self.playerID, d=self.d)
self.blocks = self.blocks + [block]
self.bind(pos=self.update_blocks)
def update_blocks(self, *args):
"""
moves the blocks that make up the blokus piece
"""
index = 0
Size = self.piece.geometry.shape
self.size = (self.d * Size[0], self.d * Size[1])
for i in xrange(Size[0]):
for j in xrange(Size[1]):
if self.piece.geometry[i, j] == 1:
self.blocks[index].pos = (
i * self.d + self.pos[0], j * self.d + self.pos[1])
index += 1
def update(self):
"""
this function updates on the clock. This is mostly providing a "snap to grid" feature
"""
if not(self.grabbed):
current_position = self.pos
if self.go_to_setpoint:
final_position = (
float(self.setpoint[0]),
float(self.setpoint[1]))
else:
final_position = (
float(np.round((self.pos[0]) / self.d - self.corner_offset[0]) * self.d + (self.corner_offset[0] * self.d)),
float(np.round((self.pos[1]) / self.d - self.corner_offset[1]) * self.d + (self.corner_offset[1] * self.d)))
direction = (
final_position[0] -
current_position[0],
final_position[1] -
current_position[1])
# how far towards the final position should it go in one step
changed_position = (
#.........这里部分代码省略.........