Reputation: 827
I created a game board:
win = GraphWin ("Gameboard",500,500)
win.setCoords(0.0,0.0,10.0,10.0)
drawBoard(win)
for i in range(10):
Line(Point(0,i),Point(10,i)).draw(win)
for x in range(10):
Line(Point(x,0),Point(x,10)).draw(win)
I have a 10x10 grid, of which the playable range is going to be from (2,2) to (9,9). For any grid marks with x = 1, x = 10, y = 1, or y = 10, I want those sections of the grid to be black and form a border. I have been enlisting google regarding how to do this, but I haven't found a fill option that seems applicable. Could someone point me in the right direction?
Upvotes: 2
Views: 2130
Reputation: 41872
I figure I can just overlay those sections of the grid with black rectangles, but I'm sure there's a more elegant solution.
A more elegant solution might be to set the window background to black, put down a rectangle in white that represents the actual game area and then apply your lines only to that rectangle:
from graphics import *
win = GraphWin("Gameboard", 500, 500)
win.setCoords(0, 0, 10, 10)
def drawBoard(window):
window.setBackground("black")
rectangle = Rectangle(Point(1, 1), Point(9, 9))
rectangle.setFill("white")
rectangle.draw(window)
for i in range(1, 10):
Line(Point(1, i), Point(9, i)).draw(window)
for x in range(1, 10):
Line(Point(x, 1), Point(x, 9)).draw(window)
drawBoard(win)
win.getMouse()
win.close()
This gives you an 8 x 8 board without having draw individual border squares:
Upvotes: 1