Mastermind

Professeur référent :

M FAURY (ISN)

Avec mon collègue, nous avons, après une longue réflexion, décidé de réaliser un Mastermind, un projet issu des jeux de notre enfance.

 

Programme

from tkinter import *


class Application(Tk):
    def __init__(self):
        Tk.__init__(self)
        self.createWidgets()
        self.title("lolo&deckerfamily productionofgame")
        self.accueil()
        # self.creation_fenetre2
        self.canvas.grid()
        self.abandonner
        self.demonstration
        self.quitButton = Button(self, text='QUITTER',command=self.destroy) # Use destroy instead of quit
        self.quitButton.grid(row=0, column=3, sticky="nsew")

     
    def createWidgets(self):
        #taille de fenetre
        self.minsize(1100,500)

        #creation d'un cadre
        cadre = Frame(self)
        cadre.grid()

        #titre sur la page
        titre = Label(cadre,text="MASTERMIND")
        titre.grid(row=3, column=1, columnspan=1)

        #couleur de texte
        titre.configure(fg = 'red')

        #label
        label = Label(cadre, text="FIND THE RIGHT COMBINATION ", bg="blue")
        label.configure(fg = 'red')
        label.grid()



        #forme du jeu
        self.canvas = Canvas(self, width=1000, height=700, background='black')
        
    ##tentative pour créer une fenetre d'alerte indiquant la perte du jeu en cours en cas de fuite.    
    # def creation_fenetre2(self):
    #     fenetre2=Tk()
    #     titre1=Label(fenetre2, text = "ATTENTION:")
    #     titre1.grid()
    #     fenetre1.title("etes vous sur de vouloir partir? toutes progression sera perdu!")
    # 
    
    
    def jeu(self):
        self.canvas.delete('all')
        n = 10
        m = 4
        r = 60
        y0 = -61
        i = 1
        j = 0
        for j in range (n):
             y0 += 70
             j += 1
             x0 = 11
             for i in range (m):
                 x0 += 70
                 self.canvas.create_oval(x0, y0, x0+r, y0+r,fill='white')
                 i += 1
        r = 20 
        y0 = -61
        i = 1
        j = 0
        for j in range (n):
             y0 += 70
             j += 1
             x0 = m*70+70
             for i in range (m):
                 x0 += 20
                 self.canvas.create_oval(x0, y0, x0+r, y0+r, fill='white')
                 i += 1
        self.canvas.create_oval(580-15, 26-15, 580+15, 26+15, fill='red')
        self.canvas.create_oval(580-15, 79-15, 580+15, 79+15, fill='yellow')
        self.canvas.create_oval(580-15, 133-15, 580+15, 133+15, fill='blue')
        self.canvas.create_oval(580-15, 186-15, 580+15, 186+15, fill='orange')
        self.canvas.create_oval(580-15, 240-15, 580+15, 240+15, fill='green')
        self.canvas.create_oval(580-15, 293-15, 580+15, 293+15, fill='turquoise')
        self.canvas.create_oval(580-15, 347-15, 580+15, 347+15, fill='violet')
        self.canvas.create_oval(580-15, 401-15, 580+15, 401+15, fill='grey')
    
        btn_rules= Button(self.canvas, text='retour', command=self.rules)
        btn_rules_window = self.canvas.create_window(780,100, anchor=NW, window=btn_rules)
       
       
        btn_abandon= Button(self.canvas, text='abandonner', command=self.abandonner)
        btn_abandon_window = self.canvas.create_window(780,130, anchor=NW, window=btn_abandon)

    
         # btn_avt= Button(self.canvas, text= "return", command=self.creation_fenetre2)
         # btn_avt_window = self.canvas.create_window(800,200, anchor=NW, window=btn_avt)
         # self.canvas.bind("<Button-1>",self.creation_fenetre)
    
       
        
        self.canvas.create_rectangle(870,10,970,630,outline='blue', fill='red')
        self.canvas.create_text(920,50, text= 'M', font='Arial 50', fill='blue')        
        self.canvas.create_text(920,110, text= 'A', font='Arial 50', fill='blue') 
        self.canvas.create_text(920,170, text= 'S', font='Arial 50', fill='blue')  
        self.canvas.create_text(920,230, text= 'T', font='Arial 50', fill='blue') 
        self.canvas.create_text(930,290, text= 'E ', font='Arial 50', fill='blue') 
        self.canvas.create_text(930,350, text= 'R ', font='Arial 50', fill='blue') 
        self.canvas.create_text(930,410, text= 'M ', font='Arial 50', fill='blue')   
        self.canvas.create_text(930,470, text= 'I ', font='Arial 50', fill='blue') 
        self.canvas.create_text(930,530, text= 'N ', font='Arial 50', fill='blue') 
        self.canvas.create_text(930,590, text= 'D ', font='Arial 50', fill='blue') 
 
 
 
    def accueil(self):   
    #ACCUEIL
        self.canvas.delete('all')
        self.canvas.create_text(500,60, text='Mastermind', font='arial 70', fill='red')
        self.canvas.create_rectangle(250,195,750,285,outline='blue', fill='red')
        self.canvas.create_text(500,245, text= 'JOUER', font='Arial 30', fill='blue')
        
        self.canvas.create_text(500,400, text='BON COURAGE', font='arial 70', fill='red')

        
        btn_rules= Button(self.canvas, text='JOUER', command=self.rules)
        btn_rules_window = self.canvas.create_window(700,230, anchor=NW, window=btn_rules)
 
 
        self.canvas.bind("<Button-1>",self.rules)
        
    def rules(self):   
    #regles
        self.canvas.delete('all')
        self.canvas.create_text(500,40, text='Règles', font='arial 60', fill='red')
       
        self.canvas.create_rectangle(250,100,750,635,outline='blue', fill='red')
        self.canvas.create_text(500,130, text= 'Le but du jeu est simple.', font='Arial 30', fill='blue')        
        self.canvas.create_text(500,200, text= 'Trouver les bonnes couleurs', font='Arial 30', fill='blue') 
        self.canvas.create_text(500,250, text= 'et leur ordre', font='Arial 30', fill='blue')  
        self.canvas.create_text(500,320, text= "L'ordinateur définira la suite", font='Arial 30', fill='blue') 
        self.canvas.create_text(500,420, text= 'tu as 10 essais ', font='Arial 30', fill='blue') 
        self.canvas.create_text(500,470, text= 'et 8 choix de couleurs ', font='Arial 30', fill='blue') 
        self.canvas.create_text(500,580, text= 'Good luck! ', font='Arial 30', fill='blue')   
        btn_demonstration= Button(self.canvas, text='EXPLICATION ', command=self.demonstration)
        btn_jeu_window = self.canvas.create_window(650,580, anchor=NW, window=btn_demonstration)
 
 
        self.canvas.bind("<Button-1>",self.demonstration)
 
    def demonstration(self):   
    #explication du jeu
        self.canvas.delete('all')
        self.canvas.create_text(500,40, text='EXPLICATION', font='arial 60', fill='red')
       
        self.canvas.create_rectangle(250,100,750,635,outline='blue', fill='red')
        self.canvas.create_text(500,130, text= 'Les 8 couleurs sont:', font='Arial 30', fill='blue')         
        self.canvas.create_oval(360-15, 170-15, 360+15, 170+15, fill='red')
        self.canvas.create_oval(400-15, 170-15, 400+15, 170+15, fill='yellow')
        self.canvas.create_oval(440-15, 170-15, 440+15, 170+15, fill='blue')
        self.canvas.create_oval(480-15, 170-15, 480+15, 170+15, fill='orange')
        self.canvas.create_oval(520-15, 170-15, 520+15, 170+15, fill='green')
        self.canvas.create_oval(560-15, 170-15, 560+15, 170+15, fill='turquoise')
        self.canvas.create_oval(600-15, 170-15, 600+15, 170+15, fill='violet')
        self.canvas.create_oval(640-15, 170-15, 640+15, 170+15, fill='grey')
       
       
        self.canvas.create_text(500,250, text= 'lorsque la couleur est bonne:', font='Arial 30', fill='blue')  
        self.canvas.create_text(500,300, text= '- et mal placée', font='Arial 30', fill='blue') 
        self.canvas.create_oval(360-15, 350-15, 360+15, 350+15, fill='black')
        self.canvas.create_oval(400-15, 350-15, 400+15, 350+15, fill='white')
        self.canvas.create_oval(440-15, 350-15, 440+15, 350+15, fill='white')
        self.canvas.create_oval(480-15, 350-15, 480+15, 350+15, fill='white')
        
        self.canvas.create_text(500,400, text= '-et bien placée ', font='Arial 30', fill='blue') 
        self.canvas.create_oval(360-15, 450-15, 360+15, 450+15, fill='blue')
        self.canvas.create_oval(400-15, 450-15, 400+15, 450+15, fill='white')
        self.canvas.create_oval(440-15, 450-15, 440+15, 450+15, fill='white')
        self.canvas.create_oval(480-15, 450-15, 480+15, 450+15, fill='white')
        
        self.canvas.create_text(500,530, text= "N'oublis pas, tu as", font='Arial 30', fill='blue') 
        self.canvas.create_text(500,580, text= 'seulement 10 essais!! ', font='Arial 30', fill='blue')   
        btn_jeu= Button(self.canvas, text='go play ', command=self.jeu)
        btn_jeu_window = self.canvas.create_window(670,600, anchor=NW, window=btn_jeu)
 
 
        self.canvas.bind("<Button-1>",self.jeu)    



    def abandonner(self):   
    #quand tu as perdus
        self.canvas.delete('all')
        self.canvas.create_text(500,60, text='TU AS PERDU!', font='arial 70', fill='red')
        self.canvas.create_rectangle(110,155,890,235,outline='blue', fill='red')
        self.canvas.create_text(500,195, text= 'appuie sur le bouton quitter pour quitter', font='Arial 30', fill='blue')
        self.canvas.create_rectangle(110,255,890,335,outline='blue', fill='red')
        self.canvas.create_text(500,295, text= 'appuie sur le bouton ci dessous pour rejouer', font='Arial 30', fill='blue')  
        self.canvas.create_text(500,500, text='REESSAYES', font='arial 70', fill='red')
        btn_rejouer= Button(self.canvas, text='REJOUER', command=self.accueil)
        btn_rejouer_window = self.canvas.create_window(500,360, anchor=NW, window=btn_rejouer)


app = Application()
app.mainloop()

 

Vous aimerez aussi...

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *