-
Notifications
You must be signed in to change notification settings - Fork 0
/
Piece.py
138 lines (115 loc) · 4.32 KB
/
Piece.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from Constants import *
class Piece:
def __init__(self, side, piece, x, y, imgs):
self.x = x
self.y = y
self.side = side
self.selected = False
self.origPos = (x, y)
self.piece = piece
self.origPiece = piece
self.dropping = False
self.P,self.L,self.N,self.S,self.G,self.K,self.R,self.B,self.PP, \
self.PL,self.PN,self.PS,self.PR,self.PB, \
self.RP,self.RL,self.RN,self.RS,self.RG,self.RK,self.RR,self.RB,self.RPP, \
self.RPL,self.RPN,self.RPS,self.RPR,self.RPB = imgs
def setPos(self, x, y):
self.x = x
self.y = y
def select(self):
self.origPos = (self.x, self.y)
self.selected = True
def deselect(self):
self.selected = False
self.x = self.origPos[0]
self.y = self.origPos[1]
def showImage(self, img):
if not self.selected:
image(img,self.x*CELLDIM+MARGIN+CELLMARGIN,self.y*CELLDIM+MARGIN+CELLMARGIN,\
CELLDIM-2*CELLMARGIN,CELLDIM-2*CELLMARGIN)
else:
image(img, self.x-(CELLDIM-2*CELLMARGIN)//2, self.y-(CELLDIM-2*CELLMARGIN)//2,\
CELLDIM-2*CELLMARGIN, CELLDIM-2*CELLMARGIN)
def showPromotionImage(self, x, y):
marg = CELLMARGIN // 2
image(self.getPic(),x+marg,y+marg,\
OPTIONDIM-2*marg,OPTIONDIM-2*marg)
def getPic(self):
if self.side == "bot":
if self.piece == "lance":
return self.L
elif self.piece == "knight":
return self.N
elif self.piece == "silver":
return self.S
elif self.piece == "gold":
return self.G
elif self.piece == "king":
return self.K
elif self.piece == "pawn":
return self.P
elif self.piece == "bishop":
return self.B
elif self.piece == "rook":
return self.R
elif self.piece == "tokin":
return self.PP
elif self.piece == "horse":
return self.PB
elif self.piece == "dragon":
return self.PR
elif self.piece == "lancePro":
return self.PL
elif self.piece == "knightPro":
return self.PN
elif self.piece == "silverPro":
return self.PS
else:
if self.piece == "lance":
return self.RL
elif self.piece == "knight":
return self.RN
elif self.piece == "silver":
return self.RS
elif self.piece == "gold":
return self.RG
elif self.piece == "king":
return self.RK
elif self.piece == "pawn":
return self.RP
elif self.piece == "bishop":
return self.RB
elif self.piece == "rook":
return self.RR
elif self.piece == "tokin":
return self.RPP
elif self.piece == "horse":
return self.RPB
elif self.piece == "dragon":
return self.RPR
elif self.piece == "lancePro":
return self.RPL
elif self.piece == "knightPro":
return self.RPN
elif self.piece == "silverPro":
return self.RPS
def show(self):
self.showImage(self.getPic())
def promote(self):
if self.piece == "pawn":
self.piece = "tokin"
elif self.piece == "lance":
self.piece = "lancePro"
elif self.piece == "knight":
self.piece = "knightPro"
elif self.piece == "silver":
self.piece = "silverPro"
elif self.piece == "bishop":
self.piece = "horse"
elif self.piece == "rook":
self.piece = "dragon"
def dePromote(self):
self.piece = self.origPiece
def showAtPos(self, sc=1):
pic = self.getPic()
image(pic, self.x, self.y, (CELLDIM-2*CELLMARGIN)*sc, (CELLDIM-2*CELLMARGIN)*sc)