/
main.py
411 lines (351 loc) · 14.2 KB
/
main.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
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
#Main HS game
#To Lindsay
from pygame import *
from Board import *
from Damage import *
from DrawBoard import *
from Turn import *
from card import *
from cards import *
from heroPower import *
from spawn import *
from Constants import *
from Messages import *
from Generator import *
from selectionScreen import *
from hover import *
from inputbox import *
#Colour Declerations
RED = (255, 0, 0)
GREEN = (0, 200, 0)
BLUE = (0, 0, 255)
BOARD = (205,182,139)
LINDSAY = (255, 7, 162)
#BOARD = LINDSAY
id = 0
# Turn tracker
turn = getTurn()
# Get foldername from Constants
foldername = getFoldername()
#Number of cards show at a time on card selection screen
DISPLAYNUM = 4
#filename to be hovered over
filename = foldername+"abusive_sergeant.png"
#Check to see if User wants to quit the application
def check_to_quit():
for evnt in event.get(): # checks all events that happen
keys = key.get_pressed()
keyz= key.get_pressed ()
if evnt.type == QUIT:
return False
return True
#Check if a Player has clicked on their hero power
def checkHeroPower(pos, turn):
if turn == 1:
if 19*widthInc < pos[0] < 21*widthInc and 2*heightInc < pos[1] < 4*heightInc:
player1.doHeroPower()
else:
if 19*widthInc < pos[0] < 21*widthInc and 12*heightInc < pos[1] < 14*heightInc:
player2.doHeroPower()
# Highlight the current space hovered over and the last space clicked
def highlight(pos, selcted, square):
screen = getScreen()
for i in range (0,10):
if pos[1] < heightInc*2 and pos[0]> i*tenth and pos[0] < (i+1)*tenth:
xcor = pos[0] % tenth
draw.rect(screen, GREEN, (tenth*i,0, tenth, heightInc*2), 10)
if pos[1] > heightInc*14 and pos[0]> i*tenth and pos[0] < (i+1)*tenth:
xcor = pos[0] % tenth
draw.rect(screen, GREEN, (tenth*i,heightInc*14, tenth, heightInc*2), 10)
for i in range (0,7):
if pos[1] > heightInc*4 and pos[1] < heightInc*8 and pos[0]> i*widthInc*4 and pos[0] < (i+1)*widthInc*4:
draw.rect(screen, GREEN, (widthInc*4*i,heightInc*4, widthInc*4, heightInc*4), 10)
if pos[1] < heightInc*12 and pos[1] > heightInc*8 and pos[0]> i*widthInc*4 and pos[0] < (i+1)*widthInc*4:
draw.rect(screen, GREEN, (widthInc*4*i,heightInc*8, widthInc*4, heightInc*4), 10)
for i in range (2):
if widthInc*11 < pos[0] < widthInc*17 and heightInc*2 + heightInc*10*i < pos[1] < heightInc*4 + heightInc*10*i:
draw.rect(screen, GREEN, (widthInc*11,heightInc*2 + heightInc*10*i, widthInc*6, heightInc*2), 10)
if widthInc*19 < pos[0] < widthInc*21 and heightInc*2 + heightInc*10*i < pos[1] < heightInc*4 + heightInc*10*i:
draw.rect(screen, GREEN, (widthInc*19,heightInc*2 + heightInc*10*i, widthInc*2, heightInc*2), 10)
if selected != None:
square0 = abs(1-square[0])
draw.rect(screen, (0,255,255), (square[1], square0, square[2], square[3]), 10)
def canAttack(target, player):
if player.getTaunts():
for targ in player.getTaunts():
if targ == target:
return True
return False
return True
# A completely massive function which handles how selections work
def select(mouseObj, spots, current, state, hands):
global filename
print "Current Type"
print current
if current == None:
mx, my = mouseObj.pos
for i in range (0,2):
for j in range(0,7):
if widthInc*4*j < mx < widthInc*4*(j+1) and heightInc*4 + heightInc*4*(i) < my < heightInc*4 + heightInc*4*(i+1):
square = [i,j]
reversei = abs(1-i)
if spots[reversei][j].getOccupied():
if spots[reversei][j].getCard().getTired() == False:
filename = spots[reversei][j].getCard().getFilename()
return spots[reversei][j], [i*widthInc*4 + widthInc*4, j*heightInc*4, widthInc*4, heightInc*4], "B"
for j in range(0,10):
if tenth*j < mx < tenth*(j+1) and 0 < my < heightInc*2 :
square = [i,j]
if turn == 1:
filename = hands[0].getCards()[j].getFilename()
return [hands[0].getCards()[j], [0,j]], [0, j*tenth, tenth, heightInc*2], "H"
for j in range(0,10):
if tenth*j < mx < tenth*(j+1) and heightInc*14 < my < heightInc*16 :
square = [i,j]
if turn == 0:
newfilename = hands[1].getCards()[j].getFilename()
filename = newfilename
return [hands[1].getCards()[j], [1,j]], [widthInc*14, j*tenth, tenth, heightInc*2], "H"
murn = abs(1 - turn)
if widthInc*11 < mx < widthInc*17 and heightInc*2 + heightInc*10*murn < my < heightInc*4 + heightInc*10*murn and board.getCurrentPlayer().getPower() > 0 and board.getCurrentPlayer().isReady():
return 1, [widthInc*2 + widthInc*10*murn,heightInc*11, widthInc*6, heightInc*2], "C"
elif widthInc*11 < mx < widthInc*17 and heightInc*2 + heightInc*10*murn < my < heightInc*4 + heightInc*10*murn and board.getCurrentPlayer().getPower() > 0:
return None, None, None
else:
mx, my = mouseObj.pos
for i in range (0,2):
for j in range(0,7):
if widthInc*4*j < mx < widthInc*4*(j+1) and heightInc*4 + heightInc*4*(i) < my < heightInc*4 + heightInc*4*(i+1):
i = abs(1-i)
if state == "B":
if i != turn:
if spots[i][j].getOccupied():
if canAttack(spots[i][j].getCard(), getBoard().getEnemyPlayer()):
fight(spots[i][j], current, board)
current = None
state = None
else:
tauntMessage = TauntMessage(screen)
tauntMessage.displayMessage()
return None, None, None
else:
NVT = NonValidTarget(screen)
NVT.displayMessage()
return None, None, None
else:
WT = WrongTurn(screen)
WT.displayMessage()
return None, None, None
#Play Card
elif state == "H":
if spots[i][j].getOccupied() == False:
if i == getTurn():
return playCard(board.getCurrentPlayer(), board.getCurrentPlayer().getCurMana(), current[0], spots[i][j],
hands[current[1][0]], current[1][1])
else:
return None, None, None
else:
prevCard = spots[i][j].getCard()
canRight = checkRight([i,j], spots)
canLeft = checkLeft([i,j], spots)
if canLeft or canRight:
playCard(board.getCurrentPlayer(), board.getCurrentPlayer().getCurMana(), current[0], spots[i][j],
hands[current[1][0]], current[1][1])
if mx > widthInc*4*j + widthInc*2 and canRight:
shiftRight([i,j], spots, prevCard)
elif canLeft:
shiftLeft([i,j], spots, prevCard)
elif canRight:
shiftRight([i,j], spots, prevCard)
return None, None, None
#Hero attack
elif state == "C":
attacker = board.getCurrentPlayer()
if spots[i][j].getOccupied():
if canAttack(spots[i][j].getCard(), getBoard().getEnemyPlayer()):
faceGo(attacker, spots[i][j], board)
attacker.setReady(False)
if attacker.isArmed():
weapon = attacker.getWeapon()
if weapon.attackCheck():
attacker.unarmed()
attacker.setWeapon(None)
else:
nvt = NonValidTarget(screen)
nvt.displayMessage()
return None, None, None
if state == "B":
if widthInc*11 < mx < heightInc*17 and heightInc*2 < my <heightInc*4 and not (current.getCard().getTired()):
if canAttack(player1, getBoard().getEnemyPlayer()):
goFace(current.getCard(), player1)
return None, None, None
else:
tauntMessage = TauntMessage(screen)
tauntMessage.displayMessage()
return None, None, None
elif widthInc*11 < mx < heightInc*17 and heightInc*12 < my <heightInc*14 and not (current.getCard().getTired()):
if canAttack(player1, getBoard().getEnemyPlayer()):
goFace(current.getCard(), player2)
return None, None, None
else:
tauntMessage = TauntMessage(screen)
tauntMessage.displayMessage()
elif state == "C":
if widthInc*11 < mx < heightInc*17 and heightInc*2 < my <heightInc*4 and player2.isReady():
if canAttack(player2, player1):
faceToFace(player1, player2)
attacker = player2
if attacker.isArmed():
weapon = attacker.getWeapon()
if weapon.attackCheck():
attacker.unarmed()
attacker.setWeapon(None)
else:
tauntMessage = TauntMessage(screen)
tauntMessage.displayMessage()
return None, None, None
elif widthInc*11 < mx < heightInc*17 and heightInc*12 < my <heightInc*14 and player1.isReady():
if canAttack(player1, player2):
faceToFace(player2, player1)
attacker = player1
if attacker.isArmed():
weapon = attacker.getWeapon()
if weapon.attackCheck():
attacker.unarmed()
attacker.setWeapon(None)
else:
tauntMessage = TauntMessage(screen)
tauntMessage.displayMessage()
return None, None, None
return None, None, None
return current, [i,j, widthInc*4, heightInc*5], state
#Play a card onto the board
def playCard(player, mana, card, spot, hand1, hand2):
board = getBoard()
global id
if card.getCost() <= player.getCurMana() and card.getType() == "Creature":
card.setID(id)
id +=1
player.changeCurMana(-card.getCost())
spot.setCard(card)
spot.setOccupied(True)
hand1.setNull(hand2)
if card.hasBattleCry():
print "WHY NOT"
card.battleCry()
board.playedCreature(card)
if card.hasEffect():
card.doEffect()
if card.hasTaunt():
player.addTaunt(card)
display.flip()
return None, None, None
def spellCheck(spell, square, lastpos, stat):
if spell:
if type(spell) is list:
spell = spell[0]
if spell.getType() == "Spell":
test = True
while test:
drawGrid(filename, lastpos, stat)
highlight(mouse.get_pos(), None, square)
showBoard(spots)
showHand(hands, turn)
for evnt in event.get():
if evnt.type == MOUSEBUTTONDOWN:
spell.doSpell(evnt.pos)
return True
display.flip()
#Initialize the board and Pygame
init()
size =(1400,700)
screen= display.set_mode(size)
setScreen(screen)
width = screen.get_width()
height = screen.get_height()
widthInc = width/32.0
heightInc = height/16.0
tenth = width/11.42
convx = width / 1600.0
convy = height/ 800.0
nameFont = font.Font(None, 30)
handFont = font.Font(None, 15)
selected = None
square = None
display.flip()
breaker = True
board = Board()
setBoard(board)
spots = board.getSpots()
hands = board.getHands()
player1 = board.getPlayer1()
player2 = board.getPlayer2()
twice = 0
state = None
x = 0
selecting = True
gen = Generator(screen, board, player1)
cardList = gen.getCards()
cardList = [CH_YETI(), FL_JUG(), RIV_CROC(), MUR_RAID(), ABU_SRG(), LNC_CAR(), IRN_OWL(), ELF_ARC(),
GRM_MUR(), NOV_ENG(), LOT_HRD(), GLD_FOT()]
deck1Cards = []
deck2Cards = []
start = 0
choosing = True
#Initialize Player1's Deck
player1, deck1Cards, save1, name1 = selectScreen(player1, screen, board, 1)
#Initialize Player2's Deck
player2, deck2Cards, save2, name2 = selectScreen(player2, screen, board, 2)
selecting = True
if save1:
Deck1 = open('deck1.txt', 'w')
Deck1.write(name1+"\n")
Deck1.write(player1.getRole()+"\n")
for i in deck1Cards:
Deck1.write(i.getName()+"\n")
Deck1.close()
if save2:
Deck2 = open('deck2.txt', 'w')
Deck2.write(name2+"\n")
Deck2.write(player2.getRole()+"\n")
for i in deck2Cards:
Deck2.write(i.getName()+"\n")
Deck2.close()
deck1, deck2 = board.simpleDecks(deck1Cards,deck2Cards, player1, player2)
hands[0].initialize(deck1)
hands[1].initialize(deck2)
lastpos = [1400, 0]
stat = 0
curpos = [1200, 0]
#GamePlay Loop
while (breaker):
turn = getTurn()
breaker = check_to_quit()
#Draw the board
drawGrid(filename, lastpos, stat)
#Highlight current mouse POS
highlight(mouse.get_pos(), selected, square)
# Show minions on board
showBoard(spots)
# Show cards in hand
showHand(hands, turn)
time.wait(10)
for newEvent in event.get():
if newEvent.type == MOUSEBUTTONDOWN:
selected, square, state = select(newEvent, spots, selected, state, hands)
spellCheck(selected, square, lastpos, stat)
print "SELECTED"
print selected
checkHeroPower(newEvent.pos, turn)
turn = endTurn(newEvent.pos, turn, board, convx, convy)
filename, stat = hoverCardMain(filename, newEvent.pos, spots, hands)
elif newEvent.type == MOUSEMOTION:
lastpos = newEvent.pos
filename, stat = hoverCardMain(filename, newEvent.pos, spots, hands)
curpos = newEvent.pos
else:
if newEvent.type == QUIT:
breaker = False
hoveredCard(screen, curpos, stat, filename)
display.flip()
quit()