-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_.py
139 lines (109 loc) · 4.52 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
import pygame
import random
import time
import config
from utils import *
from player import Player
from computer import Computer
from pygame.locals import (
K_ESCAPE,
KEYDOWN,
QUIT,
)
clock = pygame.time.Clock()
screen = pygame.display.set_mode((config.SCREEN_WIDTH, config.SCREEN_HEIGHT))
pygame.display.set_caption(config.WINDOW_CAPTION)
canvas = pygame.image.load('assets/canvas.png')
deckSprites = pygame.sprite.Group()
cards = createDeck()
random.shuffle(cards)
playerCards = sortCards(cards[0:13])
for card in playerCards:
deckSprites.add(card)
player0 = Player(cards=playerCards, id = 0, sprites=deckSprites)
player1 = Computer(cards=sortCards(cards[13:26]), id = 1)
player2 = Computer(cards=sortCards(cards[26:39]), id = 2)
player3 = Computer(cards=sortCards(cards[39:52]), id = 3)
players = [player0, player1, player2, player3]
for player in players:
if player.hasAceOfSpades:
firstPlayer = player.id
break
def main():
index = firstPlayer
prevIndex = firstPlayer
highestCard = firstPlayer
cardsInPlay = []
playersInPlay = []
ongoingSuit = None
isFirstTurnInGame = True
totalRounds = 0
pygame.init()
clock.tick(config.FPS)
flag = False
while True:
screen.blit(canvas,(0,0))
### TAKE INPUTS
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
quit()
### PERFROM COMPUTATIONS
print(config.IS_ANYTHING_MOVING)
if flag:
if not config.IS_ANYTHING_MOVING: # only do this stuff when nothing is moving
if len(players[index].cards) != 0: # if the player still has cards
players[index].isTurn = True
players[index].getCard(ongoingSuit=ongoingSuit, isFirstTurnInGame=isFirstTurnInGame)
players[index].cardThrownThisTurn.target = config.TARGET_RECT[index]
if len(cardsInPlay) == 0: # if this is the first turn in current round
totalRounds += 1
ongoingSuit = players[index].cardThrownThisTurn.suit
highestCard = index
cardsInPlay.append(players[index].cardThrownThisTurn)
playersInPlay.append(index)
assert not players[index].isTurn # make sure current player has completed turn
if len(cardsInPlay) > 1:
if players[highestCard].cardThrownThisTurn.rank > players[index].cardThrownThisTurn.rank:
highestCard = highestCard
else:
highestCard = index
thula = isThula([
players[index].cardThrownThisTurn,
players[prevIndex].cardThrownThisTurn
])
prevIndex = index
index = index + 1 if index != 3 else 0 # update index for next player
if thula:
for idx, card in enumerate(cardsInPlay):
if card.isStationary:
card.target = config.DECK_RECT[highestCard]
players[playersInPlay[idx]].cards.remove(card)
players[highestCard].insert(cardsInPlay)
cardsInPlay = []
playersInPlay = []
index = highestCard
if not thula and len(cardsInPlay) == 4:
for idx, card in enumerate(cardsInPlay):
if card.isStationary:
card.target = config.DECK_RECT[highestCard]
players[playersInPlay[idx]].cards.remove(card)
cardsInPlay = []
playersInPlay = []
index = highestCard
### RENDER STUFF
renderCards(
screen=screen,
decks=[player0.cards, player1.cards, player2.cards, player3.cards], # deck order is important
ongoingSuit = ongoingSuit,
isFirstTurnInGame=isFirstTurnInGame,
showEligible=False
)
flag = True
isFirstTurnInGame = False
pygame.display.flip()
print(config.IS_ANYTHING_MOVING)
if __name__ == '__main__':
main()