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 :

Un jeu en language c, je suis coincé


Sujet :

C

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau candidat au Club
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1
    Par défaut Un jeu en language c, je suis coincé
    Bonjour, voila j'ai un probleme sur un jeu le 421...

    le programme fait jouer un seul joueur. Celui ci doit réaliser un 421 en 3 lancés. Il a la possibilité de garder 1, 2 résultats. Dés qu’il obtient le résultat 421, un message lui indiquant qu’il a gagné s’affiche.


    jai commencer mon prog...mais je n'arrive pas a sauvegarder le resultat lors du 2eme et 3eme lancée... et sa n'affiche pas que jai perdu ou gagné.

    merci de me dire ce qu'il va pas.
    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
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
     
    main()
    {
          unsigned lance1, lance2, lance3;
          unsigned WIN = 0;
          unsigned reroll = 6;
          unsigned choix;
          unsigned i=1;
     
                 printf("\n---------\n");
                 printf("\nJeu 421\n"); 
                 printf("\n---------\n");
     
     
                 srand(time(NULL));
     
     
                 lance1 = rand() % 6;
                 lance2 = rand() % 6;
                 lance3 = rand() % 6;
                 ++lance1;
                 ++lance2;
                 ++lance3;
     
     printf("\nRésultat:\n- Lance1: %d  \n- Lance2: %d  \n- Lance3: %d \n",lance1 ,lance2 ,lance3 );
                 --reroll;
     
               if ((lance1 == 4) && (lance2 == 2) && (lance3 == 1) || (lance1 == 4) && (lance2 == 1) && (lance3 == 2) || (lance1 == 2) && (lance2 == 1) && (lance3 == 4) || (lance1 == 2) && (lance2 == 4) && (lance3 == 1) || (lance1 == 1) && (lance2 == 4) && (lance3 == 2) || (lance1 == 1) && (lance2 == 2) && (lance3 == 4))
                 {
                 printf ("GAGNE\n");
                 WIN = 1;
                 }
                 else
                     {
                     printf("PERDU\n");                              
                     }
     
                 if ((WIN == 0) && (reroll != 0))
                 {
                 for(choix = 0;choix < 1 || choix > 2;)
     
     
                         {
                         printf("\nRelancer le 1er lancé???, si oui tapez 1, sinon tapez 2:\n");
                         scanf("%d", &choix);
                                     if(choix == 1)
                                     {
                                     lance1 = rand() % 6;
                                     ++lance1;
                         }
                 }
                 for(choix = 0;choix < 1 || choix > 2;)
                         {
                         printf("\nRelancer le 2eme lancé???, si oui tapez 1, sinon tapez 2:\n");
                         scanf("%d", &choix);
                                     if(choix == 1)
                                     {
                                     lance2 = rand() % 6;
                                     ++lance2;
                                     }
                         }
                 for(choix = 0;choix < 1 || choix > 2;)
                         {
                         printf("\nRelancer le 3eme lancé???, si oui tapez 1, sinon tapez 2:\n");
                         scanf("%d", &choix);
                                     if(choix == 1)
                                     {
                                     lance3 = rand() % 6;
                                     ++lance3;
     
     
                                     }
                         }
     
                 }
     
     
     
     
     
                 srand(time(NULL));
     
     
                 lance1 = rand() % 6;
                 lance2 = rand() % 6;
                 lance3 = rand() % 6;
                 ++lance1;
                 ++lance2;
                 ++lance3;
     
     printf("\nRésultat:\n- Lance1: %d  \n- Lance2: %d  \n- Lance3: %d \n",lance1 ,lance2 ,lance3 );
                 --reroll;
     
               if ((lance1 == 4) && (lance2 == 2) && (lance3 == 1) || (lance1 == 4) && (lance2 == 1) && (lance3 == 2) || (lance1 == 2) && (lance2 == 1) && (lance3 == 4) || (lance1 == 2) && (lance2 == 4) && (lance3 == 1) || (lance1 == 1) && (lance2 == 4) && (lance3 == 2) || (lance1 == 1) && (lance2 == 2) && (lance3 == 4))
                 {
                 printf ("GAGNE\n");
                 WIN = 1;
                 }
                 else
                     {
                     printf("PERDU\n");                              
                     }
     
                 if ((WIN == 0) && (reroll != 0))
                 {
                 for(choix = 0;choix < 1 || choix > 2;)
     
     
                         {
                         printf("\nRelancer le 1er lancé???, si oui tapez 1, sinon tapez 2:\n");
                         scanf("%d", &choix);
                                     if(choix == 1)
                                     {
                                     lance1 = rand() % 6;
                                     ++lance1;
                         }
                 }
                 for(choix = 0;choix < 1 || choix > 2;)
                         {
                         printf("\nRelancer le 2eme lancé???, si oui tapez 1, sinon tapez 2:\n");
                         scanf("%d", &choix);
                                     if(choix == 1)
                                     {
                                     lance2 = rand() % 6;
                                     ++lance2;
                                     }
                         }
                 for(choix = 0;choix < 1 || choix > 2;)
                         {
                         printf("\nRelancer le 3eme lancé???, si oui tapez 1, sinon tapez 2:\n");
                         scanf("%d", &choix);
                                     if(choix == 1)
                                     {
                                     lance3 = rand() % 6;
                                     ++lance3;
     
     
                                     }
                         }
     
                 }
     
     
     
     
     
                 srand(time(NULL));
     
     
                 lance1 = rand() % 6;
                 lance2 = rand() % 6;
                 lance3 = rand() % 6;
                 ++lance1;
                 ++lance2;
                 ++lance3;
     
     printf("\nRésultat:\n- Lance1: %d  \n- Lance2: %d  \n- Lance3: %d \n",lance1 ,lance2 ,lance3 );
                 --reroll;
     
               if ((lance1 == 4) && (lance2 == 2) && (lance3 == 1) || (lance1 == 4) && (lance2 == 1) && (lance3 == 2) || (lance1 == 2) && (lance2 == 1) && (lance3 == 4) || (lance1 == 2) && (lance2 == 4) && (lance3 == 1) || (lance1 == 1) && (lance2 == 4) && (lance3 == 2) || (lance1 == 1) && (lance2 == 2) && (lance3 == 4))
                 {
                 printf ("GAGNE\n");
                 WIN = 1;
                 }
                 else
                     {
                     printf("PERDU\n");                              
                     }
     
                 if ((WIN == 0) && (reroll != 0))
                 {
                 for(choix = 0;choix < 1 || choix > 2;)
     
     
                         {
                         printf("\nRelancer le 1er lancé???, si oui tapez 1, sinon tapez 2:\n");
                         scanf("%d", &choix);
                                     if(choix == 1)
                                     {
                                     lance1 = rand() % 6;
                                     ++lance1;
                         }
                 }
                 for(choix = 0;choix < 1 || choix > 2;)
                         {
                         printf("\nRelancer le 2eme lancé???, si oui tapez 1, sinon tapez 2:\n");
                         scanf("%d", &choix);
                                     if(choix == 1)
                                     {
                                     lance2 = rand() % 6;
                                     ++lance2;
                                     }
                         }
                 for(choix = 0;choix < 1 || choix > 2;)
                         {
                         printf("\nRelancer le 3eme lancé???, si oui tapez 1, sinon tapez 2:\n");
                         scanf("%d", &choix);
                                     if(choix == 1)
                                     {
                                     lance3 = rand() % 6;
                                     ++lance3;
     
     
                                     }
                         }
     
                 }
                 }

  2. #2
    Expert éminent
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 395
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 395
    Par défaut
    1. Contrairement à ce qu'on peut croire, scanf() est à déconseiller aux débutants.
    2. N'utilise pas de variables en majuscules.
    3. Pour tes trois lancers, tu devrais peut-être utiliser une boucle, ou au moins découper ton code en fonctions, car là, tu as un taux de copier-coller monstrueux...
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  3. #3
    Membre confirmé Avatar de semaj_james
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    193
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2004
    Messages : 193
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    main()
    {
          unsigned lance1, lance2, lance3;
          unsigned WIN = 0;
          unsigned reroll = 6;
          unsigned choix;
          unsigned i=1;
     
     printf("\nRésultat:\n- Lance1: %d  \n- Lance2: %d  \n- Lance3: %d \n",lance1 ,lance2 ,lance3 );
                 --reroll;
    Pour imprimer une variable unsigned avec printf il faut utiliser %u
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    #include <stdio.h>
     
    int main() {
    unsigned int a;
    int b;
     
    a=4000;
    b=a;
    /* Attention au format %u */
    printf("a=%u \nb=%d \n", a, b);
    }

  4. #4
    Expert éminent
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 68
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Par défaut
    Citation Envoyé par semaj_james
    unsigned n'est pas utilisé correctement. Il te faut défnir le type de la variable:
    Non. unsigned et unsigned int sont synonymes.

    Par contre, "%d" avec unsigned, ça le fait pas. C'est "%u".

  5. #5
    Membre confirmé Avatar de semaj_james
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    193
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2004
    Messages : 193
    Par défaut
    Citation Envoyé par Emmanuel Delahaye
    Non. unsigned et unsigned int sont synonymes.
    c'est exact j'ai ecris trop vite !

  6. #6
    Expert éminent
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 68
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Par défaut
    Citation Envoyé par pooky91
    merci de me dire ce qu'il va pas.
    Je laisse la parole à mon compilateur qui a des commentaires à faire :
    Project : Forums
    Compiler : GNU GCC Compiler (called directly)
    Directory : C:\dev\forums2\
    --------------------------------------------------------------------------------
    Switching to target: default
    Compiling: main.c
    main.c:6: warning: return type defaults to `int'
    main.c: In function `main':
    main.c:31: warning: suggest parentheses around && within ||
    main.c:31: warning: suggest parentheses around && within ||
    main.c:31: warning: suggest parentheses around && within ||
    main.c:31: warning: suggest parentheses around && within ||
    main.c:31: warning: suggest parentheses around && within ||
    main.c:97: warning: suggest parentheses around && within ||
    main.c:97: warning: suggest parentheses around && within ||
    main.c:97: warning: suggest parentheses around && within ||
    main.c:97: warning: suggest parentheses around && within ||
    main.c:97: warning: suggest parentheses around && within ||
    main.c:163: warning: suggest parentheses around && within ||
    main.c:163: warning: suggest parentheses around && within ||
    main.c:163: warning: suggest parentheses around && within ||
    main.c:163: warning: suggest parentheses around && within ||
    main.c:163: warning: suggest parentheses around && within ||
    main.c:11: warning: unused variable `i'
    main.c:211: warning: control reaches end of non-void function
    Linking console executable: C:\dev\forums2\console.exe
    Process terminated with status 0 (0 minutes, 2 seconds)
    0 errors, 18 warnings
    J'ai jeté un oeil à ton code et j'ai eu peur ! Tu n'as jamais entendu parlé des fonctions ? Ce serait le moment de les utiliser...

    Une petite reflexion sur la règle du 421 permettrait d'écrire l'algorithme d'une façon simple et claire et de monter les fonctions à réaliser...

Discussions similaires

  1. Mon jeu, venez m'aider, je suis un peu coincé!
    Par Megascript dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 20/06/2007, 18h44
  2. Réponses: 4
    Dernier message: 22/05/2007, 18h40
  3. conception jeu video quel outils, quel language?
    Par darontankian dans le forum Développement 2D, 3D et Jeux
    Réponses: 6
    Dernier message: 13/02/2007, 20h32
  4. [AJAX]Help je suis coincé :(
    Par Death83 dans le forum Général JavaScript
    Réponses: 10
    Dernier message: 12/03/2006, 10h40

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