-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdrawPlayers.py
More file actions
264 lines (230 loc) · 8.99 KB
/
drawPlayers.py
File metadata and controls
264 lines (230 loc) · 8.99 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
from functions import hover
import objects as obj
players = []
pawn_colors = []
cards = []
palette = obj.palette
point_worth = {
"pawn": 1,
"knight": 4,
"rook": 5,
"queen": 8,
"king": 10
}
images = {
"pawn": loadImage("pawn.png"),
"knight": loadImage("knight.png"),
"rook": loadImage("rook.png"),
"queen": loadImage("queen.png"),
"king": loadImage("king.png")
}
cardWidth = 1080 - 200
cardHeight = 150 - 60/4
cursorImg = ARROW
errorMsgCounter = 0
errorMsg = ""
openSans = loadFont("OpenSans-48.vlw")
openSansBold = loadFont("OpenSans-Bold-48.vlw")
def get_players(A):
print("ah")
global players, pawn_colors, cardHeight, cardWidth, alivePlayers
player_list = []
alivePlayers = len(A)
for i in range(len(A)):
player_list.append(Player(A[i][0],A[i][1]))
pawn_colors.append(A[i][1])
# playercard info
player_list[i].cardLocation = [120, 60 + (cardHeight+10)*i - 20, cardWidth, cardHeight, 5]
players = player_list
def getNames():
temp = []
for i in range(len(players)):
temp.append([players[i].name, players[i].player_color])
return temp
def getAlivePlayers(): # returns list of player objects that still have their king
return alivePlayers
def getPlayers():
sortedList = sorted(players, key=lambda x: x.points, reverse=True)
return sortedList
def get_points(target):
global players
target.points = 0
for player in players:
if target.player_color == player.player_color:
pass
else:
for pawn in player.pawns:
if pawn.pawn_color == target.player_color:
target.points += pawn.worth
def draw_player_info():
global cardHeight, cardWidth, cursorImg, errorMsgCounter, errorMsg, alivePlayers
#noTint()
Blok = loadImage('Blokje.png')
cursorImg = ARROW
textSize(26)
for idx,i in enumerate(players):
get_points(i)
fill(255)
if hover([mouseX,mouseY], i.cardLocation):
fill(248)
rect(i.cardLocation[0], i.cardLocation[1], i.cardLocation[2], i.cardLocation[3], 7)
noStroke()
strokeWeight(0)
fill(130)
textFont(openSansBold, 28)
text(i.name, i.cardLocation[0]+20, 80 + (cardHeight+10)*idx)
fill(50)
textFont(openSansBold, 20)
text('punten:', i.cardLocation[0]+20, 135 + (cardHeight+10)*idx)
textFont(openSans, 20)
text(i.points, i.cardLocation[0]+130, 135 + (cardHeight+10)*idx)
textFont(openSansBold, 20)
text('blokkades:', i.cardLocation[0]+20, 160 + (cardHeight+10)*idx)
Blokkades = i.points // 4
i.change_to_pawn_color(i.pawns[-1])
noStroke()
noTint()
if Blokkades >= 1:
image(Blok, 250, 140 + (cardHeight+10)*idx,20,20)
if Blokkades >= 2:
image(Blok, 270, 140 + (cardHeight+10)*idx,20,20)
if Blokkades >= 3:
image(Blok, 290, 140 + (cardHeight+10)*idx,20,20)
if Blokkades >= 4:
image(Blok, 310, 140 + (cardHeight+10)*idx,20,20)
if Blokkades >= 5:
image(Blok, 330, 140 + (cardHeight+10)*idx,20,20)
for idx,player in enumerate(players):
player.draw_pawns(idx)
if not mousePressed:
alivePlayers = []
for player in players:
if player.isAlive():
alivePlayers.append(player)
cursor(cursorImg)
# draw error message when there is one
if errorMsgCounter > 0:
textSize(24)
errorMsgCounter -= 1
fill(229, 56, 59, errorMsgCounter*10)
textAlign(CENTER)
text(errorMsg,540,30)
textAlign(LEFT)
class Player:
def __init__(self, name, player_color):
self.points = 0
self.name = name
self.player_color = player_color
self.pawns = self.setup_pawns()
self.cardLocation = []
self.isActive = False
cards.append(self)
def add_points(self, points):
self.points += points
def setup_pawns(self):
temp = []
temp += ([Pawn("pawn", self.player_color) for i in range(6)])
temp += ([Pawn("knight", self.player_color) for i in range(2)])
temp += ([Pawn("rook", self.player_color) for i in range(2)])
temp += ([Pawn("queen", self.player_color)])
temp += ([Pawn("king", self.player_color)])
return temp
def change_to_pawn_color(self, pawn):
alpha = 200
stroke(100)
strokeWeight(1)
if(pawn.pawn_color == "black"):
fill(palette['player_colors'][1], alpha)
elif(pawn.pawn_color == "white"):
fill(palette['player_colors'][0], alpha)
elif(pawn.pawn_color == "red"):
fill(palette['player_colors'][2], alpha)
elif(pawn.pawn_color == "blue"):
fill(palette['player_colors'][3], alpha)
if(pawn.owner_color == "black"):
tint(palette['player_colors'][1])
elif(pawn.owner_color == "white"):
tint(palette['player_colors'][0])
elif(pawn.owner_color == "red"):
tint(palette['player_colors'][2])
else:
tint(palette['player_colors'][3])
def isAlive(self):
if self.pawns[-1].pawn_color == self.player_color:
return True
else:
return False
def draw_pawns(self,idx):
rectMode(CORNER)
imageMode(CORNER)
global pawn_colors, images, alreadyDragging, players, cursorImg, errorMsgCounter, errorMsg, alivePlayers
mouse = [mouseX,mouseY]
high = 0
for i in range(len(self.pawns)):
currentPawn = self.pawns[i]
if i % 4 == 0 and i != 0:
high += 1
self.change_to_pawn_color(currentPawn)
noStroke()
strokeWeight(0)
currentPawn.location = [1080 - 45*4 - 45*(i-(high*4)), 50+40*high + idx*145, 35, 35]
if currentPawn.drag:
cursorImg = MOVE
# change color to card below
for player in players:
if hover(mouse, player.cardLocation) and currentPawn.drag:
currentPawn.pawn_color = player.player_color
break
if not mousePressed:
self.clicked = False
currentPawn.drag = False
alreadyDragging = False
if hover(mouse, currentPawn.location) or currentPawn.drag:
cursorImg = MOVE
fill(20,0)
if alreadyDragging or currentPawn.pawn_color == currentPawn.owner_color:
self.isActive = True
if mousePressed and not alreadyDragging and mouseButton == LEFT:
alreadyDragging = True
currentPawn.drag = True
if currentPawn.drag:
currentPawn.location = [mouseX-28, mouseY-32, 35, 35]
else:
# reset color
cursorImg = HAND
if mousePressed and mouseButton == RIGHT:
currentPawn.pawn_color = currentPawn.owner_color
elif mousePressed and mouseButton == LEFT:
errorMsgCounter = 120
errorMsg = "Klik op rechtermuisknop om de kleur te wissen."
# hier moet een error msg komen als mouseButton == LEFT
# update color by clicking
'''
if mousePressed and (mouseButton == LEFT) and not self.clicked:
self.clicked = True
print(currentPawn.name, currentPawn.pawn_color, currentPawn.worth)
try:
currentPawn.pawn_color = pawn_colors[:len(players)][pawn_colors.index(currentPawn.pawn_color)+1]
except:
currentPawn.pawn_color = pawn_colors[0]
'''
rect(currentPawn.location[0], currentPawn.location[1], currentPawn.location[2], currentPawn.location[3], 15)
self.change_to_pawn_color(currentPawn)
if currentPawn.pawn_color != currentPawn.owner_color:
rect(currentPawn.location[0], currentPawn.location[1], currentPawn.location[2], currentPawn.location[3], 15)
image(currentPawn.img, currentPawn.location[0], currentPawn.location[1], currentPawn.location[2], currentPawn.location[3])
noStroke()
class Pawn:
def __init__(self,type,pawn_color):
self.drag = False
self.imagePointer = type + ".png"
self.img = loadImage(self.imagePointer)
self.location = []
self.clicked = False
self.worth = point_worth[type]
self.name = type
self.pawn_color = pawn_color
self.owner_color = pawn_color
def add_to_player(self, player):
player.add_points(self.worth)
print(str(self.worth), player.name)