-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.py
More file actions
82 lines (73 loc) · 3.46 KB
/
Copy pathBoard.py
File metadata and controls
82 lines (73 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from graphics import *
from Piece import *
import math
import os.path as path
class Board:
SQUARE_SIZE = 100
PIECE_IMAGES = "resources/pieces/"
IMAGE_EXTENSION = ".png"
def __init__(self):
self.spaces = [
[None, None, None, None, None, None, None, None],
[Pawn((0, 1), "black"), Pawn((1, 1), "black"), Pawn((2, 1), "black"), Pawn((3, 1), "black"), Pawn((4, 1), "black"), Pawn((5, 1), "black"), Pawn((6, 1), "black"), Pawn((7, 1), "black")],
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
]
def draw_board(self):
drawn_spaces = [
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
]
drawn_pieces = [
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None],
]
for row in range(len(self.spaces)):
for column in range(len(self.spaces[row])):
square = Rectangle(Point(column * self.SQUARE_SIZE, row * self.SQUARE_SIZE), Point(column * self.SQUARE_SIZE - self.SQUARE_SIZE, row * self.SQUARE_SIZE - self.SQUARE_SIZE))
if pow(-1, row + column) == 1:
square.setFill("#CDC8B1") # White squares
else:
square.setFill("#556B2F") # Black squares
drawn_spaces[row][column] = square
for row in range(len(self.spaces)):
for column in range(len(self.spaces[row])):
piece = self.spaces[row][column]
if piece is not None:
square_center = drawn_spaces[row][column].getCenter()
drawn_pieces[row][column] = Image(square_center, self.PIECE_IMAGES + str(piece) + self.IMAGE_EXTENSION)
return drawn_spaces, drawn_pieces
def main():
win = GraphWin("game", 1080, 1080)
# c = Circle(Point(self.SQUARE_SIZE, self.SQUARE_SIZE), 10)
# c.draw(win)
board = Board()
spaces, pieces = board.draw_board()
print(spaces)
print(pieces)
for row in range(len(spaces)):
for space in range(len(spaces[row])):
spaces[row][space].draw(win)
for row in range(len(pieces)):
for space in range(len(pieces[row])):
if pieces[row][space] is not None:
pieces[row][space].draw(win)
win.getMouse() # Pause to view result
win.close() # Close window when done
main()