IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

aide compréhension lignes.


Sujet :

Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Futur Membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2013
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2013
    Messages : 4
    Par défaut aide compréhension lignes.
    Bonsoir,
    J'aimerais que vous m'expliquiez deux trois choses que je ne comprends pas vraiment dans ce qui suit:


    #DICTIONNAIRE DE RECONNAISSANCE

    self.dictionnaire = {}
    v = 0
    for y in range(10, 390, 55):
    for x in range(10, 437, 63):
    self.dictionnaire[(x, y, x + 50, y + 50)] = v
    v += 1
    self.coordscentres.append((x + 25, y + 25))
    (Je ne comprends pas comment cette bibliothèque fonctionne)

    #METHODE DEFINISSANT UNE PARTIE GAGNÉE

    def win(self, qui, p, d):
    (J'ignore ce qu'est le "qui")

    Merci d'avance...

  2. #2
    Expert confirmé
    Avatar de fred1599
    Homme Profil pro
    Lead Dev Python
    Inscrit en
    Juillet 2006
    Messages
    4 062
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Lead Dev Python
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Juillet 2006
    Messages : 4 062
    Par défaut
    Il faudrait mettre cela dans des balises code (bouton #) afin de voir l'indentation (très important en python).

    Pourquoi ne pas mettre des print pour voir ce qui se passe?

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2013
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2013
    Messages : 4
    Par défaut
    Je te donne le programme complet, ce sera plus simple à comprendre:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    # -*- coding: utf-8 -*-
    
        #APPEL DU MODULE TKINTER
    
    from Tkinter import *
    
        #INSTANCIATION DE L'OBJET CANVAS PAR LA CLASSE CAN
    
    class Can(Canvas):
    
    
        def __init__(self):
    
                #ARGUMENTS VARIABLES (GAMEPLAY)
    
            self.cases      = [] #CASES DEJA COLORIEES   
            self.listebordeau = [] #LISTE DES CASES BORDEAUX
            self.listeturquoise = [] #LISTE DES CASES TURQUOISES
            self.running    = 1  #PARTIE EN COURS
            self.couleur    = ["firebrick", "light sea green"]
            self.color      = ["firebrick", "light sea green"]
    
                #ARGUMENTS D'INTERFACE (GUI)
    
            self.clair      = "grey"
            self.fonce      = "black"
            self.police    = "Neuropol 10"
            self.police1    = "Neuropol 14 bold"
            self.can        = Canvas.__init__(self, width =446, height = 430, bg=self.fonce, bd=0)
            self.grid(row=1, columnspan=5)
            self.textcolor  = "black"
            self.textcolor1  = "light sea green"
            self.textcolor2  = "firebrick"
    
                #COULEUR LIEE A CHAQUE DES JOUEURS
    
            self.joueur = 1
            self.create_text(10, 400, text ="JOUEUR  1", anchor = NW, fill = self.textcolor1, font= self.police1)
            self.create_text(10, 412, text ="JOUEUR 2", anchor = NW, fill = self.textcolor2, font= self.police1)
    
                #BOUTON RECOMMENCER
    
            self.create_rectangle(335,400,440,425,fill=self.clair)
            self.create_text(340, 405, text =" RECOMMENCER", anchor = NW, fill = self.textcolor, font= self.police)
    
                #CASES
    
            self.rectangle = []
            for y in range(10, 390, 55):
                for x in range(10, 437, 63):
                    self.rectangle.append(self.create_rectangle(x, y, x + 50, y + 50 , fill= "light grey"))
    
                #ASSIGNATION DE L'EVENEMENT LIE AU CLICK GAUCHE DE LA SOURIS
    
            self.bind("<Button-1>", self.click)
    
                #ARGUMENT ASSIGNANT LES COORDONNEES DES CASES AUX CENTRES DE CELLES CI
    
            self.coordscentres = []
    
                #DICTIONNAIRE DE RECONNAISSANCE
    
            self.dictionnaire = {}
            v = 0
            for y in range(10, 390, 55):
                for x in range(10, 437, 63):
                    self.dictionnaire[(x, y, x + 50, y + 50)] = v
                    v += 1
                    self.coordscentres.append((x + 25, y + 25))
                    
                #LORS D'UN CLICK
                    
                    #RECOMMENCER
    
        def click(self,event):
            if 330 < event.x and 400 < event.y and event.x < 420 and event.y < 425:
                self.new()
    
                    #COLORIER UNE CASE
    
            else :
                if self.running != 0:
                    for (w, x, y, z) in self.dictionnaire:
                        if event.x > (w, x, y, z)[0] and event.y >(w, x, y, z)[1] and event.x < (w, x, y, z)[2] and event.y < (w, x, y, z)[3]:
                            self.colorier(self.dictionnaire[(w, x, y, z)])
    
                #METHODE PERMETTANT LA COLORATION D'UNE CASE
    
        def colorier(self, n, nb=0):
    
                    #UNE CASE DEJA COLORIEE RESTE TELLE QUELLE
            
            if n in self.cases : return
    
                    #ON COLORIE LA CASE LA PLUS BASSE
    
            if n + 7 not in self.cases and n + 7 < 49:
                self.colorier(n+7)
    
                    #SINON ON COLORIE CELLE CI
    
            else:
    
                self.itemconfigure(self.rectangle[n], fill = self.color[self.joueur])
                self.cases.append(n)
                self.color[self.joueur] == 'firebrick' and self.listebordeau.append(n) or self.listeturquoise.append(n)
                self.listeturquoise = [case for case in self.listeturquoise if case not in self.listebordeau]
                self.verif(n)
    
                #ALTERNANCE DE JOUEUR
    
                self.joueur = [0,1][[0,1].index(self.joueur)-1]
    
                #VERIFICATION D'ALIGNEMENT
                   
        def verif(self, n):
    
            if self.running == 0 : return
    
                    #D'ABORD POUR LES JETONS BORDEAUX
    
                        #A LA VERTICALE
    
            if n in self.listebordeau and n+7  in self.listebordeau and n+14  in self.listebordeau and n+21 in self.listebordeau:                                                                                           
                liste=[n, n+7, n+14, n+21] 
                if self.gagnantes(liste) : self.win("firebrick", liste[0],liste[3])
                return
    
                        #A L'HORIZONTALE ET EN DIAGONALE
    
            for x in (1,-6,8):
            
                if n in self.listebordeau and n+x  in self.listebordeau and n+x*2  in self.listebordeau and n+x*3 in self.listebordeau:
                    liste=[n, n+x, n+x*2, n+x*3]
                    if self.gagnantes(liste) : self.win("firebrick", liste[0],liste[3])
                    return
                
            for x in (-1,6,-8):
                
                if n in self.listebordeau and n+x  in self.listebordeau and n+x*2  in self.listebordeau and n+x*3 in self.listebordeau:
                    liste=[n, n+x, n+x*2, n+x*3]
                    if self.gagnantes(liste) : self.win("firebrick", liste[0],liste[3])
                    return
            
                
    
                    #PUIS POUR LES JETONS TURQUOISES
    
                        #A LA VERTICALE
    
            if n in self.listeturquoise and n+7 in self.listeturquoise and n+14 in self.listeturquoise and n+21 in self.listeturquoise:
                liste=[n, n+7, n+14, n+21]
                if self.gagnantes(liste) : self.win("light sea green", liste[0],liste[3])
                return
    
                        #A L'HORIZONTALE ET EN DIAGONALE
            
            for x in (1,-6,8):
            
                if n in self.listeturquoise and n+x  in self.listeturquoise and n+x*2  in self.listeturquoise and n+x*3 in self.listeturquoise:
                    liste=[n, n+x, n+x*2, n+x*3] 
                    if self.gagnantes(liste) : self.win("light sea green", liste[0],liste[3])
                    return
    
            for x in (-1,6,-8):
                
                if n in self.listeturquoise and n+x  in self.listeturquoise and n+x*2  in self.listeturquoise and n+x*3 in self.listeturquoise:
                    liste=[n, n+x, n+x*2, n+x*3]
                    if self.gagnantes(liste) : self.win("light sea green", liste[0],liste[3])
                    return
    
                #METHODE DEFINISSANT UNE PARTIE GAGNÉE
    
        def win(self, qui, p, d):
    
                #ON TRACE UNE LIGNE LORSQUE QUATRE JETONS SONT ALIGNES
    
            self.create_line(self.coordscentres[p][0], self.coordscentres[p][1],
                             self.coordscentres[d][0], self.coordscentres[d][1],
                             fill="goldenrod2", width="7")
    
                #METHODE AJOUTANT LES JETONS GAGNANTS DANS UNE LISTE
    
        def gagnantes(self, liste=[]):
    
            return 1
        
                #METHODE PERMETTANT DE RECOMMENCER                          
    
        def new(self):
    
                #ARGUMENTS DE LANCEMENT DU JEU
    
            self.destroy()
            self.__init__()
            
    if __name__ ==    "__main__" :
        fen = Tk()
        fen.title("Cyberpuissance 4 project bac")
        fen.config(bg="grey")
        lecan = Can()
        fen.mainloop()

  4. #4
    Expert confirmé
    Avatar de fred1599
    Homme Profil pro
    Lead Dev Python
    Inscrit en
    Juillet 2006
    Messages
    4 062
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Lead Dev Python
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Juillet 2006
    Messages : 4 062
    Par défaut
    la variable qui semble être une couleur exemple: "goldenrod2"

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2013
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2013
    Messages : 4
    Par défaut
    Oui, cela pourrait se tenir puisque sans le "qui", j'ai un message d'erreur lorsque 4 jetons sont alignés (il refusent d'afficher la barre marquant l'alignement). Mais la question est, qu'est ce qui nous permet d'affirmer qu'il s'agit d'une variable liée à la couleur goldenrod2?

  6. #6
    Membre Expert Avatar de PauseKawa
    Homme Profil pro
    Technicien Help Desk, maintenance, réseau, système et +
    Inscrit en
    Juin 2006
    Messages
    2 725
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Technicien Help Desk, maintenance, réseau, système et +
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2006
    Messages : 2 725
    Par défaut
    L'appel de la fonction.

    Vous avez votre fonction win ici
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
        def win(self, qui, p, d):
    
                #ON TRACE UNE LIGNE LORSQUE QUATRE JETONS SONT ALIGNES
    
            self.create_line(self.coordscentres[p][0], self.coordscentres[p][1],
                             self.coordscentres[d][0], self.coordscentres[d][1],
                             fill="goldenrod2", width="7")
    Comme vous le remarquez 'qui' n'est pas utilisé.
    En voici un appel
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    self.win("light sea green", liste[0],liste[3])
    Comme vous le constatez la variable qui porte le nom 'qui' dans votre fonction est ici une couleur.
    La seule couleur dans la fonction étant celle de fill vous pouvez écrire
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
        def win(self, qui, p, d):
    
                #ON TRACE UNE LIGNE LORSQUE QUATRE JETONS SONT ALIGNES
    
            self.create_line(self.coordscentres[p][0], self.coordscentres[p][1],
                             self.coordscentres[d][0], self.coordscentres[d][1],
                             fill=qui, width="7")
    @+

Discussions similaires

  1. Aide en ligne pour un formulaire
    Par Michel DELAVAL dans le forum Access
    Réponses: 13
    Dernier message: 16/08/2006, 14h03
  2. [Free Pascal] Aide en ligne
    Par Gnux dans le forum Free Pascal
    Réponses: 1
    Dernier message: 27/01/2006, 12h30
  3. problèmes aide en ligne Delphi 2005
    Par philippe.vernhes dans le forum Delphi .NET
    Réponses: 4
    Dernier message: 25/10/2005, 19h35
  4. comment activer l'aide en ligne
    Par saibe dans le forum Eclipse Java
    Réponses: 2
    Dernier message: 11/01/2005, 14h23
  5. Aide en ligne
    Par étoile dans le forum Composants VCL
    Réponses: 2
    Dernier message: 07/08/2002, 14h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo