-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
84 lines (65 loc) · 3.35 KB
/
main.py
File metadata and controls
84 lines (65 loc) · 3.35 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
83
84
from tkinter import Frame, Tk, Label
from Pieces.knight import Knight
from Pieces.piece import Piece
from Pieces.pawn import Pawn
from Pieces.king import King
from Pieces.rook import Rook
from GUI.custom_banner import CustomBanner
from GUI.custom_button import CustomButton
from GUI.chessboard import Chessboard
def fill_figures() -> list:
rooks = [Rook("♖", (1,1), [(1, 0), (-1, 0), (0, 1), (0, -1)], 5),
Rook("♖", (1,8), [(1, 0), (-1, 0), (0, 1), (0, -1)], 5),
Rook("♜", (8,1), [(1, 0), (-1, 0), (0, 1), (0, -1)], 5, "black"),
Rook("♜", (8,8), [(1, 0), (-1, 0), (0, 1), (0, -1)], 5, "black")
]
bishop = [Piece("♗", (1,3), [(1, -1), (1, 1), (-1,-1), (-1,1)], 3),
Piece("♗", (1,6), [(1, -1), (1, 1), (-1,-1), (-1,1)], 3),
Piece("♝", (8,3), [(1, -1), (1, 1), (-1,-1), (-1,1)], 3, "black"),
Piece("♝", (8,6), [(1, -1), (1, 1), (-1,-1), (-1,1)], 3, "black")
]
queen = [Piece("♕", (1,4), [(1, 0), (-1, 0), (0, 1), (0, -1), (1, -1), (1, 1), (-1,-1), (-1,1)], 9),
Piece("♛", (8,4), [(1, 0), (-1, 0), (0, 1), (0, -1), (1, -1), (1, 1), (-1,-1), (-1,1)], 9, "black")
]
knight = [Knight("♘", (1,2), [(2, 1),(2, -1),(-2, 1),(-2, -1),(1, 2),(1, -2), (-1, 2),(-1, -2)], 3),
Knight("♘", (1,7), [(2, 1),(2, -1),(-2, 1),(-2, -1),(1, 2),(1, -2), (-1, 2),(-1, -2)], 3),
Knight("♞", (8,7), [(2, 1),(2, -1),(-2, 1),(-2, -1),(1, 2),(1, -2), (-1, 2),(-1, -2)], 3, "black"),
Knight("♞", (8,2), [(2, 1),(2, -1),(-2, 1),(-2, -1),(1, 2),(1, -2), (-1, 2),(-1, -2)], 3, "black")
]
king = [King("♔", (1,5), [(1, 0), (-1, 0), (0, 1), (0, -1),(1, 1), (1, -1), (-1, 1), (-1, -1)], 100),
King("♚", (8,5), [(1, 0), (-1, 0), (0, 1), (0, -1),(1, 1), (1, -1), (-1, 1), (-1, -1)], 100, "black")]
pawns = []
for i in range(8):
pawns.append(Pawn("♙", (2, i+1), [(1,0)], 1))
pawns.append(Pawn("♟", (7, i+1), [(-1,0)], 1, "black"))
pieces: Piece = [rooks, bishop, queen, knight, king, pawns]
return pieces
def create_label(window, row, col, text="", bg_color="#183446", fg_color="black") -> None:
label = Label(window, text=text, bg=bg_color, fg=fg_color, font=('Helvetica 20 bold'))
label.grid(row=row, column=col, sticky="nsew")
def create_window(cc) -> Tk:
window = Tk()
window.title("PyChess")
window.resizable(False,False)
banner_frame = CustomBanner(window, "#022F40")
board_frame = Frame(window, bg="#183446")
board_frame.pack(fill="x")
for i in range(9):
board_frame.grid_rowconfigure(i, weight=1, uniform="equal")
board_frame.grid_columnconfigure(i, weight=1, uniform="equal")
for i in range(9):
for j in range(9):
if i == 8 and j < 8: # Bottom row (numbers)
create_label(board_frame, i, j + 1, text=f"{j + 1}") #chr(65 + j)
elif j == 0 and i < 8: # Left column (numbers)
create_label(board_frame, i, j, text=f"{8 - i}")
for position, piece in Chessboard.chessboard.items():
CustomButton(piece, cc, banner_frame, board_frame, position)
return window
pieces: Piece = fill_figures()
cc = Chessboard(pieces)
window = create_window(cc)
print(cc)
for piece in pieces[5]:
piece.window = window
window.mainloop()