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

Programmation multimédia/Jeux Python Discussion :

Programmation des 24h du Mans


Sujet :

Programmation multimédia/Jeux Python

  1. #21
    Membre habitué
    Homme Profil pro
    Prépa BCPST
    Inscrit en
    Février 2021
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Prépa BCPST

    Informations forums :
    Inscription : Février 2021
    Messages : 13
    Par défaut
    D'accord merci !

    Je suis désolé de vous demander cela comme ca mais je dois absolument rendre ce programme demain pour mon concours. Avec mon collègue, on a fait ceux-ci (joint ci-desous) sauf que j'ai le soucis que la fonction mouvement que j'ai programmé ne fonctionne pas. Serait-il possible d'avoir une correction de la faute s'il vous plaît...

    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
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
     
    from tkinter import *
    import math
    import random as rd
    from PIL import Image, ImageTk
    import os
     
    def combinaison_lineaire(A,B,u,v):
        return [A[0]*u+B[0]*v,A[1]*u+B[1]*v]
     
    def interpolation_lineaire(A,B,t):
        return combinaison_lineaire(A,B,t,1-t)
     
    def vecteur_unitaire(P1,P2):
        Ux = P2[0]-P1[0]
        Uy = P2[1]-P1[1]
        norme = math.sqrt(Ux*Ux+Uy*Uy)
        if norme!=0:
            return [Ux/norme,Uy/norme]
        else:
            return False
     
    def test_alignement_4pts(points,epsilon):
        U1 = vecteur_unitaire(points[0],points[1])
        U2 = vecteur_unitaire(points[1],points[2])
        U3 = vecteur_unitaire(points[2],points[3])
        if U2:
            x = 2.0-(U1[0]*U2[0]+U1[1]*U2[1]+U2[0]*U3[0]+U2[1]*U3[1])
        else:
            x = 1.0-(U1[0]*U3[0]+U1[1]*U3[1])
        if abs(x) < epsilon:
            return True
        else:
            return False
     
    def division_courbe_bezier_3(points_control):
        P01 = interpolation_lineaire(points_control[0],points_control[1],0.5)
        P12 = interpolation_lineaire(points_control[1],points_control[2],0.5)
        P23 = interpolation_lineaire(points_control[2],points_control[3],0.5)
        P01_12 = interpolation_lineaire(P01,P12,0.5)
        P12_23 = interpolation_lineaire(P12,P23,0.5)
        Q = interpolation_lineaire(P01_12,P12_23,0.5)
        return ([points_control[0],P01,P01_12,Q],[Q,P12_23,P23,points_control[3]])
     
    def courbe_bezier_3_recursif(points_control,epsilon,pile_points_courbe):
        if test_alignement_4pts(points_control,epsilon):
            pile_points_courbe.append(points_control[0])
        else:
            (points_1,points_2) = division_courbe_bezier_3(points_control)
            courbe_bezier_3_recursif(points_1,epsilon,pile_points_courbe)
            courbe_bezier_3_recursif(points_2,epsilon,pile_points_courbe)
     
    class Courbe:
        def __init__(self,P0,P1,P2,P3,epsilon):
            self.points_courbe = []
            self.epsilon = epsilon
            self.bezier_3_recursif_init([P0,P1,P2,P3])
            self.points_control = [P0,P1,P2,P3]
     
        def bezier_3_recursif_init(self,points_control):
            courbe_bezier_3_recursif(points_control,self.epsilon,self.points_courbe)
            self.P2 = points_control[2]
            self.P3 = points_control[3]
     
        def ajouter(self,P2,P3):
            P0 = self.P3
            P1 = [P0[0]+P0[0]-self.P2[0],P0[1]+P0[1]-self.P2[1]]
            self.bezier_3_recursif_init([P0,P1,P2,P3])
            self.points_control.append(P1)
            self.points_control.append(P2)
            self.points_control.append(P3)
            self.dernier_point = P3
     
        def liste_points(self):
            self.points_courbe.append(self.dernier_point)
            return self.points_courbe
     
        def liste_points_control(self):
            self.points_control.append(self.dernier_point)
            return self.points_control
     
    def CalculeVitesse(L):
        n = len(L)
        V = []
        T = []
        for i in range(0,n):
            x,y = L[i]
            xp, yp = L[i-1]
            xs, ys = L[(i+1)//n]
            dG = ((x-xp)**2 + (y - yp)**2)**.5
            dD = ((x-xs)**2 + (y - ys)**2)**.5
            v = (dG+dD)/2
            V.append(v)
            T.append(dD/v)
        V.append(50)
        return V, T
     
    courbe = Courbe([121,276],[142,246],[169,212],[190,182],5e-3)
    courbe.ajouter([269,146],[339,142])
    courbe.ajouter([460,161],[491,154])
    courbe.ajouter([514,151],[535,149])
    courbe.ajouter([562,142],[571,132])
    courbe.ajouter([605,112],[637,130])
    courbe.ajouter([684,137],[713,96])
    courbe.ajouter([782,114],[791,110])
    courbe.ajouter([810,140],[815,145])
    courbe.ajouter([600,440],[600,445])
    courbe.ajouter([300,400],[300,405])
    courbe.ajouter([121,275],[121,276])
     
    points = courbe.liste_points()
     
    class Menu() :
     
        def __init__(self) :
            self.f = Tk()
     
            self.f.attributes('-fullscreen', True)
            self.f.bind('<Escape>',lambda e: self.f.destroy())
     
            w, h = self.f.winfo_screenwidth(), self.f.winfo_screenheight()
     
            image = Image.open(r"C:\Users\user\Documents\cours\informatique\prog\proj_info\logo2.png")
            image = image.resize((w, h))
            photo = ImageTk.PhotoImage(image)
     
            can = Canvas(self.f, highlightthickness=0)
            can.create_image(0, 0, anchor='nw', image=photo)
     
            l=Label(can, text = 'Bienvenue dans Le Mans, Le jeu !', fg = '#FFFFFF', bg = '#01193b' ).place(x = 350, y = 450)
            l0=Label(can, text = "Ceci est un jeu de simulation visant à recréer différentes années de la célèbre course des 24h du Mans.\nVous allez être projeté au coeur de l'une de ces années avec pour objectif de réussir à gagner.\nPlusieurs paramètres seront pris en compte pour cela.\nNous vous laissons découvrir tout cela... Bon jeu !", fg = '#FFFFFF', bg = '#01193b').place(x = 170, y = 475)
     
            self.L1=points
            self.i=-1
            self.d=True
     
            b0 = Button(can, width = '10', text = 'Suite !', fg = '#FFFFFF', bg = '#01193b', command=self.s).place(x = 400, y = 550)
            bEnd = Button(can, text = 'Quitter', command = self.destroyf).place(x = 750, y = 825)
     
            can.pack(fill='both', expand=1)
     
            self.f.mainloop()
     
     
     
        def Ecuries(self) :
            self.f1 = Tk()
     
            self.f1.attributes('-fullscreen', True)
            self.f1.bind('<Escape>',lambda e: self.f1.destroy())
     
            w, h = self.f1.winfo_screenwidth(), self.f1.winfo_screenheight()
     
            image = Image.open(r"C:\Users\user\Documents\cours\informatique\prog\proj_info\logo2.png")
            image = image.resize((w, h))
            photo = ImageTk.PhotoImage(image)
     
            can = Canvas(self.f1, highlightthickness=0)
            can.create_image(0, 0, anchor='nw', image=photo)
     
            l1 = Label(self.f1, text = 'Veuillez choisir votre écurie.', fg = '#FFFFFF', bg = '#01193b').place(x = 400, y = 400)
            l2 = Label(self.f1, text = 'Attention, chaque écurie possède ses propres caractéristiques !', bg = '#01193b', fg = '#B40431').place(x = 300, y = 450)
            l3 = Label(self.f1, text = 'Bon jeu !', fg = '#FFFFFF', bg = '#01193b').place(x = 440, y = 500)
     
            b1 = Button(self.f1, width = '10', text = "Ferrari", fg = '#FFFFFF', bg = '#01193b', command=self.s1).place(x = 1300, y = 450)
            b2 = Button(self.f1, width = '10', text = 'Alpine', fg = '#FFFFFF', bg = '#01193b', command=self.s1).place(x = 1300, y = 500)
            b3 = Button(self.f1, width = '10', text = 'Porsche', fg = '#FFFFFF', bg = '#01193b', command=self.s1).place(x = 1300, y = 300)
            b4 = Button(self.f1, width = '10', text = 'Ford', fg = '#FFFFFF', bg = '#01193b', command=self.s1).place(x = 1300, y = 350)
            b5 = Button(self.f1, width = '10', text = 'Shelby', fg = '#FFFFFF', bg = '#01193b', command=self.s1).place(x = 1300, y = 400)
            bEnd = Button(self.f1, text = 'Quitter', command = self.destroyf1).place(x = 748, y = 825)
     
            can.pack(fill='both', expand=1)
     
            self.f1.mainloop()
     
        def Boost(self) :
            self.f2 = Tk()
     
            self.f2.attributes('-fullscreen', True)
            self.f2.bind('<Escape>',lambda e: self.f2.destroy())
     
            w, h = self.f2.winfo_screenwidth(), self.f2.winfo_screenheight()
     
            image = Image.open(r"C:\Users\user\Documents\cours\informatique\prog\proj_info\logo2.png")
            image = image.resize((w, h))
            photo = ImageTk.PhotoImage(image)
     
            can = Canvas(self.f2, highlightthickness = 0)
            can.create_image(0, 0, anchor='nw', image = photo)
     
            l0 = Label(self.f2, text = "Ce menu vous permet de choisir les différents composants afin d'optimiser au mieux votre voiture.\nDes pneus soft permettrons un meilleur démarrage mais s'userons plus vite.\nLes spoilers vous permettent suivant leur classe de meilleurs temps au tour. ", fg = '#FFFFFF', bg = '#01193b').place(x = 200, y = 475)
     
            l1 = Label(self.f2, text = 'Les pneus', fg = '#FFFFFF', bg = '#01193b').place(x = 1300, y = 250)
            c1 = Checkbutton(self.f2, text = 'Soft tires', fg = '#FFFFFF', bg = '#01193b').place(x = 1300, y = 300)
            c2 = Checkbutton(self.f2, text = 'Medium tires', fg = '#FFFFFF', bg = '#01193b').place(x = 1300, y = 350)
            c3 = Checkbutton(self.f2, text = 'Wet time tires', fg = '#FFFFFF', bg = '#01193b').place(x = 1300, y = 400)
     
            l2 = Label(self.f2, text = 'Les spoilers', fg = '#FFFFFF', bg = '#01193b').place(x = 1300, y = 450)
            c4 = Checkbutton(self.f2, text = 'Spoiler basique', fg = '#FFFFFF', bg = '#01193b').place(x = 1300, y = 500)
            c5 = Checkbutton(self.f2, text = 'Spoiler élite', fg = '#FFFFFF', bg = '#01193b').place(x = 1300, y = 550)
     
            l3 = Label(self.f2, text = 'Puissance moteur', fg = '#FFFFFF', bg = '#01193b').place(x = 1300, y = 600)
     
            b1 = Button(self.f2, width = '10', text = 'Suite !', fg = '#FFFFFF', bg = '#01193b', command=self.s2).place(x = 1310, y = 700)
            bEnd = Button(self.f2, text = 'Quitter', command = self.destroyf2).place(x = 750, y = 825)
     
            can.pack(fill='both', expand=1)
     
            self.f2.mainloop()
     
        def circuit(self) :
            self.f3 = Tk()
     
            self.f3.attributes('-fullscreen', True)
            self.f3.bind('<Escape>',lambda e: self.f3.destroy())
     
            w, h = self.f3.winfo_screenwidth(), self.f3.winfo_screenheight()
     
            image = Image.open(r"C:\Users\user\Documents\cours\informatique\prog\proj_info\circuit.png")
            image = image.resize((w, h))
            photo = ImageTk.PhotoImage(image)
     
            can3 = Canvas(self.f3, highlightthickness = 0)
            can3.create_image(0, 0, anchor='nw', image = photo)
     
            l1 = Label(self.f3, width = 20, text = 'Vos options en jeu:').place(x = 1350, y = 200)
            l2 = Label(self.f3, width = 20 , text = 'Retour au stand').place(x = 1350, y = 250)
            l3 = Label(self.f3, width = 20, text = 'Etat des pneus').place(x = 1350, y = 450)
            l4 = Label(self.f3, width = 20, text = "Jauge d'essence").place(x = 1350, y = 550)
     
            b1 = Button(self.f3, width = 20, text = "Plein d'essence", bg = '#A4A4A4').place(x = 1350, y = 275)
            b2 = Button(self.f3, width = 20, text = "Changement pour pneu\nmedium", bg = '#A4A4A4').place(x = 1350, y = 305)
            b3 = Button(self.f3, width = 20, text = "Changement pour pneu\nmou", bg = '#A4A4A4').place(x = 1350, y = 345)
            b4 = Button(self.f3, width = 20, text = "Changement pour pneu\npluie", bg = '#A4A4A4').place(x = 1350, y = 385)
            b5 = Button(self.f3, width = 20, text = "start", bg = '#A4A4A4', command=self.move).place(x = 1350, y = 725)
            b6 = Button(self.f3, width = 20, text = "arrêt", bg = '#A4A4A4', command=self.stop).place(x = 1350, y = 755)
            b7 = Button(self.f3, width = 20, text = "mise en grille", bg = '#A4A4A4', command=self.miseengrille).place(x = 1350, y = 785)
            bEnd = Button(self.f3, text ='Quitter', command = self.destroyf3).place(x = 750, y = 825)
     
            can3.pack(fill='both', expand=1)
     
     
     
     
            self.f3.mainloop()
     
        def index(self):
            self.i=self.i+1
            return self.i
     
        def miseengrille(self):
            o=self.L1[1]
            self.x=o[0]
            self.y=o[1]
            self.point = self.can3.create_oval(self.x, self.y,self.x+5,self.y+5,width=20, fill="black")
     
        def move(self):
            m=len(self.L1)
            i=self.index()
            if self.d==True: 
                if i<m:
                    o=self.L1[i]
                    self.x=o[0]
                    self.y=o[1]   
                elif i>m:
                    self.i=-1
            self.can3.coords(self.point, self.x, self.y, self.x+5,self.y+5)
            self.after(40, self.move)
     
        def stop(self):
            self.d=False
            o=self.L1[1]
            self.x=o[0]
            self.y=o[1] 
     
        def s(self) :
            self.f.destroy()
            self.Ecuries()
     
        def s1(self) :
            self.f1.destroy()
            self.Boost()
     
        def s2(self) :
            self.f2.destroy()
            self.circuit()
     
        def destroyf(self) :
            self.f.destroy()
     
        def destroyf1(self) :
            self.f1.destroy()
     
        def destroyf2(self) :
            self.f2.destroy()
     
        def destroyf3(self) :
            self.f3.destroy()
     
     
    start = Menu()

  2. #22
    Membre habitué
    Homme Profil pro
    Prépa BCPST
    Inscrit en
    Février 2021
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Prépa BCPST

    Informations forums :
    Inscription : Février 2021
    Messages : 13
    Par défaut
    Ci-joint, les 2 images
    Nom : logo2.png
Affichages : 115
Taille : 72,8 Ko
    Nom : circuit.png
Affichages : 121
Taille : 14,4 Ko

  3. #23
    Expert éminent
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 790
    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 790
    Par défaut
    Salut,

    Citation Envoyé par TiT_Flo Voir le message
    Serait-il possible d'avoir une correction de la faute s'il vous plaît...
    Je ne vais pas inspecter votre code et y ajouter des "print" pour comprendre ce que çà essaie de faire (la logique que vous avez suivi) et pourquoi çà ne le fait pas: je n'ai juste pas le temps (et en plus c'est votre boulot).

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

Discussions similaires

  1. Exécuter un programme des que le poste est allumé
    Par edzodzinam dans le forum Autres Logiciels
    Réponses: 5
    Dernier message: 08/02/2006, 04h08
  2. [DBA] Programmer des jobs
    Par pzou dans le forum Oracle
    Réponses: 14
    Dernier message: 26/01/2006, 16h43
  3. [VBA-E] Toggle button: programmation des actions
    Par micknic dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 30/10/2005, 19h28
  4. Programmation des ports // et/ou séries
    Par sami_c dans le forum Windows
    Réponses: 1
    Dernier message: 17/09/2005, 13h15
  5. Programmer des threads
    Par haypo dans le forum C
    Réponses: 6
    Dernier message: 02/07/2002, 13h53

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