int对象是无法编写脚本的Python

2024-09-29 23:30:18 发布

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

我正在尝试制作战舰来练习,单人游戏很成功…当时只有一个玩家,一组飞船和一块木板: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 –


Tags: theinselfboardforisrangecolumn

热门问题