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

C Discussion :

Conversion Python en C


Sujet :

C

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2018
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Lot et Garonne (Aquitaine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2018
    Messages : 1
    Par défaut Conversion Python en C
    Bonjour, je voudrais convertir le code qui suit en C mais je bloque vraiment.
    Pouvez-vous m'aider ? Même si vous ne convertissez que quelques fonctions, je prends. Merci

    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
     
    state='init'
     
     
    def draw_score(score):
        global objectif
        draw_rectangle(create_rectangle((2*w,0),2*w,0.8*w,(0,0,0)))
        draw_rectangle(create_rectangle((w+30,w-10),(150*score)/objectif,w//5,(0,200,0)))
        draw_text(create_text(str(score)+'/'+str(objectif),(4*w,0.1*w),(150,150,150),0.4*w,'end'))
        return
     
     
    def arret():
        global user_state
        user_state='GAME'
        return
     
    def combinaison(x,y):
        global listsqr,score,w
        waitlist=[]
        c = listsqr[x][y]
        if y!= 0:
            if c==listsqr[x][y-1]:
                waitlist = waitlist+[(x,y-1)]
                if y>1:
                    if c==listsqr[x][y-2]:
                        waitlist=waitlist + [(x,y-2)]
                if y!=0:
                    if c==listsqr[x-1][y-1]:
                        waitlst=waitlist+[(x-1,y-1)]
                if x!=4:
                    if c==listsqr[x+1][y-1]:
                        waitlist=waitlist+[(x+1,y-1)]
        if y!= 6:
            if c==listsqr[x][y+1]:
                waitlist = waitlist+[(x,y+1)]
                if y<5:
                    if c==listsqr[x][y+2]:
                        waitlist=waitlist + [(x,y+2)]
                if x!=0:
                    if c==listsqr[x-1][y+1]:
                        waitlst=waitlist+[(x-1,y+1)]
                if x!=4:
                    if c==listsqr[x+1][y+1]:
                        waitlist=waitlist+[(x+1,y+1)]
        if x!= 0:
            if c==listsqr[x-1][y]:
                waitlist = waitlist+[(x-1,y)]
                if x>1:
                    if c==listsqr[x-2][y]:
                        waitlist=waitlist + [(x-2,y)]
                if y!=0:
                    if c==listsqr[x-1][y-1]:
                        waitlst=waitlist+[(x-1,y-1)]
                if y!=6:
                    if c==listsqr[x-1][y+1]:
                        waitlist=waitlist+[(x-1,y+1)]
        if x!= 4:
            if c==listsqr[x+1][y]:
                waitlist = waitlist+[(x+1,y)]
                if x<3:
                    if c==listsqr[x+2][y]:
                        waitlist=waitlist + [(x+2,y)]
                if y!=6:
                    if c==listsqr[x+1][y+1]:
                        waitlst=waitlist+[(x+1,y+1)]
                if y!=0:
                    if c==listsqr[x+1][y-1]:
                        waitlist=waitlist+[(x+1,y-1)]
        if len(waitlist)>1:
            score = score + len(waitlist)
            draw_score(score)
            for i in waitlist:
                listsqr[i[0]][i[1]]=0
                draw_rectangle(create_rectangle((w*i[0],w*(1+i[1])),w,w,(255,255,255)))
        return
     
    def draw_scene():
        R1=create_rectangle((0,0),250,50,(11, 22, 22))
        draw_rectangle(R1)
        R2=create_rectangle((0,50),250,350,(255,255,255))
        draw_rectangle(R2)
        line1 = create_line( (140,22), (170, 22), (220,220,220), 5)
        draw_line(line1)
        line2=create_line((210,22), (240,22) , (220,220,220),5)
        draw_line(line2)
     
    def square(x,y):
        global random,listsqr,sqr_x,sqr_y,w,listcolor
        draw_rectangle(create_rectangle((w*sqr_x,w*(1+sqr_y)),w,w,listcolor[0]))
        listcolor[0]=listcolor[1]
        listcolor[1]=listcolor[2]
        listcolor[2]=listcolor[3]
        listcolor[3]=random[randrange(0,4)]
        draw_rectangle(create_rectangle((w*x,w*(y+1)),w,w,listcolor[0]))
        draw_rectangle(create_rectangle((0.2*w,0.2*w),0.4*w,0.4*w,listcolor[1]))
        draw_rectangle(create_rectangle((0.8*w,0.2*w),0.4*w,0.4*w,listcolor[2]))
        draw_rectangle(create_rectangle((1.4*w,0.2*w),0.4*w,0.4*w,listcolor[3]))
        draw_rectangle(create_rectangle((w*(x+0.25),w*(1.25+y)),0.5*w,0.5*w,(250,250,250)))
        listsqr[x][y]=listcolor[0]
        sqr_x = x
        sqr_y = y
        combinaison(sqr_x,sqr_y)
        return
     
    def draw():
        global state, user_state,score,listsqr,listcolor,sqr_x,sqr_y,w,random,objectif
        if state=='init':
            w=50
            initialize(5*w,8*w,"Folt: The game")
            random=[(255,0,0),(0,255,0),(0,0,255),(255,255,0)]
            state ='HOME'
        if state=='HOME':
            fill_window((255,255,255))
            draw_text(create_text("Folt: The game",(125,100),(200,0,100),30,'middle'))
            draw_text(create_text("press enter to start",(125,350),(50,50,50),20,'middle'))
            if is_key_pressed(K_RETURN):
                state='INITGAME'
        if state=='HOME':
            fill_window((255,255,255))
            R1=create_rectangle((30,50),190,200,(176, 242, 182))
            draw_rectangle(R1)
            R2=create_rectangle((80,80),90,40,(255,0,0))
            draw_rectangle(R2)
            R3=create_rectangle((80,120),40,100,(11, 22, 22))
            draw_rectangle(R3)
            R4=create_rectangle((120,140),50,40,(49, 140, 231))
            draw_rectangle(R4)
            R5=create_rectangle((30,270),190,30,(11, 22, 22))
            draw_rectangle(R5)
            R6=create_rectangle((30,310),190,30,(11, 22, 22))
            draw_rectangle(R6)
            draw_text(create_text("JOUER:G",(125,275),(255,255,255),15,'middle'))
            draw_text(create_text("TOUCHES:T",(125,315),(255,255,255),15,'middle'))
            if is_key_pressed(K_g):
                state='INITGAME'
        if state=='INITGAME':
            fill_window((255,255,255))
            draw_scene()
            objectif = randrange(15,26)
            score=0
            draw_score(score)
            listsqr=[[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]]
            listcolor=[(255,255,255),random[randrange(0,4)],random[randrange(0,4)],random[randrange(0,4)]]
            sqr_x =0
            sqr_y= 0
            square(2,3)
            state='GAME'
            user_state = 'GAME'
        if state=='GAME':
            if score >= objectif:
                state = 'WIN'
        if state == 'WIN':
            fill_window((255,255,255))
            draw_text(create_text("Vous avez gagné",(125,150),(200,0,100),50,'middle'))
            draw_text(create_text("Retour pour revenir au menu",(125,340),(0,0,0),15,'middle'))
            draw_text(create_text("Espace pour rejouer",(125,360),(0,0,0),15,'middle'))
            if is_key_pressed(K_SPACE):
                state='INITGAME'
            if is_key_pressed(K_BACKSPACE):
                state='HOME'
        if state == 'lose':
            fill_window((255,255,255))
            draw_text(create_text("GAME OVER",(125,150),(200,0,100),30,'middle'))
            draw_text(create_text("Retour pour revenir au menu",(125,340),(0,0,0),15,'middle'))
            draw_text(create_text("Espace pour rejouer",(125,360),(0,0,0),15,'middle'))
            if is_key_pressed(K_SPACE):
                state='INITGAME'
            if is_key_pressed(K_BACKSPACE):
                state='HOME'
        return
     
    def handle_user():
        global sqr_x,sqr_y,user_state,state,w
        if is_key_pressed(K_ESCAPE):
            uninitialize()
        if user_state=='GAME':
            if is_key_pressed(K_UP):
                if sqr_y!= 0 and listsqr[sqr_x][sqr_y-1]==0:
                    square(sqr_x,sqr_y-1)
                    user_state="arret"
                    delay_process(arret,300)
            if is_key_pressed(K_LEFT):
                if sqr_x!= 0 and listsqr[sqr_x-1][sqr_y]==0:
                    square(sqr_x-1,sqr_y)
                    user_state="arret"
                    delay_process(arret,300)
            if is_key_pressed(K_DOWN):
                if sqr_y!= 6 and listsqr[sqr_x][sqr_y+1]==0:
                    square(sqr_x,sqr_y+1)
                    user_state="arret"
                    delay_process(arret,300)
            if is_key_pressed(K_RIGHT):
                if sqr_x!= 4 and listsqr[sqr_x+1][sqr_y]==0:
                    square(sqr_x+1,sqr_y)
                    user_state="arret"
                    delay_process(arret,300)
            if state == 'GAME':
                if (sqr_x!=0 and listsqr[sqr_x-1][sqr_y]==0)==False and (sqr_x!=4 and listsqr[sqr_x+1][sqr_y]==0)==False:
                    if (sqr_y !=0 and listsqr[sqr_x][sqr_y-1]==0)==0 and (sqr_y!=6 and listsqr[sqr_x][sqr_y+1]==0)==False:
                        state='lose'
        return
     
    def main_app():
        repeat_process(draw,20)
        repeat_process(handle_user,20)

  2. #2
    Membre émérite
    Avatar de emixam16
    Homme Profil pro
    Chercheur en sécurité
    Inscrit en
    Juin 2013
    Messages
    335
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Chercheur en sécurité

    Informations forums :
    Inscription : Juin 2013
    Messages : 335
    Par défaut
    Bonjour,

    Tu crois vraiment qu'on va faire ce travail à ta place? Ici on s'entraide, donc si tu as une question sur une fonction précise on pourra te conseiller mais personne ne va bénévolement faire ce travail à ta place.

    Essaye de faire un code, et si tu as des problèmes reviens nous voir

    Bonne soirée.

  3. #3
    Expert éminent

    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2007
    Messages
    5 202
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 5 202
    Par défaut
    Sur quoi bloques-tu ?

    Connais-tu le python ? Et le C ?

  4. #4
    Membre très actif
    Homme Profil pro
    Programmeur des cavernes
    Inscrit en
    Août 2017
    Messages
    364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Programmeur des cavernes
    Secteur : Enseignement

    Informations forums :
    Inscription : Août 2017
    Messages : 364
    Par défaut
    Pourquoi as-tu besoin de convertir ce bout de code (d'où vient-il au fait ?) en C ?

Discussions similaires

  1. Convertion csv vers python
    Par dedalios dans le forum Général Python
    Réponses: 27
    Dernier message: 11/04/2018, 23h11
  2. [Python 3.X] Python probléme, convertion liste de liste de str en liste de liste int
    Par eaufroide dans le forum Contribuez
    Réponses: 3
    Dernier message: 23/08/2017, 09h41
  3. [Python 3.X] Error when converting MATLAB's datenum to Python's datetime
    Par zoya23 dans le forum Calcul scientifique
    Réponses: 0
    Dernier message: 31/03/2017, 12h04
  4. Convertion Python --> C#
    Par moonshine972 dans le forum C#
    Réponses: 2
    Dernier message: 03/10/2012, 21h25
  5. Convertion de type VARIANT à type CString
    Par j_grue dans le forum MFC
    Réponses: 2
    Dernier message: 07/11/2002, 14h18

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