我正在尝试编写命令行扫雷克隆,但我的地雷生成器代码遇到了一些问题。
def genWorld(size, mines):
world = []
currBlock = []
for i in range(size):
for j in range(size):
currBlock.append("x")
world.append(currBlock)
currBlock = []
for i in range(mines):
while True:
row = randint(0, size)
col = randint(0, size)
if world[row[col]] != "M":
break
world[row[col]] = "M"
printWorld(world)
当我运行它时,我收到错误:
Traceback (most recent call last):
File "C:\Python33\minesweeper.py", line 28, in <module>
genWorld(9, 10)
File "C:\Python33\minesweeper.py", line 23, in genWorld
if world[row[col]] != "M":
TypeError: 'int' object is not subscriptable
我想这意味着我以错误的方式引用列表,但我将如何正确地做到这一点?