-
Notifications
You must be signed in to change notification settings - Fork 0
/
promotion.py
124 lines (97 loc) · 4.19 KB
/
promotion.py
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from PyQt5 import QtWidgets, QtGui, QtCore
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from constants import *
import sys
from board import Piece
width, height = 100, 100
class promotion_menu:
# Cancel Text
def __init__(self, piece: Piece) -> None:
self.piece = piece
# Clicked Functions
def exit_clicked(self, menu: QMainWindow) -> None:
self.close(menu)
if self.piece.type == "pawn":
self.promote = False
def close(self, menu: QMainWindow) -> None:
menu.close()
def queen_clicked(self, menu: QMainWindow) -> None:
if self.piece.color == "white":
self.piece.image = white_queen
elif self.piece.color == "black":
self.piece.image = black_queen
self.piece.promotion_letter = "q"
self.piece.type = "queen"
self.promote = True
self.close(menu)
def rook_clicked(self, menu: QMainWindow) -> None:
if self.piece.color == "white":
self.piece.image = white_rook
elif self.piece.color == "black":
self.piece.image = black_rook
self.piece.promotion_letter = "r"
self.piece.type = "rook"
self.promote = True
self.close(menu)
def bishop_clicked(self, menu: QMainWindow) -> None:
if self.piece.color == "white":
self.piece.image = white_bishop
elif self.piece.color == "black":
self.piece.image = black_bishop
self.piece.promotion_letter = "b"
self.piece.type = "bishop"
self.promote = True
self.close(menu)
def knight_clicked(self, menu: QMainWindow) -> None:
if self.piece.color == "white":
self.piece.image = white_knight
elif self.piece.color == "black":
self.piece.image = black_knight
self.piece.promotion_letter = "n"
self.piece.type = "knight"
self.promote = True
self.close(menu)
def draw_menu(self) -> None:
# A list of the self.pieces the user can promote their pawn to
wn = QApplication(sys.argv)
menu = QMainWindow()
menu.setWindowTitle("Your Pawn Promotes to a ...")
menu.setFixedSize(4 * width, height) # Makes it not resizable
# Drawing the Buttons
# Promotion Buttons
# Queen Button
queen_button = QPushButton(menu)
queen_button.setStyleSheet("background: rgb(127.5, 127.5, 127.5)")
queen_button.setIcon(QIcon(self.piece.promotion_pieces_directories[0]))
queen_button.setIconSize(QSize(width, height))
queen_button.setGeometry(0, 0, width, height)
# Knight Button
knight_button = QPushButton(menu)
knight_button.setStyleSheet("background: rgb(127.5, 255, 127.5)")
knight_button.setIcon(QIcon(self.piece.promotion_pieces_directories[3]))
knight_button.setIconSize(QSize(width, height))
knight_button.setGeometry(width, 0, width, height)
# Rook Button
rook_button = QPushButton(menu)
rook_button.setStyleSheet("background: rgb(0, 255, 127.5)")
rook_button.setIcon(QIcon(self.piece.promotion_pieces_directories[1]))
rook_button.setIconSize(QSize(width, height))
rook_button.setGeometry(2 * width, 0, width, height)
# Bishop Button
bishop_button = QPushButton(menu)
bishop_button.setStyleSheet("background: rgb(0, 176, 169)")
bishop_button.setIcon(QIcon(self.piece.promotion_pieces_directories[2]))
bishop_button.setIconSize(QSize(width, height))
bishop_button.setGeometry(3 * width, 0, width, height)
# Effect when a button is clicked
queen_button.clicked.connect(lambda: self.queen_clicked(menu))
rook_button.clicked.connect(lambda: self.rook_clicked(menu))
bishop_button.clicked.connect(lambda: self.bishop_clicked(menu))
knight_button.clicked.connect(lambda: self.knight_clicked(menu))
# Close Button
wn.aboutToQuit.connect(lambda: self.exit_clicked(menu))
# Display Screen
menu.show()
wn.exec_()