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

Tkinter Python Discussion :

Projet de UNO ISN [Python 3.X]


Sujet :

Tkinter Python

  1. #1
    Candidat au Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Avril 2020
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Lot (Midi Pyrénées)

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Avril 2020
    Messages : 7
    Points : 3
    Points
    3
    Par défaut Projet de UNO ISN
    Bonjour, voici notre projet d'ISN, créer un UNO. Cependant, nous voulons, grâce à la fonction pointeur, afficher une main lorsque l'on passe le pointeur sur une carte lorsqu'une carte est 'posable' (dans ce cas elle est dans la liste choixj1) et une croix lorsqu'elle le l'est pas. Cependant, le programme affiche une croix ou une main pour toutes les cartes, tout dépend de la derniere carte...
    Le if dépend de la dernière carte affichée, et donc est valable pour toutes les cartes. Pour tester, on a mis dans choix seulement des cartes vertes, ainsi, si la dernière carte est verte, le programme va afficher une main pour toutes les cartes, sinon il va afficher une croix pour toutes les cartes, même s'il y a des vertes dans le jeu.

    Ci joint le fichier.zip pour avoir accès aux images, sinon voici le programme brut :

    Merci d'avance pour votre aide.

    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
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
     
    from tkinter import *
    from random import *
    from time import *
     
    x = 0
    cartes=["9V","9V","8V","8V","7V","7V","6V","6V","5V","5V","4V","4V","3V","3V","2V","2V","1V","1V","0V"
               ,"9J","9J","8J","8J","7J","7J","6J","6J","5J","5J","4J","4J","3J","3J","2J","2J","1J","1J","0J"
               ,"9R","9R","8R","8R","7R","7R","6R","6R","5R","5R","4R","4R","3R","3R","2R","2R","1R","1R","0R"
               ,"9B","9B","8B","8B","7B","7B","6B","6B","5B","5B","4B","4B","3B","3B","2B","2B","1B","1B","0B"]
     
    joueur1=[]
    joueur2=[]
    couleurs=["R","V","B","J"]
    table = '4B'
    choixj1=["9V","8V","8V","7V","7V","6V","6V","5V","5V","4V","4V","3V","3V","2V","2V","1V","1V","0V"]
     
    distrib=0
    x= randint(0,len(cartes)-1)
    table=cartes[x]
    del cartes[x]
    while distrib<7:
     
        x= randint(0,len(cartes)-1)
        joueur1.append(cartes[x])
        del cartes[x]
     
        x= randint(0,len(cartes)-1)
        joueur2.append(cartes[x])
        del cartes[x]
        distrib=distrib+1
     
    def tourj1():
        choixj1=[]
        global table
        for carte in joueur1:
            if carte[0] == table[0] or carte[1] == table[1]:
                choixj1.append(carte)
        if len(choixj1) == 0:
            piochej(joueur1)
            choixj1 = []
        else:
            print('\nchoix j1', choixj1)
            poser=input("Entrez la valeur de la carte :  ")
            if poser in choixj1:
                table = poser
                print("j1 pose", table)
                choixj1 = []
                cartes.append(table)
                i = joueur1.index(table)
                del joueur1[i]
            else :
                print("Cette carte n'est pas valide")
     
    def tourj2():
        choixj2=[]
        global table
        for carte in joueur2:
            if carte[0] == table[0] or carte[1] == table[1]:
                choixj2.append(carte)
        if len(choixj2) == 0:
            piochej(joueur2)
            choixj2 = []
        else:
            table = choixj2[randint(0, len(choixj2) - 1)]
            print('\nchoix j2', choixj2)
            print("\nj2 pose", table)
            choixj2 = []
            cartes.append(table)
            i = joueur2.index(table)
            del joueur2[i]
     
    def piochej(j):
        x=randint(0,len(cartes)-1)
        j.append(cartes[x])
        print("pioche",cartes[x])
        del cartes[x]
        sleep(1)
     
    def start():
        i = 0
        while len(joueur1) > 0 and len(joueur2) > 0:
            if i == 0:
                print('\nmain j1', joueur1)
                print('main j2', joueur2)
                print('table:', table)
                tourj1()
                #plus_4()
                i = 1
                sleep(0.1)
            else:
                #print('main', joueur2)
                #print('table:', table)
                tourj2()
                #plus_4()
                i = 0
                sleep(0.1)
        if len(joueur1)==0:
            print('joueur 1 gagne')
        elif len(joueur2)==0:
            print('joueur 2 gagne')
     
    def do_print():
        print('test')
     
     
     
    fen=Tk()
     
    can=Canvas(fen, width=1920, height=1080, bg="#209a4d")
    can.pack()
     
    def pointeur(x):
            if x in choixj1 :
                can.tag_bind('toggle_cursor', '<Enter>', lambda e: can.configure(cursor = 'hand2'))
                can.tag_bind('toggle_cursor', '<Leave>', lambda e: can.configure(cursor=''))
            else :
                can.tag_bind('toggle_cursor', '<Enter>', lambda e: can.configure(cursor = 'x_cursor'))
                can.tag_bind('toggle_cursor', '<Leave>', lambda e: can.configure(cursor=''))
     
    if len(joueur1)>=13 :
        carte13j1=PhotoImage(file=joueur1[12]+'.gif')
        can.create_image(700,800,image=carte13j1, tag ='toggle_cursor')
        pointeur(joueur1[12])
    if len(joueur1)>=11 :
        carte11j1=PhotoImage(file=joueur1[10]+'.gif')
        can.create_image(750,800,image=carte11j1, tag ='toggle_cursor')
        pointeur(joueur1[10])
    if len(joueur1)>=9 :
        carte9j1=PhotoImage(file=joueur1[8]+'.gif')
        can.create_image(800,800,image=carte9j1, tag ='toggle_cursor')
        pointeur(joueur1[8])
    if len(joueur1)>=1 :
        carte1j1=PhotoImage(file=joueur1[0]+'.gif')
        can.create_image(850,800,image=carte1j1, tag ='toggle_cursor')
        pointeur(joueur1[0])
    if len(joueur1)>=2 :
        carte2j1=PhotoImage(file=joueur1[1]+'.gif')
        can.create_image(900,800,image=carte2j1, tag ='toggle_cursor')
        pointeur(joueur1[1])
    if len(joueur1)>=3 :
        carte3j1=PhotoImage(file=joueur1[2]+'.gif')
        can.create_image(950,800,image=carte3j1, tag ='toggle_cursor')
        pointeur(joueur1[2])
    if len(joueur1)>=4 :
        carte4j1=PhotoImage(file=joueur1[3]+'.gif')
        can.create_image(1000,800,image=carte4j1, tag ='toggle_cursor')
        pointeur(joueur1[3])
    if len(joueur1)>=5 :
        carte5j1=PhotoImage(file=joueur1[4]+'.gif')
        can.create_image(1050,800,image=carte5j1, tag ='toggle_cursor')
        pointeur(joueur1[4])
    if len(joueur1)>=6 :
        carte6j1=PhotoImage(file=joueur1[5]+'.gif')
        can.create_image(1100,800,image=carte6j1, tag ='toggle_cursor')
        pointeur(joueur1[5])
    if len(joueur1)>=7 :
        carte7j1=PhotoImage(file=joueur1[6]+'.gif')
        can.create_image(1150,800,image=carte7j1, tag ='toggle_cursor')
        pointeur(joueur1[6])
    if len(joueur1)>=8 :
        carte8j1=PhotoImage(file=joueur1[7]+'.gif')
        can.create_image(1200,800,image=carte8j1, tag ='toggle_cursor')
        pointeur(joueur1[7])
    if len(joueur1)>=10 :
        carte10j1=PhotoImage(file=joueur1[9]+'.gif')
        can.create_image(1250,800,image=carte10j1, tag ='toggle_cursor')
        pointeur(joueur1[9])
    if len(joueur1)>=12 :
        carte12j1=PhotoImage(file=joueur1[11]+'.gif')
        can.create_image(1300,800,image=carte12j1, tag ='toggle_cursor')
        pointeur(joueur1[11])
    if len(joueur1)>=14 :
        carte14j1=PhotoImage(file=joueur1[13]+'.gif')
        can.create_image(1350,800,image=carte14j1, tag ='toggle_cursor')
        pointeur(joueur1[13])
     
     
    if len(joueur2)>=13 :
        carte13j2=PhotoImage(file='UNO_back.gif')
        can.create_image(700,250,image=carte13j2)
    if len(joueur2)>=11 :
        carte11j2=PhotoImage(file='UNO_back.gif')
        can.create_image(750,250,image=carte11j2)
    if len(joueur2)>=9 :
        carte9j2=PhotoImage(file='UNO_back.gif')
        can.create_image(800,250,image=carte9j2)
     
    if len(joueur2)>=1 :
        carte1j2=PhotoImage(file='UNO_back.gif')
        can.create_image(850,250,image=carte1j2)
    if len(joueur2)>=2 :
        carte2j2=PhotoImage(file='UNO_back.gif')
        can.create_image(900,250,image=carte2j2)
    if len(joueur2)>=3 :
        carte3j2=PhotoImage(file='UNO_back.gif')
        can.create_image(950,250,image=carte3j2)
    if len(joueur2)>=4 :
        carte4j2=PhotoImage(file='UNO_back.gif')
        can.create_image(1000,250,image=carte4j2)
    if len(joueur2)>=5 :
        carte5j2=PhotoImage(file='UNO_back.gif')
        can.create_image(1050,250,image=carte5j2)
    if len(joueur2)>=6 :
        carte6j2=PhotoImage(file='UNO_back.gif')
        can.create_image(1100,250,image=carte6j2)
    if len(joueur2)>=7 :
        carte7j2=PhotoImage(file='UNO_back.gif')
        can.create_image(1150,250,image=carte7j2)
    if len(joueur2)>=8 :
        carte8j2=PhotoImage(file='UNO_back.gif')
        can.create_image(1200,250,image=carte8j2)
    if len(joueur2)>=10 :
        carte10j2=PhotoImage(file='UNO_back.gif')
        can.create_image(1250,250,image=carte10j2)
    if len(joueur2)>=12 :
        carte12j2=PhotoImage(file='UNO_back.gif')
        can.create_image(1300,250,image=carte12j2)
    if len(joueur2)>=14 :
        carte14j2=PhotoImage(file='UNO_back.gif')
        can.create_image(1350,250,image=carte14j2)
     
     
     
     
    pioche=PhotoImage(file='pioche.gif')
    can.create_image(900,525,image=pioche)
    table=PhotoImage(file=table + '.gif')
    can.create_image(1100,525,image=table)
     
    fen.mainloop()
    Fichiers attachés Fichiers attachés
    • Type de fichier : zip ISN.zip (502,6 Ko, 33 affichages)

  2. #2
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 333
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 333
    Points : 36 853
    Points
    36 853
    Par défaut
    Salut,

    Citation Envoyé par Gabrinity Voir le message
    Cependant, le programme affiche une croix ou une main pour toutes les cartes, tout dépend de la derniere carte...
    Ben oui mais... toutes les cartes que vous avez tagué 'toggle_cursor' réagiront de la même façon.

    Si vous voulez modifier le curseur en fonction du joueur qui "possède" l'item qui est en dessous de la position de la souris... c'est un peu plus compliqué.

    Vous pouvez faire un tag_bind sur l'étiquette "current" mais après, puis agir en fonction du joueur (d'autres tags associés à l'item "current").

    - W

  3. #3
    Candidat au Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Avril 2020
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Lot (Midi Pyrénées)

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Avril 2020
    Messages : 7
    Points : 3
    Points
    3
    Par défaut
    D'accord, mais je débute, donc je n'ai pas tout compris, concrètement, qu'est ce que ça veut dire ?

  4. #4
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 333
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 333
    Points : 36 853
    Points
    36 853
    Par défaut
    Citation Envoyé par Gabrinity Voir le message
    D'accord, mais je débute, donc je n'ai pas tout compris, concrètement, qu'est ce que ça veut dire ?
    Qu'est ce que vous n'avez pas compris?
    Pourquoi votre code ne peut pas marcher?
    Que faire pour que çà fonctionne?

    - W

  5. #5
    Candidat au Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Avril 2020
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Lot (Midi Pyrénées)

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Avril 2020
    Messages : 7
    Points : 3
    Points
    3
    Par défaut
    En effet, je ne comprends pas ce qu'il faut que je modifie pour que le curseur soit indépendant selon les cartes, surtout que j'aimerai par la suite pouvoir récupérer la valeur de la carte sur laquelle j'ai cliqué.
    Je n'ai pas le droit aux classes par ailleurs...

  6. #6
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 333
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 333
    Points : 36 853
    Points
    36 853
    Par défaut
    Salut,

    Je peux juste vous donner un exemple:
    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
    import tkinter as tk
     
    SIZE = 50
    COUNT = 5
    width = SIZE * (COUNT+1)
    canvas = tk.Canvas(width=width, height=width)
     
    offset = SIZE // 2
    for i in range(COUNT):
        x = offset + SIZE * i
        for j in range(COUNT):
            color = ['white', 'grey'][(i+j) % 2]
            y = offset + SIZE*j
            canvas.create_rectangle(x, y, x+30, y+30, activeoutline='red', activewidth=4, fill=color)
     
    def toggle(e):
     
        if e.type == tk.EventType.Leave:
            canvas.configure(cursor='')
        else:
            iid = canvas.find_withtag('current')[-1]
            if canvas.itemcget(iid, 'fill') == 'white':
                canvas.configure(cursor='x_cursor')
            else:
                canvas.configure(cursor='hand2')
     
    canvas.tag_bind('current', '<Enter>', toggle)
    canvas.tag_bind('current', '<Leave>', toggle)
     
    canvas.pack()
    tk.mainloop()
    Ici çà modifie le curseur suivant la couleur de la carte sur laquelle on passe.

    - W

  7. #7
    Candidat au Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Avril 2020
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Lot (Midi Pyrénées)

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Avril 2020
    Messages : 7
    Points : 3
    Points
    3
    Par défaut
    D'accord, alors il faut que je fasse la même chose mais avec un tag correspondant à la valeur de la carte ?

  8. #8
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 333
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 333
    Points : 36 853
    Points
    36 853
    Par défaut
    Citation Envoyé par Gabrinity Voir le message
    D'accord, alors il faut que je fasse la même chose mais avec un tag correspondant à la valeur de la carte ?
    Par exemple.
    Essayez de comprendre comment mon code fonctionne et d'en tirer profit pour adapter votre code

    - W

  9. #9
    Candidat au Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Avril 2020
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Lot (Midi Pyrénées)

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Avril 2020
    Messages : 7
    Points : 3
    Points
    3
    Par défaut
    Merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Projet arduino uno ( Température et affichage serre)
    Par jmud127 dans le forum Arduino
    Réponses: 6
    Dernier message: 16/09/2018, 10h19
  2. Projet de UNO
    Par Arnoanais dans le forum Tkinter
    Réponses: 1
    Dernier message: 22/04/2018, 17h24
  3. Projet javascript/html ISN
    Par Feist dans le forum Général JavaScript
    Réponses: 27
    Dernier message: 19/05/2015, 13h18
  4. Projet spécialité info (ISN)
    Par rubisom dans le forum Projets
    Réponses: 7
    Dernier message: 06/03/2015, 00h26
  5. Projet golf 2D ISN
    Par McdeluxPro402 dans le forum Programmation multimédia/Jeux
    Réponses: 5
    Dernier message: 26/05/2014, 09h56

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