我正在尝试制作战舰来练习,单人游戏很成功…当时只有一个玩家,一组飞船和一块木板:p
你知道为什么这会给我一个“int object is unscriptable”错误吗???在
这是板卡课。好吧,不管怎样,还是有些:
class Board:
'Game Board'
topMarkers = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
sideMarkers = list(range(0, 26))
def __init__(self,h,w): #Makes the map
self.height = h
self.width = w
self.xMarkers = []
self.yMarkers = []
self.hitList = []
self.hitListCopy = []
self.boardSpace = ' '
wave = '~'
self.row = []
self.column = []
#self.column = wave * self.width # If width is 4, column is now '~~~~'
for c in range(self.width):
self.column.append(wave)
self.xMarkers.append(Board.topMarkers[c])
for r in range(self.height): #
self.row.append(self.column[:]) #Use the slice to make copies
self.yMarkers.append(Board.sideMarkers[r])
def showGrid(self):
print self.boardSpace + ' ' + ' '.join(self.xMarkers)
for i in range(self.height):
print self.boardSpace + str(self.yMarkers[i]) + ' ' + '-'.join(self.row[i])
这是实际运行它的代码,导致它的代码部分在底部while和for循环中,它在注释中说要显示地图的网格。在
^{pr2}$谢谢
这是我收到的确切信息。在
Traceback (most recent call last): File "name/battleship_wClasses.py", line 431, in p[i][0][1].showGrid() #Show the grid of the player (TheirShips) TypeError: 'int' object is unsubscriptable –
对于
p
,有两个(重叠的)相互矛盾的定义:以及
^{pr2}$p[i][0][1].showGrid()
与第一个定义一起工作,但是当从第二个定义中为p
分配一个整数值时,p[i][0][1].showGrid()
将失败。在相关问题 更多 >
编程相关推荐