def play_pli(self, players, pli_number): #•fonctionne """ prends en entrée le tableau ORDONNEE des players de ce pli et le renvoi réordonné """ #la meilleure card est le 1er joueur pour l'ini choosen_color = players[0].Hand.play(self.screen, players[0].number, players[0].random, self.pli, hand=players[0].Hand) for j in players[1:]: allowed_hand = self.allowed_cards(choosen_color, j) j.Hand.play(self.screen, j.number, j.random, self.pli, hand=allowed_hand) if not self.hidden: wait_or_pass(4) """ choosen_color=players[0].Hand.play_card( self.pli, players[0].Hand.choose_card(random=players[0].random)) for j in players[1:]: if not self.hidden :#GRAPHIC self.pli.display(self.screen,"board") allowed_hand=self.allowed_cards( choosen_color, j) choosen_card=allowed_hand.choose_card(random=j.random) # trois lignes a verifier j.Hand.play_card( self.pli, choosen_card) if not self.hidden :# GRAPHIC self.pli.display(self.screen,"board") """ winner = self.pli.winner() if not self.hidden: #GRAPHIC draw_text( self.screen, str("{} a gagné avec le {} de {}".format( players[winner].name, self.pli.cards[winner].number, self.pli.cards[winner].color)), gconst.area["points"]) new_order = [ players[winner], players[(winner + 1) % 4], players[(winner + 2) % 4], players[(winner + 3) % 4] ] players[winner].plis += 1 self.teams[players[winner].team].pli += self.pli #reinitialise le pli assert (self.pli.rest["cards"] == 0) #compter 10 de der if pli_number == 8: self.teams[players[winner].team].pli.points += 10 return new_order
def choose_announce(self, screen, value_or_color): assert ((value_or_color == "color") or (value_or_color == "value")) confirmation_zone = None while True: event = pygame.event.poll() if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: #escape break for announce in gconst.area["announce"][value_or_color]: if gconst.get_mouse( gconst.area["announce"][value_or_color][announce]): if event.type == pygame.MOUSEBUTTONDOWN: if confirmation_zone == gconst.area["announce"][ value_or_color][announce]: #second click draw_text(screen, announce, gconst.area["announce"][value_or_color] [announce], background_color=gconst.RED) pygame.display.flip() return announce else: if confirmation_zone != None: # already click elsewhere draw_text(screen, confirmed_announce, confirmation_zone) draw_text(screen, announce, gconst.area["announce"][value_or_color] [announce], background_color=gconst.YELLOW) pygame.display.flip() confirmation_zone = gconst.area["announce"][ value_or_color][ announce] #click once to highligth, click twice to confirm confirmed_announce = announce
def choose_atout(screen): screen.fill(gconst.PURPLE,gconst.area["middle"]) for announce in gconst.area["announce"]["value"]: draw_text(screen,announce,gconst.area["announce"]["value"][announce]) for announce in gconst.area["announce"]["color"]: draw_text(screen,announce,gconst.area["announce"]["color"][announce]) color=choose_announce(screen,"color") value=choose_announce(screen,"value") screen.fill(gconst.GREEN,gconst.area["middle"]) draw_text(screen,value + " " + color,gconst.area["middle"])
def graphic_choose_atout(self, screen, annonce_actuelle): for announce in gconst.area["announce"]["value"]: draw_text(screen, announce, gconst.area["announce"]["value"][announce]) for announce in gconst.area["announce"]["color"]: draw_text(screen, announce, gconst.area["announce"]["color"][announce]) color = self.choose_announce(screen, "color") while True: bet = self.choose_announce(screen, "value") annonce_voulue = const.liste_annonce.index(bet) if annonce_voulue > annonce_actuelle: annonce_actuelle = annonce_voulue break draw_text(screen, "you must bet higher ! ", gconst.area["message"]) screen.fill(gconst.GREEN, gconst.area["middle"]) return (color, bet, annonce_actuelle)
def choose_atout( self, screen, background_color="GREEN" ): # pensez a display avant surcoinche empecher danooncer 170 180 tout atout sans atout """ select the atout and return true if someone didnt pass his turn """ players = self.shortkey() bet = 0 annonce_actuelle = -1 turn = 0 while turn != 4 and bet != 'generale' and not self.coinche: for player in players: if turn == 4 or bet == 'generale' or self.coinche: break else: #BOT if player.random: wanted_bet, betColor = self.bots[player.name].bet() if wanted_bet != None: annonce_voulue = const.liste_annonce.index( wanted_bet) if annonce_voulue > annonce_actuelle: bet = wanted_bet annonce_actuelle = annonce_voulue self.atout = betColor if self.bots[player.name].level == "advanced": #Keep in mind that he has announced in this color self.bots[player.name].announcetracker[ betColor] = True if not self.hidden: #GRAPHIC draw_text( screen, ' {} prend à {} {} !'.format( player.name, bet, self.atout), gconst.area["message"]) draw_text( screen, '{} : {} {}'.format( self.teams[player.team].name, bet, self.atout), gconst.area["points"]) wait_or_pass(2) self.coincher(screen, player, bet) #If our partner is not stupid he adapted his bet according to ours allyName = self.bots[player.name].ally #Our ally is a bot if allyName in self.bots: if self.bots[allyName].level == "advanced": self.bots[allyName].adaptBetStrength( PartnerBet=bet, BetColor=betColor) turn = 1 else: #bet too low turn += 1 else: #doesnt bet turn += 1 #print(player.name,turn,wanted_bet,betColor) # TODO : for test only remove this #PLAYER else: if not graphic_yesorno( screen, question="annoncer ?", question_surface=gconst.area["choice"] ["question"], yes_surface=gconst.area["choice"]["yes"], no_surface=gconst.area["choice"]["no"]): turn += 1 else: turn = 1 self.atout, bet, annonce_actuelle = self.graphic_choose_atout( screen, annonce_actuelle) if not self.hidden: #GRAPHIC draw_text(screen, '{} : {} {}'.format( self.teams[player.team].name, bet, self.atout), gconst.area["points"]) #WE ASSUME self.coincher(screen, player, bet) #If our partner is not stupid he adapted his bet according to ours allyName = self.teams[0].players[ 1].name # TODO: I assume here that we are the player 1 #Our ally is a bot if allyName in self.bots: if self.bots[allyName].level == "advanced": self.bots[allyName].adaptBetStrength( PartnerBet=bet, BetColor=self.atout) if (self.atout == None): return False if not self.hidden: #GRAPHIC for team in self.teams: if team.bet != None: draw_text( screen, "L'équipe '{}' a pris {} {} !!!".format( team.name, team.bet, self.atout), gconst.area["message"]) screen.fill(gconst.GREEN, gconst.area["middle"]) return True
def coincher(self, screen, player, bet): """ make a turn of coince take as argument the player who just bet This method fixes the bet """ self.teams[ player. team].bet = bet #fixe la bet de lteam attention bet est un char self.teams[(player.team + 1) % 2].bet = None if bet == "generale": player.generale = True for coincheur in self.teams[(player.team + 1) % 2].players: if not self.coinche: #BOT if coincheur.random: #too stupid to coinche if self.bots[coincheur.name].level == "beginner": self.coinche = False elif self.bots[coincheur.name].level == "advanced": self.coinche = self.bots[coincheur.name].coinche( bet, self.atout) #PLAYER else: self.coinche = graphic_yesorno( screen, question="coincher ?", question_surface=gconst.area["choice"]["question"], yes_surface=gconst.area["choice"]["yes"], no_surface=gconst.area["choice"]["no"]) if self.coinche: if not self.hidden: #GRAPHIC draw_text( screen, ' {} coinche sur {} {} !'.format( coincheur.name, bet, self.atout), gconst.area["message"]) wait_or_pass(2) for surcoincheur in self.teams[player.team].players: if not self.surcoinche: #BOT if surcoincheur.random: self.surcoinche = False # TODO : surCOINCHE #self.surcoinche=generic.decision(random=surcoincheur.random, question='surcoincher sur {} {} ?'.format(bet,self.atout), ouverte=False) #PLAYER else: self.surcoinche = graphic_yesorno( screen, question="surcoincher ?", question_surface=gconst.area["choice"] ["question"], yes_surface=gconst.area["choice"]["yes"], no_surface=gconst.area["choice"]["no"]) if self.surcoinche: if not self.hidden: #GRAPHIC draw_text( screen, ' {} surcoinche sur {} {} !'.format( surcoincheur.name, bet, self.atout), gconst.area["message"]) wait_or_pass(2)
def test(): cartes=[] i=0 """ for numero in const.liste_numero : cartes.append(GraphicCard(numero,"carreau", (gconst.position["J1"][i][0],gconst.screen_size[1]-gconst.card_size[1]) )) i+=1 """ pygame.init() screen=pygame.display.set_mode(gconst.screen_size) screen.fill(gconst.GREEN) while True: event = pygame.event.poll() if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: #escape break if event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT: #test screen.fill(gconst.YELLOW,(100,100,100,100)) if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE: #draw_rect(screen,gconst.position["J1"][1][0] ,gconst.position["J1"][1][1]) screen.fill(gconst.BLUE,(gconst.card_size[0],gconst.screen_size[1]-gconst.card_size[1],110,110)) if event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN: #draw_rect(screen,gconst.position["J1"][1][0] ,gconst.position["J1"][1][1]) screen.fill(gconst.BLUE,gconst.grid[31][17]) if event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT : draw_rect(screen,gconst.card_size,(0,0)) """ if event.type == pygame.KEYDOWN and event.key == pygame.K_UP : afficher_cartes(screen, cartes) if pygame.mouse.get_pos()[1]<(gconst.area["cards"]["J1"][1]): for carte in cartes: if pygame.mouse.get_pos()[0]>(carte.position[0]) and pygame.mouse.get_pos()[0]<(carte.position[0]+gconst.card_size[0]): if event.type == pygame.MOUSEBUTTONDOWN : carte.jouer(screen) delete=cartes.index(carte) cartes=cartes[:delete]+cartes[delete+1:] """ if event.type == pygame.KEYDOWN and event.key == pygame.K_1 : screen.fill(gconst.BLUE,gconst.area["j1"]) if event.type == pygame.KEYDOWN and event.key == pygame.K_2 : screen.fill(gconst.BLUE,gconst.area["j2"]) if event.type == pygame.KEYDOWN and event.key == pygame.K_3 : screen.fill(gconst.BLUE,gconst.area["j3"]) if event.type == pygame.KEYDOWN and event.key == pygame.K_4 : screen.fill(gconst.BLUE,gconst.area["j4"]) if event.type == pygame.KEYDOWN and event.key == pygame.K_5 : screen.fill(gconst.BLUE,gconst.area["middle"]) if event.type == pygame.KEYDOWN and event.key == pygame.K_6 : screen.fill(gconst.BLUE,gconst.area["points"]) if event.type == pygame.KEYDOWN and event.key == pygame.K_7 : wait_or_pass(1) if event.type == pygame.KEYDOWN and event.key == pygame.K_9 : screen.fill(gconst.GREEN) if event.type == pygame.KEYDOWN and event.key == pygame.K_KP7 : screen.fill(gconst.YELLOW,gconst.area["cards"]["j1"][7]) if event.type == pygame.KEYDOWN and event.key == pygame.K_KP0 : screen.fill(gconst.YELLOW,gconst.area["cards"]["j1"][0]) if event.type == pygame.KEYDOWN and event.key == pygame.K_KP9 : choose_atout(screen) if event.type == pygame.KEYDOWN and event.key == pygame.K_KP4 : result=graphic_yesorno(screen,question="surcoincher ?",question_surface=gconst.area["choice"]["question"], yes_surface=gconst.area["choice"]["yes"],no_surface=gconst.area["choice"]["no"]) pygame.time.wait(1000) screen.fill(gconst.GREEN,gconst.area["middle"]) draw_text(screen,str(result),gconst.area["middle"]) pygame.display.flip() pygame.quit()