I just started my first programming course in Python and I'm having trouble understanding what's wrong with my code for Game of life. Our task is to create the grid that the game will play in but I can't understand what is wrong with my code (see below).
def paint(target_window, grid):
height = len(grid)
width = len(grid[0])
target_window.setCoords(0,height,width,0)
for row in range(height):
for col in range(width):
rect = Rectangle(Point(row,col),Point(row + 1, col + 1))
rect.draw(target_window)
target_window.update()
More specific the grid is supposed to be "infinite" so that the game isn't restricted. I think that my .setCoords
may have something to do with what's wrong.
In case you are using this Graphics library, indeed your call of setCoords
is wrong. Try to change it into this
target_window.setCoords(0,0,width,height)
The documentation says
setCoords(xll, yll, xur, yur) Sets the coordinate system of the window. The lower- left corner is (xll, yll) and the upper-right corner is (xur, yur). All subsequent drawing will be done with respect to the altered coordinate system (except forplotPixel).
... and there is also issue with the indentation of rect.draw(target_window)
, as mkrieger1 pointed out.