Skip to content
Snippets Groups Projects
Commit b9c61116 authored by Ouhmidou Sarra's avatar Ouhmidou Sarra
Browse files

fin cartes spéciales

parent f01d620d
Branches special2
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
No preview for this file type
File added
......@@ -34,11 +34,10 @@ def create_all_cards():
Card(id = i, front = front_image_path, back = back_image_path, theme =3)
#creation of special cards
Card(id = 200, front = "IMAGES/power1.png", back = '', theme = 0, power = 1)
Card(id = 201, front = "IMAGES/power2.png", back = '', theme = 0, power = 2)
Card(id = 202, front = "IMAGES/power3.png", back = '', theme = 0, power = 3)
Card(id = 203, front = "IMAGES/power4.png", back = '', theme = 0, power = 4)
Card(id = 204, front = "IMAGES/power5.png", back = '', theme = 0, power = 5)
Card(id = 200, front = "IMAGES/power1.png", back = '', theme = 0, power = 1) # +10
Card(id = 201, front = "IMAGES/power2.png", back = '', theme = 0, power = 2) # -5
Card(id = 202, front = "IMAGES/power3.png", back = '', theme = 0, power = 3) # pair
Card(id = 203, front = "IMAGES/power4.png", back = '', theme = 0, power = 4) #shuffle
def associate_all_pairs(theme) -> None :
CARDS = Card.get_cards() #we fetch the list of all the cards
......@@ -53,6 +52,7 @@ def associate_all_pairs(theme) -> None :
def get_front_images(game): #renvoie une liste de toutes les images face des cartes de la grille, meme indices que la grille
front_images = []
grid = game.grid
print(game.cards)
for l in grid :
front_images.append(['']*len(l))
nb_rows = game.level.nb_row
......
......@@ -64,8 +64,8 @@ class Card :
@classmethod
def choose_special_cards(cls, number):
special_cards_id_1 = [200, 203]
special_cards_id_2 = [201, 203]
special_cards_id_1 = [200, 202, 203]
special_cards_id_2 = [201, 202, 203]
choice = []
choice1 = rd.sample(special_cards_id_1, k = number)
choice.append(choice1)
......@@ -79,8 +79,8 @@ class Level :
self.nb_pairs = nb_pairs
self.nb_row = nb_row
self.nb_column = nb_column
self.timer = id*20 #time the player has before losing the game
self.max_attempts = 4*nb_pairs
self.timer = 500 #time the player has before losing the game
self.max_attempts = 500
class Game :
def __init__(self, level : Level, theme):
......@@ -93,13 +93,14 @@ class Game :
self.matched_pairs = 0 #number of pairs discovered
self.grid = [] #list of list containing the cards id that are in the grid
self.started = False
self.init_game()
self.init_special_cards()
self.init_game()
self.init_grid()
def init_game(self):
level = self.level
nb_pairs = level.nb_pairs
nb_pairs = level.nb_pairs
print(nb_pairs)
pairs = rd.sample(Card.THEMES[self.theme], k = nb_pairs)
for (i,j) in pairs :
self.cards.append(i)
......@@ -120,20 +121,13 @@ class Game :
def init_special_cards(self):
back = self.get_back()
if (self.level.id == 2 or self.level.id == 3):
if (self.level.id > 1) :
self.special_cards = Card.choose_special_cards(2)
for id in self.special_cards :
self.cards.append(id) #we add the special card to the other ones
card = Card.get_card_with_id(id)
card.back = back
card.theme = self.theme
elif (self.level.id == 4):
self.special_cards = Card.choose_special_cards(4)
for id in self.special_cards :
self.cards.append(id) #we add the special card to the other ones
card = Card.get_card_with_id(id)
card.back = back
card.theme = self.theme
def is_finished(self): #game over if all pairs have been discovered or all attemps have been used
return (self.matched_pairs is self.level.nb_pairs, self.attempts >= self.level.max_attempts)
......
......@@ -12,6 +12,7 @@ window_variables = []
#format : [window]
image_variables = []
#format : [front_images, images_id]
SHUFFLE = False
def create_window( title, color):
window = tk.Tk()
......@@ -159,7 +160,7 @@ def special1_2(game, can, playing_window, countdown_label, attempts_label, i):
update_countdown(game, can, playing_window, countdown_label, attempts_label, new_timer)
return countdown_label
def special4(game, can, front_images, back_image): #shuffle
def special4(game, can, front_images, back_image): #shuffle
new_grid = shuffle_cards(game) #change la grille du jeu
rows = game.level.nb_row
columns = game.level.nb_column
......@@ -178,7 +179,7 @@ def special4(game, can, front_images, back_image): #shuffle
k,l = get_card_position(game, new_id)
new_front_images[i][j] = front_images[k][l]
new_images_id[i][j] = can.create_image(j*column_width + column_width/2 , i*line_height + line_height/2, image = front_images[k][l])
image_variables[0] = new_front_images
image_variables[1] = new_images_id
......@@ -186,9 +187,9 @@ def special4(game, can, front_images, back_image): #shuffle
game.flipped = []
game.matched_pairs = 0
for list in new_images_id: #affichage des dos
for image_id in list :
can.itemconfig(image_id, image = back_image)
for i in range(rows): #on les affichent
for j in range(columns):
can.itemconfig(new_images_id[i][j], image = back_image)
for id in game.cards :
card = Card.get_card_with_id(id)
......@@ -197,8 +198,6 @@ def special4(game, can, front_images, back_image): #shuffle
for id in game.special_cards :
card = Card.get_card_with_id(id)
card.flipped = False
return new_images_id, new_front_images
def special3(game, can, images_id, list):
for (i,j) in Card.THEMES[game.theme] :
......@@ -263,6 +262,7 @@ def on_click(game, event, can, line_height, column_width, back_image, attempts_l
else :
game.matched_pairs += 1 #une paire en plus est trouvée
else :
global SHUFFLE
if (card.power == 1):
special1_2(game, can, playing_window, countdown_label, attempts_label, 1)
elif (card.power == 2):
......@@ -270,8 +270,8 @@ def on_click(game, event, can, line_height, column_width, back_image, attempts_l
elif (card.power == 3):
game.flipped.append(card.id)
special3(game, can, images_id, list)
elif (card.power == 4):
can.itemconfig(images_id[i][j], image = list[i][j]) # On affiche l'image
elif (card.power == 4 and SHUFFLE == False ):
SHUFFLE = True
special4(game, can, list, back_image)
def hide_unmatched_cards(game, can, images_id, card, previous_card, back_image):
......
......@@ -4,7 +4,7 @@ from interface2 import display_main_game_interface
def main():
create_all_cards()
associate_all_pairs(1) #on fait que pour le theme 1 et 2
associate_all_pairs(1)
associate_all_pairs(2)
associate_all_pairs(3)
player, game = init_player_and_game() #initialise le joueur et la partie
......
......@@ -5,7 +5,7 @@ from parameters_choice_interface import *
def main():
create_all_cards()
associate_all_pairs(1) #on fait que pour le theme 1 et 2
associate_all_pairs(1)
associate_all_pairs(2)
associate_all_pairs(3)
open_pseudo_window()
......
......@@ -22,7 +22,7 @@ def init_player_and_game():
game = Game(level, theme)
return player, game
elif id_level == 4 :
level = Level(id = 4, nb_pairs = 10, nb_row = 4, nb_column = 6)
level = Level(id = 4, nb_pairs = 11, nb_row = 4, nb_column = 6)
game = Game(level, theme)
return player, game
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment