Last active
May 3, 2021 06:47
-
-
Save pcchou/94ef5fd617e7d48765f259eaabb32ee0 to your computer and use it in GitHub Desktop.
Finished part3(資芽 py 2021 大作業練習)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import config | |
def getCellsAbsolutePosition(piece): | |
'''取得方塊當前所有方格的座標''' | |
return [(y + piece.y, x + piece.x) for y, x in piece.getCells()] | |
def printPiece(shot, piece): | |
print('目前方塊:', getCellsAbsolutePosition(piece)) | |
### Let's practice NOW! | |
def moveLeft(shot, piece): | |
for y, x in getCellsAbsolutePosition(piece): | |
if x == 0 or shot.status[y][x - 1] == 2: | |
return | |
piece.x -= 1 | |
def moveRight(shot, piece): | |
for y, x in getCellsAbsolutePosition(piece): | |
if x + 1 == config.columns or shot.status[y][x + 1] == 2: | |
return | |
piece.x += 1 | |
def moveUp(shot, piece): | |
for y, x in getCellsAbsolutePosition(piece): | |
if y == 0 or shot.status[y - 1][x] == 2: | |
return | |
piece.y -= 1 | |
def moveDown(shot, piece): | |
for y, x in getCellsAbsolutePosition(piece): | |
if y + 1 == config.rows or shot.status[y + 1][x] == 2: | |
return | |
piece.y += 1 | |
def printMap(shot, piece): | |
print('Print Map:') | |
print('---'*4) | |
for y in range(config.rows): | |
for x in range(config.columns): | |
print(shot.status[y][x], end='') | |
print() | |
print('---'*4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment