次のようなエラーが表示されて困っています。
Traceback (most recent call last):
File "/Users/joelwilliams/Desktop/delete me", line 30, in <module>
v.writef( '======================', 10, 10 )
File "/Users/joelwilliams/Desktop/delete me", line 24, in writef
self.write( word )
File "/Users/joelwilliams/Desktop/delete me", line 15, in write
self.l[ self.y ] [ self.x : ( self.x + len( word ) ) ] = word
IndexError: list index out of range
メインコードは次のとおりです。
class board():
def __init__( self ):
self.x, self.y = 0, 0
self.l = []
self.screenWidth, self.screenHeight = 0, 0
def createBoard( self ):
listBig = [ ['`'] * self.screenWidth for _ in range( self.screenHeight ) ]
def setup( self, sw, sh ):
self.screenWidth = sw - 1
self.screenHeight = sh - 1
def write( self, word ):
self.l[ self.y ] [ self.x : ( self.x + len( word ) ) ] = word
def draw( self ):
for v in self.l:
print(''.join(v))
def writef( self, word, y, x ):
self.cursorPosX = x - 1
self.cursorPosY = y - 1
self.write( word )
v = board()
v.setup( 75, 20 )
v.createBoard()
v.writef( '======================', 10, 10 )
v.writef( '= =', 11, 10 )
v.writef( '= Pls Work. =', 12, 10 )
v.writef( '= =', 13, 10 )
v.writef( '======================', 14, 10 )
v.draw()
望ましい結果は、コンソールに次のように表示されることです。
======================
= =
= Pls Work. =
= =
======================
上記のコードを作成するためのガイドとしてこれを使用しました。