我试图在控制台中创建一个竞技场风格的游戏,但我需要一些帮助。我已经有了网格,我现在能够移动玩家,但我不认为我能以最好的方式做到这一点。什么是更好的方式?
import subprocess as sp
plyr_x, plyr_y = (9,5)
def create_board():
board = []
for _ in range(10):
board.append(['-']*10)
board[plyr_x][plyr_y] ='o'
return board
def print_board(board):
tmp = sp.call('clear')
for row in board:
print ' '.join(row)
board = create_board()
print_board(board)
while True:
direction = raw_input('Which way do you want to move? ')
if direction == 'up':
plyr_x += -1
print_board(create_board())
elif direction == 'down':
plyr_x += 1
print_board(create_board())
elif direction == 'right':
plyr_y += 1
print_board(create_board())
elif direction == 'left':
plyr_y += -1
print_board(create_board())
答案 0 :(得分:0)
例如:
将玩家当前位置保留在元组(x,y)
中提示:
direction = input('which direction?')
明确旧职位:
board[y][x] = ' '
更新新位置(x,y)(将该逻辑留给您)
更新电路板:
board[y][x] = 'X'