我试图创建这个游戏,蜗牛"@“将在这个方框内按你想要的方向移动。当它移动到一个空间时,它会留下一条小径。"_“。我对它进行了编码,这样它才能向右移动,但我不知道要改变什么,这样它才能向下移动。
column = int(input("column"))
gameField = []
for i in range(row):
gameField.append([])
for j in range(column):
gameField[i].append(" ")
def printField(listField):
for i in listField:
for j in i:
print(j, end= " ")
print()
curRow = 0
curCol = 0
gameField[curRow][curCol] = "@"
game = True
while game:
direction = input("wasdq")
if direction == "q":
game = False
elif direction == "d":
if curCol+1 == column:
print("try again")
else:
gameField[curRow][curCol] = "_"
curCol += 1
gameField[curRow][curCol] = "@"
printField(gameField)
elif direction == "s":
if curCol+1 == column:
print("try again")
else:
gameField[curRow][curCol] = "_"
curCol = curCol - 1
gameField[curRow][curCol] = "@"
printField(gameField)发布于 2021-12-07 02:35:44
对于初学者,您的用户提示不太清楚。我会说这样的话
columns = int(input("Enter Columns: "))对于wasdq来说也是一样的,因为我不知道该如何处理它。
但是不管怎么说,如果改变了栏目,你的蜗牛左右移动,你如何上下移动蜗牛?
matrix = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
# This is a matrix that looks like
# [0, 1, 2]
# [3, 4, 5]
# [6, 7, 8]
zero = matrix[0][0]
one = matrix[0][1]
three = matrix[1][0]
four = matrix[1][1]如果蜗牛生活在矩阵上,向右移动就相当于从单元格0移动到单元格1(举个例子),向下移动相当于从单元格0移动到单元格3(举个例子)。
https://stackoverflow.com/questions/70254142
复制相似问题