列表超出范围(地图)

2024-10-16 20:43:50 发布

您现在位置:Python中文网/ 问答频道 /正文

在Python3.7中,我的列表超出了映射的范围,我尝试了多种方法来修复它(这是我正在制作的俄勒冈小径游戏)

我试过改变max x和max y

trail = [[1 for x in range(maxx)]for y in range(maxy)]
trail [25][2] = "Fort Kearney"
trail [26][2] = "St. Joseph"
trail [24][2] = "Ash Hollow"
trail [22][2] = "Chimney Rock"
trail [22][2] = "Fort Laramie"
trail [29][2] = "Independence Rock"
trail [27][2] = "Fort Bridger"
trail [24][2] = "Sublette Cutoff"
trail [23][2] = "North Platte River Crossing"
trail [23][2] = "Fort Hall"
trail [22][2] = "Snake River Crossing"

我得到了错误信息

/Python/Python37-32/oregontrail.py", line 15, in <module>
    trail [25][2] = "Fort Kearney"
IndexError: list index out of range
>>>

Tags: 方法in游戏列表forrangemaxtrail