def end_turn(): global tour print('Fin du tour') print('Tour ' + str(tour)) if tour % 2 == 0: rect_end_turn = pygame.Rect(10, 400, 1260, 100) text_tools.draw_text( 'Tour ' + str(tour + 1) + ' - C\'est au joueur 1 de jouer !', font_title, (255, 255, 255), screen, 250, 320) pygame.display.flip() joueur1.add_action_to_stock() joueur1.add_gold_to_stock() joueur1.add_mana_to_stock() elif tour % 2 == 1: rect_end_turn = pygame.Rect(10, 400, 1260, 100) text_tools.draw_text( 'Tour ' + str(tour + 1) + ' - C\'est au joueur 2 de jouer !', font_title, (255, 255, 255), screen, 250, 320) pygame.display.flip() joueur2.add_action_to_stock() joueur2.add_gold_to_stock() joueur2.add_mana_to_stock() tour += 1 time.sleep(2)
def main_menu(): click = False while True: screen.fill((192, 192, 192)) text_tools.draw_text('IPSSI Card Game', font_title, (0, 0, 0), screen, 50, 20) mx, my = pygame.mouse.get_pos() button_1 = pygame.Rect(50, 200, 300, 100) button_2 = pygame.Rect(50, 350, 300, 100) button_3 = pygame.Rect(50, 500, 300, 100) button_4 = pygame.Rect(50, 650, 300, 100) if button_1.collidepoint(mx, my): if click: play.game() if button_2.collidepoint(mx, my): if click: rules() if button_3.collidepoint(mx, my): if click: options() if button_4.collidepoint(mx, my): if click: exit() pygame.draw.rect(screen, (0, 0, 0), button_1) pygame.draw.rect(screen, (0, 0, 0), button_2) pygame.draw.rect(screen, (0, 0, 0), button_3) pygame.draw.rect(screen, (0, 0, 0), button_4) screen.blit(font_title.render('Jouer', True, (255, 255, 255)), (88, 225)) screen.blit(font_title.render('Règles', True, (255, 255, 255)), (88, 375)) screen.blit(font_title.render('Options', True, (255, 255, 255)), (88, 525)) screen.blit(font_title.render('Quitter', True, (255, 255, 255)), (88, 675)) text_tools.blit_text( screen, 'Cliquer sur le menu pour y accèder ou appuyer sur \'Echap\' pour revenir au menu précédent', (950, 455), font_text) click = False for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_ESCAPE: pygame.quit() sys.exit() if event.type == MOUSEBUTTONDOWN: if event.button == 1: click = True pygame.display.update()
def add_buttons(screen, button_edit, button_delete, x): y = 725 pygame.draw.rect(screen, (255, 0, 0), button_edit) pygame.draw.rect(screen, (255, 0, 0), button_delete) text_tools.draw_text('Modifier', font_text, (0, 0, 0), screen, x + 50, y) text_tools.draw_text('Supprimer', font_text, (0, 0, 0), screen, x + 170, y)
def main_menu(): click = False while True: screen.fill((192, 192, 192)) screen.blit(fond_ecran, (25, 25)) text_tools.draw_text('Projet Dev', font_title, (0, 0, 0), screen, 50, 20) mx, my = pygame.mouse.get_pos() button_1 = pygame.Rect(50, 200, 300, 100) button_2 = pygame.Rect(50, 350, 300, 100) button_3 = pygame.Rect(50, 500, 300, 100) button_4 = pygame.Rect(50, 650, 300, 100) if button_1.collidepoint(mx, my): if click: play.game() if button_2.collidepoint(mx, my): if click: rules() if button_3.collidepoint(mx, my): if click: options() if button_4.collidepoint(mx, my): if click: exit() screen.blit(font_title.render('Jouer', True, (255, 255, 255)), (88, 225)) screen.blit(font_title.render('Regles', True, (255, 255, 255)), (88, 375)) screen.blit(font_title.render('Options', True, (255, 255, 255)), (88, 525)) screen.blit(font_title.render('Quitter', True, (255, 255, 255)), (88, 675)) text_tools.blit_text( screen, """Cliquer sur le bouton que vous voulez et appuyer sur \'Echap\' pour revenir au menu precedent""", (1105, 385), font_text, (0, 6, 251)) click = False for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_ESCAPE: pygame.quit() sys.exit() if event.type == MOUSEBUTTONDOWN: if event.button == 1: click = True pygame.display.update()
def rules(): continuer = True while continuer: screen.fill((192, 192, 192)) mx, my = pygame.mouse.get_pos() text_tools.draw_text('Regles', font_title, (0, 0, 0), screen, 20, 20) rules = """Le but du jeu est de vider la barre de vie de son adversaire ainsi etre le dernier survivant. Chaque joueur possede un maximum de 100 PV (barre de vie) et de 30 points de boucliers. Plus votre bouclier prend de degats plus vous perdez de vos PV. Vous avez un deck de 32 cartes maximun et une main de 7 cartes maximum. Vous disposez de 3 ressources differentes, necessaires a l'utilisation de vos cartes : - votre energie - vos potions - votre mana Vos ressources sont generees automatiquement a chaque debut de tour (ou a l'aide de vos cartes selon ces competences). Deroulement d'un tour : Au debut de votre tour, vous generez des ressources en plus. Apres cela, vous piochez une carte aleatoirement dans votre deck si votre en main ne contient pas deja 7 cartes. Vous avez en suite 2 choix : - Soit vous jouez une carte avec clique gauche en depensant le cout necessaire en ressources. - Soit vous defaussez une carte de votre main. C'est la fin de votre tour, et le debut de celui de votre adversaire qui se deroule exactement pareil. La partie se terminent lorsqu'un joueur tombe a 0 points de vie. """ text_tools.blit_text(screen, rules, (20, 120), font_text) button_option_1 = pygame.Rect(20, 850, 100, 40) pygame.draw.rect(screen, (0, 0, 0), button_option_1) text_tools.draw_text('Retour', font_text, (255, 255, 255), screen, 32, 855) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_ESCAPE: continuer = False if event.type == MOUSEBUTTONDOWN: if button_option_1.collidepoint(mx, my) and event.button == 1: continuer = False pygame.display.update()
def options(): continuer = True click = False while continuer: screen.fill((192, 192, 192)) mx, my = pygame.mouse.get_pos() # screen.blit(prompt, prompt_rect) # screen.blit(user_input, user_input_rect) text_tools.draw_text('Options', font_title, (0, 0, 0), screen, 20, 20) button_option_1 = pygame.Rect(50, 200, 600, 100) # button_option_2 = pygame.Rect(50, 350, 600, 100) button_option_3 = pygame.Rect(50, 500, 600, 100) if button_option_1.collidepoint(mx, my): if click: Cards_CRUD.cards_list() # elif button_option_2.collidepoint(mx, my): # if click: # Stats.stats() elif button_option_3.collidepoint(mx, my): if click: continuer = False pygame.draw.rect(screen, (0, 0, 0), button_option_1) # pygame.draw.rect(screen, (0, 0, 0), button_option_2) pygame.draw.rect(screen, (0, 0, 0), button_option_3) screen.blit( font_title.render('Gestion des cartes', True, (255, 255, 255)), (88, 225)) # screen.blit(font_title.render('Statistiques', True, (255, 255, 255)), (88, 375)) screen.blit(font_title.render('Retour', True, (255, 255, 255)), (88, 525)) click = False for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == KEYDOWN: if event.key in (pygame.K_ESCAPE, pygame.K_KP_ENTER): continuer = False break elif event.type == MOUSEBUTTONDOWN: if event.button == 1: click = True pygame.display.update()
def cards_list(): continuer = True # begin of the loop n = 0 # end of the loop m = 3 # get_cards_csv() # for card in cards: # print(card) test_cards = mysql_connexion.readCards() get_cards_db(test_cards) nb_cards = len(cards) while continuer: mx, my = pygame.mouse.get_pos() screen.fill((192, 192, 192)) button_option_1 = pygame.Rect(20, 20, 100, 40) #pygame.draw.rect(screen, (0, 0, 0), button_option_1) #text_tools.draw_text('Retour', font_text, (255, 255, 255), screen, 35, 25) button_option_2 = pygame.Rect(20, 820, 150, 40) pygame.draw.rect(screen, (255, 0, 0), button_option_1) pygame.draw.rect(screen, (255, 0, 0), button_option_2) text_tools.draw_text('Retour', font_text, (0, 0, 0), screen, 35, 25) text_tools.draw_text('Créer carte', font_text, (0, 0, 0), screen, 35, 825) button_edit_1 = pygame.Rect(150, 720, 100, 40) button_delete_1 = pygame.Rect(270, 720, 140, 40) button_edit_2 = pygame.Rect(500, 720, 100, 40) button_delete_2 = pygame.Rect(620, 720, 140, 40) button_edit_3 = pygame.Rect(850, 720, 100, 40) button_delete_3 = pygame.Rect(970, 720, 140, 40) # # add_buttons(screen, button_edit_1, button_delete_1, 110) # add_buttons(screen, button_edit_2, button_delete_2, 460) # add_buttons(screen, button_edit_3, button_delete_3, 810) #cards = mysql_connexion.readCards() #nb_cards = len(cards) fond_carte_po = pygame.image.load( "ressources/fonds de cartes/fond_carte_13.png").convert_alpha() fond_carte_pm = pygame.image.load( "ressources/fonds de cartes/fond_carte_11.png").convert_alpha() fond_carte_pa = pygame.image.load( "ressources/fonds de cartes/fond_carte_09.png").convert_alpha() left_arrow = pygame.image.load( "ressources/images/left arrow.png").convert_alpha() left_arrow_small = pygame.transform.scale(left_arrow, (50, 50)) button_left_arrow = pygame.Rect(5, 430, 50, 50) pygame.draw.rect(screen, (192, 192, 192), button_left_arrow) right_arrow = pygame.image.load( "ressources/images/right arrow.png").convert_alpha() right_arrow_small = pygame.transform.scale(right_arrow, (50, 50)) button_right_arrow = pygame.Rect(1225, 430, 50, 50) pygame.draw.rect(screen, (192, 192, 192), button_right_arrow) x = 110 y = 200 # On veut afficher juste 3 cartes à la fois for card in cards[n:m]: add_buttons(screen, button_edit_1, button_delete_1, 110) if len(cards) > n + 1: add_buttons(screen, button_edit_2, button_delete_2, 460) if len(cards) > n + 2: add_buttons(screen, button_edit_3, button_delete_3, 810) # card_set[card[0]] = pygame.Rect(x, y, 340, 474) # pygame.draw.rect(screen, (192, 192, 192), card_set[card[0]]) if card.get_ressource_type() == "PO": screen.blit(fond_carte_po, (x, y)) elif card.get_ressource_type() == "PM": screen.blit(fond_carte_pm, (x, y)) elif card.get_ressource_type() == "PA": screen.blit(fond_carte_pa, (x, y)) if n > 0: screen.blit(left_arrow_small, (5, 430)) if nb_cards > n + 3: screen.blit(right_arrow_small, (1225, 430)) text_tools.draw_text(card.get_name(), font_text, (0, 0, 0), screen, x + 50, y + 20) text_tools.draw_text( 'Cost : ' + str(card.get_cost()) + ' ' + card.get_ressource_type(), font_text, (0, 0, 0), screen, x + 50, y + 100) text_tools.draw_text( 'Effect : ' + str(card.get_value()) + ' ' + card.get_target() + ' ' + card.get_effect(), font_text, (0, 0, 0), screen, x + 50, y + 125) text_tools.draw_text('Rarity : ' + card.get_rarity(), font_text, (0, 0, 0), screen, x + 50, y + 150) y2 = 400 for line in break_text(card.get_description()): text_tools.draw_text(line, font_text, (0, 0, 0), screen, x + 50, y2) y2 = y2 + 25 x += 350 for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_ESCAPE: continuer = False if event.type == MOUSEBUTTONDOWN: if button_option_1.collidepoint(mx, my) and event.button == 1: continuer = False if button_option_2.collidepoint(mx, my) and event.button == 1: new_card = Card('', '', '', '', '', '', '', '') create_card(new_card, "create") if button_left_arrow.collidepoint( mx, my) and event.button == 1 and n > 0: n = n - 3 m = m - 3 elif button_right_arrow.collidepoint( mx, my) and event.button == 1 and nb_cards > n + 3: n = n + 3 m = m + 3 if button_edit_1.collidepoint(mx, my) and event.button == 1: create_card(cards[n], "edit") if button_edit_2.collidepoint(mx, my) and event.button == 1: create_card(cards[n + 1], "edit") if button_edit_3.collidepoint(mx, my) and event.button == 1: create_card(cards[n + 2], "edit") if button_delete_1.collidepoint(mx, my) and event.button == 1: delete_card(cards[n]) if button_delete_2.collidepoint(mx, my) and event.button == 1: delete_card(cards[n + 1]) if button_delete_3.collidepoint(mx, my) and event.button == 1: delete_card(cards[n + 2]) pygame.display.update()
def create_card(card, mode="create"): name_input = InputBox(200, 25, 140, 32, card.get_name(), str) ressource_type_input = InputBox(350, 75, 140, 32, card.get_ressource_type(), str, ['PA', 'PM', 'PO'], 'Ressource non reconnue') cost_input = InputBox(100, 125, 140, 32, str(card.get_cost()), int) effect_input = InputBox(300, 175, 140, 32, card.get_effect(), str, ['Life', 'Shield'], 'Effet non reconnu') value_input = InputBox(100, 225, 140, 32, str(card.get_value()), int) target_input = InputBox(250, 275, 140, 32, card.get_target(), str, ['Self', 'Enemy'], 'Cible non reconnue') rarity_input = InputBox(350, 325, 140, 32, card.get_rarity(), str, ['Rare', 'Epic', 'Legendary'], 'Rareté non reconnue') description_input = InputBox(200, 375, 140, 32, card.get_description(), str) input_boxes = [ name_input, ressource_type_input, cost_input, effect_input, value_input, target_input, rarity_input, description_input ] clock = pygame.time.Clock() done = False while not done: mx, my = pygame.mouse.get_pos() screen.fill((192, 192, 192)) for box in input_boxes: box.update() for box in input_boxes: box.draw(screen) text_tools.draw_text('Nom de la carte:', font_text, (0, 0, 0), screen, 10, 25) text_tools.draw_text('Type de ressource (PA, PM ou PO):', font_text, (0, 0, 0), screen, 10, 75) text_tools.draw_text('Cout:', font_text, (0, 0, 0), screen, 10, 125) text_tools.draw_text('Effet (Life ou Shield):', font_text, (0, 0, 0), screen, 10, 175) text_tools.draw_text('Valeur:', font_text, (0, 0, 0), screen, 10, 225) text_tools.draw_text('Cible (Self ou Enemy):', font_text, (0, 0, 0), screen, 10, 275) text_tools.draw_text('Rareté (Rare, Epic ou Legendary):', font_text, (0, 0, 0), screen, 10, 325) text_tools.draw_text('Description:', font_text, (0, 0, 0), screen, 10, 375) button_option_1 = pygame.Rect(20, 620, 150, 40) button_option_2 = pygame.Rect(220, 620, 150, 40) pygame.draw.rect(screen, (255, 0, 0), button_option_1) pygame.draw.rect(screen, (255, 0, 0), button_option_2) text_tools.draw_text(mode, font_text, (0, 0, 0), screen, 35, 625) text_tools.draw_text('Retour', font_text, (0, 0, 0), screen, 235, 625) events = pygame.event.get() for event in events: if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == MOUSEBUTTONDOWN: if button_option_1.collidepoint(mx, my) and event.button == 1: for box in input_boxes: box.validateInput() if (mode == "create"): done = mysql_connexion.createCard(input_boxes) elif (mode == "edit"): mysql_connexion.editCard(input_boxes, card.get_name()) done = edit_card(input_boxes) if button_option_2.collidepoint(mx, my) and event.button == 1: done = True for box in input_boxes: box.handle_event(event) pygame.display.update()
def end_game(): global joueur1 global joueur2 button_retour = pygame.Rect(400, 800, 400, 65) done = False musique_partie.stop() screen.fill((30, 30, 30)) # joueur1.hp = 0 text_tools.draw_text("Nombre de tour joués : " + str(tour), font_retour, (255, 255, 255), screen, 120, 300) pygame.draw.rect(screen, (30, 30, 30), button_retour) text_tools.draw_text('Retour au menu', font_title, (255, 255, 255), screen, 400, 805) if joueur1.hp <= 0: text_tools.draw_text("Victoire du joueur 2 !", font_title, (255, 255, 255), screen, 400, 120) text_tools.draw_text( "Nombre de Points de vie restants : " + str(joueur2.hp), font_retour, (255, 255, 255), screen, 120, 400) text_tools.draw_text( "Nombre de points de bouclier restants : " + str(joueur1.shield), font_retour, (255, 255, 255), screen, 120, 500) musique_loose_start.play() musique_loose.play() elif joueur2.hp <= 0: text_tools.draw_text("Victoire du joueur 1 !", font_title, (255, 255, 255), screen, 400, 120) text_tools.draw_text( "Nombre de Points de vie restants : " + str(joueur1.hp), font_retour, (255, 255, 255), screen, 120, 400) text_tools.draw_text( "Nombre de points de bouclier restants : " + str(joueur1.shield), font_retour, (255, 255, 255), screen, 120, 500) musique_win_start.play() musique_win.play() pygame.display.flip() while not done: mx, my = pygame.mouse.get_pos() for event in pygame.event.get(): if event.type == MOUSEBUTTONDOWN: if button_retour.collidepoint(mx, my) and event.button == 1: done = True return done if event.type == QUIT: pygame.quit() sys.exit()
def get_username(): font = pygame.font.Font(None, 70) input_box_1 = pygame.Rect(500, 350, 350, 65) input_box_2 = pygame.Rect(500, 450, 350, 65) button_play = pygame.Rect(500, 700, 250, 65) color_inactive = pygame.Color('white') color_active = pygame.Color('red') color1 = color_inactive color2 = color_inactive global player1_username global player2_username active1 = False active2 = False text1 = '' text2 = '' done = False while not done: mx, my = pygame.mouse.get_pos() for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN: # If the user clicked on the input_box rect. if input_box_1.collidepoint(mx, my): # Toggle the active variable. active1 = not active1 if active2: active2 = False elif input_box_2.collidepoint(mx, my): # Toggle the active variable. active2 = not active2 if active1: active1 = False else: active1 = False active2 = False # Change the current color of the input box. color1 = color_active if active1 else color_inactive color2 = color_active if active2 else color_inactive if event.type == pygame.KEYDOWN: if active1: if event.key == pygame.K_RETURN: player1_username = text1 elif event.key == pygame.K_BACKSPACE: text1 = text1[:-1] else: text1 += event.unicode if active2: if event.key == pygame.K_RETURN: player2_username = text2 elif event.key == pygame.K_BACKSPACE: text2 = text2[:-1] else: text2 += event.unicode if event.type == MOUSEBUTTONDOWN: if button_play.collidepoint( mx, my ) and event.button == 1 and text1 != '' and text2 != '': return [text1, text2] screen.fill((121, 114, 114)) # Render the current text. text_tools.draw_text( "Clic gauche pour jouer une carte, clic droit pour se défausser d'une carte", font_text, (255, 255, 255), screen, 50, 80) text_tools.draw_text("Pseudo joueur 1 :", font, pygame.Color('white'), screen, 50, 350) text_tools.draw_text("Pseudo joueur 2 :", font, pygame.Color('white'), screen, 50, 450) txt_surface = font.render(text1, True, color1) txt_surface2 = font.render(text2, True, color2) # Resize the box if the text is too long. width = max(350, txt_surface.get_width() + 10) input_box_1.w = width # Blit the text. screen.blit(txt_surface, (input_box_1.x + 5, input_box_1.y + 5)) screen.blit(txt_surface2, (input_box_2.x + 5, input_box_2.y + 5)) # Blit the input_box rect. pygame.draw.rect(screen, color1, input_box_1, 2) pygame.draw.rect(screen, color2, input_box_2, 2) pygame.draw.rect(screen, (121, 114, 114), button_play) text_tools.draw_text('JOUER', font_title, (255, 255, 255), screen, 500, 705) pygame.display.flip()
def print_hand(joueur): position = joueur.get_player_index() player_hand = joueur.get_player_hand() global hand1 global hand2 if position == 1: x = 50 y = 485 for i in range(0, len(joueur.get_player_hand())): hand1[i] = pygame.Rect(x, y, 150, 200) pygame.draw.rect(screen, (192, 192, 192), hand1[i]) text_tools.draw_text("Coût :", font_text, (0, 0, 0), screen, x + 15, y + 50) text_tools.draw_text(str(player_hand[i].cost), font_text, (0, 0, 0), screen, x + 67, y + 50) if player_hand[i].ressource_type == 'PA': screen.blit(fond_carte_pa_small, (x, y)) screen.blit(pa_very_small, (x + 105, y + 52)) elif player_hand[i].ressource_type == 'PO': screen.blit(fond_carte_po_small, (x, y)) screen.blit(po_very_small, (x + 105, y + 52)) elif player_hand[i].ressource_type == 'PM': screen.blit(fond_carte_pm_small, (x, y)) screen.blit(pm_very_small, (x + 105, y + 52)) text_tools.draw_text(player_hand[i].name, font_text_small, (0, 0, 0), screen, x + 12, y + 5) text_tools.draw_text(player_hand[i].target, font_text, (0, 0, 0), screen, x + 15, y + 100) text_tools.draw_text(str(player_hand[i].value), font_text, (0, 0, 0), screen, x + 67, y + 100) if player_hand[i].effect == 'Shield': screen.blit(shield_very_small, (x + 105, y + 102)) elif player_hand[i].effect == 'Life': screen.blit(heart_very_small, (x + 105, y + 102)) x += 175 elif position == 2: x = 50 y = 85 for i in range(0, len(joueur.get_player_hand())): hand2[i] = pygame.Rect(x, y, 150, 200) pygame.draw.rect(screen, (192, 192, 192), hand2[i]) text_tools.draw_text("Coût :", font_text, (0, 0, 0), screen, x + 15, y + 50) text_tools.draw_text(str(player_hand[i].cost), font_text, (0, 0, 0), screen, x + 67, y + 50) if player_hand[i].ressource_type == 'PA': screen.blit(fond_carte_pa_small, (x, y)) screen.blit(pa_very_small, (x + 105, y + 52)) elif player_hand[i].ressource_type == 'PO': screen.blit(fond_carte_po_small, (x, y)) screen.blit(po_very_small, (x + 105, y + 52)) elif player_hand[i].ressource_type == 'PM': screen.blit(fond_carte_pm_small, (x, y)) screen.blit(pm_very_small, (x + 105, y + 52)) text_tools.draw_text(player_hand[i].name, font_text_small, (0, 0, 0), screen, x + 12, y + 5) text_tools.draw_text(player_hand[i].target, font_text, (0, 0, 0), screen, x + 15, y + 100) text_tools.draw_text(str(player_hand[i].value), font_text, (0, 0, 0), screen, x + 67, y + 100) if player_hand[i].effect == 'Shield': screen.blit(shield_very_small, (x + 105, y + 102)) elif player_hand[i].effect == 'Life': screen.blit(heart_very_small, (x + 105, y + 102)) x += 175
def game_interface(joueur1, joueur2): screen.fill((192, 192, 192)) global rect_end_turn rect_joueur_2 = pygame.Rect(10, 0, 1260, 100) text_tools.draw_text(joueur2.name, font_title, (0, 0, 0), screen, 35, 25) rect_joueur_1 = pygame.Rect(10, 810, 1260, 100) text_tools.draw_text(joueur1.name, font_title, (0, 0, 0), screen, 35, 735) text_tools.draw_text('Tour ' + str(tour), font_text, (0, 0, 0), screen, 25, 440) rect_end_turn = pygame.Rect(1140, 425, 100, 50) text_tools.draw_text('Fin de tour', font_text, (0, 0, 0), screen, 1155, 440) text_tools.draw_text(str(joueur2.hp), font_text, (0, 0, 0), screen, 460, 60) screen.blit(heart_small, (450, 20)) text_tools.draw_text(str(joueur1.hp), font_text, (0, 0, 0), screen, 460, 770) screen.blit(heart_small, (450, 730)) text_tools.draw_text(str(joueur2.shield), font_text, (0, 0, 0), screen, 535, 60) screen.blit(shield_small, (525, 20)) text_tools.draw_text(str(joueur1.shield), font_text, (0, 0, 0), screen, 535, 770) screen.blit(shield_small, (525, 730)) text_tools.draw_text(str(joueur2.mana_stock), font_text, (0, 0, 0), screen, 745, 60) text_tools.draw_text('(+' + str(joueur2.mana_generation) + ')', font_text, (0, 0, 0), screen, 760, 60) screen.blit(pm_small, (750, 20)) text_tools.draw_text(str(joueur1.mana_stock), font_text, (0, 0, 0), screen, 745, 770) text_tools.draw_text('(+' + str(joueur1.mana_generation) + ')', font_text, (0, 0, 0), screen, 760, 870) screen.blit(pm_small, (750, 730)) text_tools.draw_text(str(joueur2.gold_stock), font_text, (0, 0, 0), screen, 815, 60) text_tools.draw_text('(+' + str(joueur2.gold_generation) + ')', font_text, (0, 0, 0), screen, 835, 60) screen.blit(po_small, (825, 20)) text_tools.draw_text(str(joueur1.gold_stock), font_text, (0, 0, 0), screen, 815, 770) text_tools.draw_text('(+' + str(joueur1.gold_generation) + ')', font_text, (0, 0, 0), screen, 835, 870) screen.blit(po_small, (825, 730)) text_tools.draw_text(str(joueur2.action_stock), font_text, (0, 0, 0), screen, 890, 60) text_tools.draw_text('(+' + str(joueur2.action_generation) + ')', font_text, (0, 0, 0), screen, 910, 60) screen.blit(pa_small, (900, 20)) text_tools.draw_text(str(joueur1.action_stock), font_text, (0, 0, 0), screen, 890, 770) text_tools.draw_text('(+' + str(joueur1.action_generation) + ')', font_text, (0, 0, 0), screen, 910, 870) screen.blit(pa_small, (900, 730)) text_tools.draw_text( str(deck_joueur2.get_nb_cards_in_deck()) + ' card(s) left', font_text, (0, 0, 0), screen, 1100, 60) screen.blit(deck_small, (1120, 20)) text_tools.draw_text( str(deck_joueur1.get_nb_cards_in_deck()) + ' card(s) left', font_text, (0, 0, 0), screen, 1100, 770) screen.blit(deck_small, (1120, 730))
def action_depending_of_card(player, enemy, player_hand, player_deck): bonus_damages = 0 progressing = True done = False rect_info = pygame.Rect(10, 400, 1260, 100) for j in range(0, len(player.get_player_hand())): # On joue la carte avec le bouton gauche if player_hand[j].collidepoint( (mx, my)) and event.button == 1 and player.hand[j]: if 25 < enemy.shield < 30: bonus_damages = 0.05 elif 20 < enemy.shield <= 25: bonus_damages = 0.10 elif 15 < enemy.shield <= 20: bonus_damages = 0.15 elif 10 < enemy.shield <= 15: bonus_damages = 0.20 elif 5 < enemy.shield <= 10: bonus_damages = 0.25 elif 0 < enemy.shield <= 5: bonus_damages = 0.30 # print('shield : ' + str(enemy.shield) + ' - bonus dégats : ' + str(bonus_damages)) if player.hand[j].ressource_type == 'PA': if player.action_stock >= player.hand[j].cost: # print('Vous pouvez jouer la carte') if player.hand[j].effect == 'Shield': if player.hand[j].target == 'Self': if player.shield < 30: print('Le joueur ' + str(player.player_index) + ' gagne ' + str(player.hand[j].value) + ' points de shield') player.shield += player.hand[j].value if player.shield > 30: player.shield = 30 progressing = False else: text_tools.draw_text( 'Vos points de bouclier sont au maximum', font_title, (255, 255, 255), screen, 250, 420) pygame.display.flip() time.sleep(1) elif enemy.shield > abs(player.hand[j].value): if enemy.shield > 0: enemy.shield += player.hand[j].value print('Le joueur ' + str(enemy.player_index) + ' perd ' + str(abs(player.hand[j].value)) + ' points de shield') if enemy.shield < 0: enemy.shield = 0 progressing = False else: text_tools.draw_text( 'L\'adversaire n\'a plus de bouclier !', font_title, (255, 255, 255), screen, 250, 420) pygame.display.flip() time.sleep(1) elif player.hand[j].effect == 'Life': if player.hand[j].target == 'Self': if player.hp < 100: print('Le joueur ' + str(player.player_index) + ' gagne ' + str(player.hand[j].value) + ' points de vie') player.hp += player.hand[j].value if player.hp > 100: player.hp = 100 progressing = False else: text_tools.draw_text( 'Vos points de vie sont au maximum', font_title, (255, 255, 255), screen, 250, 420) pygame.display.flip() time.sleep(1) elif enemy.hp > abs(player.hand[j].value): enemy.hp += int(player.hand[j].value * (1 + bonus_damages)) print('Le joueur ' + str(enemy.player_index) + ' perd ' + str( abs( int(player.hand[j].value * (1 + bonus_damages)))) + ' points de vie') progressing = False elif enemy.hp <= abs(player.hand[j].value): enemy.hp += int(player.hand[j].value * (1 + bonus_damages)) print('Le joueur ' + str(enemy.player_index) + ' perd ' + str( abs( int(player.hand[j].value * (1 + bonus_damages)))) + ' points de vie') print( 'Le joueur ' + str(enemy.player_index) + ' n\'a plus de points de vie ! Le joueur ' + str(player.player_index) + ' remporte la partie !') done = end_game() return done if progressing == False: player.action_stock -= player.hand[j].cost player.hand.remove(player.hand[j]) if player_deck.get_nb_cards_in_deck() > 0: add_card_to_hand(player_deck, player, True) else: text_tools.draw_text( 'Le joueur n\'a plus de cartes dans son deck !', font_title, (255, 255, 255), screen, 250, 420) pygame.display.flip() time.sleep(1) end_turn() # print(str(tour)) else: text_tools.draw_text('Pas assez de ressouces', font_title, (255, 255, 255), screen, 250, 320) pygame.display.flip() time.sleep(1) elif player.hand[j].ressource_type == 'PM': if player.mana_stock >= player.hand[j].cost: # print('Vous pouvez jouer la carte') if player.hand[j].effect == 'Shield': if player.hand[j].target == 'Self': if player.shield < 30: print('Le joueur ' + str(player.player_index) + ' gagne ' + str(player.hand[j].value) + ' points de shield') player.shield += player.hand[j].value if player.shield > 30: player.shield = 30 progressing = False else: text_tools.draw_text( 'Vos points de bouclier sont au maximum', font_title, (255, 255, 255), screen, 250, 420) pygame.display.flip() time.sleep(1) elif enemy.shield > abs(player.hand[j].value): if enemy.shield > 0: enemy.shield += player.hand[j].value print('Le joueur ' + str(enemy.player_index) + ' perd ' + str(abs(player.hand[j].value)) + ' points de shield') if enemy.shield < 0: enemy.shield = 0 progressing = False else: text_tools.draw_text( 'L\'adversaire n\'a plus de bouclier !', font_title, (255, 255, 255), screen, 250, 420) pygame.display.flip() time.sleep(1) elif player.hand[j].effect == 'Life': if player.hand[j].target == 'Self': if player.hp < 100: print('Le joueur ' + str(player.player_index) + ' gagne ' + str(player.hand[j].value) + ' points de vie') player.hp += player.hand[j].value if player.hp > 100: player.hp = 100 progressing = False else: text_tools.draw_text( 'Vos points de vie sont au maximum', font_title, (255, 255, 255), screen, 250, 420) pygame.display.flip() time.sleep(1) elif enemy.hp > abs(player.hand[j].value): enemy.hp += int(player.hand[j].value * (1 + bonus_damages)) print('Le joueur ' + str(enemy.player_index) + ' perd ' + str( abs( int(player.hand[j].value * (1 + bonus_damages)))) + ' points de vie') progressing = False elif enemy.hp <= abs(player.hand[j].value): enemy.hp += int(player.hand[j].value * (1 + bonus_damages)) print('Le joueur ' + str(enemy.player_index) + ' perd ' + str( abs( int(player.hand[j].value * (1 + bonus_damages)))) + ' points de vie') print( 'Le joueur ' + str(enemy.player_index) + ' n\'a plus de points de vie ! Le joueur ' + str(player.player_index) + ' remporte la partie !') done = end_game() return done if progressing == False: player.mana_stock -= player.hand[j].cost player.hand.remove(player.hand[j]) if player_deck.get_nb_cards_in_deck() > 0: add_card_to_hand(player_deck, player, True) else: text_tools.draw_text( 'Le joueur n\'a plus de cartes dans son deck !', font_title, (255, 255, 255), screen, 250, 420) pygame.display.flip() time.sleep(1) end_turn() # print(str(tour)) else: text_tools.draw_text('Pas assez de ressouces', font_title, (255, 255, 255), screen, 250, 320) pygame.display.flip() time.sleep(1) elif player.hand[j].ressource_type == 'PO': if player.gold_stock >= player.hand[j].cost: # print('Vous pouvez jouer la carte') if player.hand[j].effect == 'Shield': if player.hand[j].target == 'Self': if player.shield < 30: print('Le joueur ' + str(player.player_index) + ' gagne ' + str(player.hand[j].value) + ' points de shield') player.shield += player.hand[j].value if player.shield > 30: player.shield = 30 progressing = False else: text_tools.draw_text( 'Vos points de bouclier sont au maximum', font_title, (255, 255, 255), screen, 250, 420) pygame.display.flip() time.sleep(1) elif enemy.shield > abs(player.hand[j].value): if enemy.shield > 0: enemy.shield += player.hand[j].value print('Le joueur ' + str(enemy.player_index) + ' perd ' + str(abs(player.hand[j].value)) + ' points de shield') if enemy.shield < 0: enemy.shield = 0 progressing = False else: text_tools.draw_text( 'L\'adversaire n\'a plus de bouclier !', font_title, (255, 255, 255), screen, 250, 420) pygame.display.flip() time.sleep(1) elif player.hand[j].effect == 'Life': if player.hand[j].target == 'Self': if player.hp < 100: print('Le joueur ' + str(player.player_index) + ' gagne ' + str(player.hand[j].value) + ' points de vie') player.hp += player.hand[j].value if player.hp > 100: player.hp = 100 progressing = False else: text_tools.draw_text( 'Vos points de vie sont au maximum', font_title, (255, 255, 255), screen, 250, 420) pygame.display.flip() time.sleep(1) elif enemy.hp > abs(player.hand[j].value): enemy.hp += int(player.hand[j].value * (1 + bonus_damages)) print('Le joueur ' + str(enemy.player_index) + ' perd ' + str( abs( int(player.hand[j].value * (1 + bonus_damages)))) + ' points de vie') progressing = False elif enemy.hp <= abs(player.hand[j].value): enemy.hp += int(player.hand[j].value * (1 + bonus_damages)) print('Le joueur ' + str(enemy.player_index) + ' perd ' + str( abs( int(player.hand[j].value * (1 + bonus_damages)))) + ' points de vie') print( 'Le joueur ' + str(enemy.player_index) + ' n\'a plus de points de vie ! Le joueur ' + str(player.player_index) + ' remporte la partie !') done = end_game() return done if progressing == False: player.gold_stock -= player.hand[j].cost player.hand.remove(player.hand[j]) if player_deck.get_nb_cards_in_deck() > 0: add_card_to_hand(player_deck, player, True) else: text_tools.draw_text( 'Le joueur n\'a plus de cartes dans son deck !', font_title, (255, 255, 255), screen, 250, 320) pygame.display.flip() time.sleep(1) end_turn() # print(str(tour)) else: text_tools.draw_text('Pas assez de ressouces', font_title, (255, 255, 255), screen, 250, 320) pygame.display.flip() time.sleep(1) # joueur2.hand.remove(joueur2.hand[j]) # Discard avec le bouton droit elif player_hand[j].collidepoint( (mx, my)) and event.button == 3 and player.hand[j]: print('Clic sur la ' + str(j + 1) + 'eme carte de ma main du joueur ' + str(player.player_index)) print('discard ' + player.hand[j].name) player.hand.remove(player.hand[j]) if player_deck.get_nb_cards_in_deck() > 0: add_card_to_hand(player_deck, player, True) end_turn()
def rules(): continuer = True while continuer: screen.fill((192, 192, 192)) mx, my = pygame.mouse.get_pos() text_tools.draw_text('Règles', font_title, (0, 0, 0), screen, 20, 20) rules = """Le but du jeu est de se défaire de son adversaire et ainsi d'être le dernier des deux joueurs en vie. Chaque joueur possède un maximum de 100 points de vie (PV) et 30 points de boucliers. Des dégats supplémentaires sont infligés en cas de nombre de points de bouclier réduits. Vous jouez avec un deck de 32 cartes et une main composée de 7 cartes au maximum. Vous disposez également de 3 ressources nécessaires à l'utilisation de vos cartes : - des points d'action (PA) - de l'or (PO) - des points de mana (PM) Ces ressources sont générées à chaque tour automatiquement ou à l'aide de cartes, et peuvent être stockées d'un tour à l'autre. Au début de votre tour, vous générez des ressources supplémentaires. Vous piochez automatiquement une carte si votre en main en contient moins de 7. Vous pouvez ensuite 2 possibilités : - Jouer une carte en dépensant le coût nécessaire en ressources. - Vous défausser d'une des cartes de votre main. C'est ensuite la fin de votre tour, et le début de celui de votre adversaire. La partie se terminent lorsqu'un joueur tombe à 0 points de vie. """ screen.blit(heart_very_small, (595, 151)) screen.blit(shield_very_small, (865, 151)) screen.blit(deck_very_small, (250, 268)) screen.blit(pa_very_small, (290, 353)) screen.blit(po_very_small, (178, 383)) screen.blit(pm_very_small, (290, 413)) text_tools.blit_text(screen, rules, (20, 120), font_text) button_option_1 = pygame.Rect(20, 850, 100, 40) pygame.draw.rect(screen, (0, 0, 0), button_option_1) text_tools.draw_text('Retour', font_text, (255, 255, 255), screen, 32, 855) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_ESCAPE: continuer = False if event.type == MOUSEBUTTONDOWN: if button_option_1.collidepoint(mx, my) and event.button == 1: continuer = False pygame.display.update()