【magickey】...空间玩家P的位置和magickeyK的...
答案:2 悬赏:0 手机版
解决时间 2021-02-11 20:24
- 提问者网友:川水往事
- 2021-02-11 10:52
【magickey】...空间玩家P的位置和magickeyK的...
最佳答案
- 五星知识达人网友:想偏头吻你
- 2021-02-11 12:06
【答案】 #楼上竟然比我还快
def printBoard(playerX, playerY, keyX, keyY):
board = [ ['.']* 8 for _ in range(8) ]
board[playerY][playerX] = 'P'
board[keyY][keyX] = 'K'
print('-'*10)
for i in range(8):
print('|' + ''.join(board[i]) + '|')
print('-'*10)
def updatePosition(direction, playerX, playerY):
d = {'north': (-1, 0),
'south': (1, 0),
'west': (0, -1),
'east': (0, 1) }
direction = direction.lower()
playerX += d[direction][1]
playerY += d[direction][0]
return playerX, playerY
def offboard(pX, pY):
return pX 7 or pY > 7
def reachedKey(playerX, playerY, keyX, keyY):
return playerX == keyX and playerY == keyY
if __name__ == '__main__':
x, y = 2,4
keyX , keyY = 3, 6
print('Welcome to the Loops HW. Get to the key!!!')
printBoard(x, y, keyX, keyY)
while True:
print('North, South, East or West?')
dire = raw_input()
if dire not in ['north', 'south', 'west', 'east']:
continue
x, y = updatePosition(dire, x, y)
if offboard(x, y):
print('offboard')
continue
if reachedKey(x, y, keyX, keyY):
print('You found the magic key!')
break
printBoard(x, y, keyX, keyY)
def printBoard(playerX, playerY, keyX, keyY):
board = [ ['.']* 8 for _ in range(8) ]
board[playerY][playerX] = 'P'
board[keyY][keyX] = 'K'
print('-'*10)
for i in range(8):
print('|' + ''.join(board[i]) + '|')
print('-'*10)
def updatePosition(direction, playerX, playerY):
d = {'north': (-1, 0),
'south': (1, 0),
'west': (0, -1),
'east': (0, 1) }
direction = direction.lower()
playerX += d[direction][1]
playerY += d[direction][0]
return playerX, playerY
def offboard(pX, pY):
return pX 7 or pY > 7
def reachedKey(playerX, playerY, keyX, keyY):
return playerX == keyX and playerY == keyY
if __name__ == '__main__':
x, y = 2,4
keyX , keyY = 3, 6
print('Welcome to the Loops HW. Get to the key!!!')
printBoard(x, y, keyX, keyY)
while True:
print('North, South, East or West?')
dire = raw_input()
if dire not in ['north', 'south', 'west', 'east']:
continue
x, y = updatePosition(dire, x, y)
if offboard(x, y):
print('offboard')
continue
if reachedKey(x, y, keyX, keyY):
print('You found the magic key!')
break
printBoard(x, y, keyX, keyY)
全部回答
- 1楼网友:老鼠爱大米
- 2021-02-11 12:31
这个问题的回答的对
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯