我正在尝试编写命令行minesweeper克隆,而我的地雷生成器代码遇到了一些麻烦。
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
我以为这意味着我以错误的方式引用了列表,但是我将如何正确地做到这一点呢?
Qyouu
浮云间
饮歌长啸
相关分类