je fait un jeu de solitaire en c++
j'ai un probleme dans ma fonction pour melanger les cartes du talon (ds la fonction melange
j'aimeré que vous maidié a trouver pourqoi sa ne marche pas
merci d'avance



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

#include <iostream>
#include <ctime>
#include <cmath>
#include <fstream>
using namespace std;
typedef struct jeu_carte{
   char * nb;
   char *couleur;
}carte;


typedef struct pile {          //pile represente les structure des tableau, fondation, ecart, talon en liste chaine
    carte *c;
    struct pile *pcartesuivante;
}pile;





  
//fct creation du jeu de carte
void creation_jeu_de_carte( carte **&tab)
{     
  
  int i,j;
  tab=new carte*[52];
  for(i=0;i<52;i++)
      tab[i]=new jeu_carte();
  for(j=0;j<4;j++)
  {
  for(i=0;i<13;i++)
      {
      tab[i+13*j]->couleur=new char[8];
      tab[i+13*j]->nb=new char [25];
      switch (j){
      case 0 : tab[i+13*j]->couleur="coeur";
               break;
      case 1 : tab[i+13*j]->couleur="carreau";
               break;
      case 2 : tab[i+13*j]->couleur="trefle";
               break;
      case 3 : tab[i+13*j]->couleur="pique";
               break;
               }
      switch (i){ 
      case 0  : tab[i+13*j]->nb="as ";
                break;            
      case 1  : tab[i+13*j]->nb="deux ";
                break;
      case 2  : tab[i+13*j]->nb="trois ";
                 break;
      case 3  : tab[i+13*j]->nb="quatre ";
                 break;
      case 4  : tab[i+13*j]->nb="cinq ";
                break;
      case 5  : tab[i+13*j]->nb="six ";
                break;
      case 6  : tab[i+13*j]->nb="sept ";
                break;
      case 7  : tab[i+13*j]->nb="huit ";
                break;
      case 8  : tab[i+13*j]->nb="neuf ";
               break;
      case 9  : tab[i+13*j]->nb="dix ";
               break;
      case 10 : tab[i+13*j]->nb="valet ";
                break;
      case 11 : tab[i+13*j]->nb="dame ";
                break;
      case 12 : tab[i+13*j]->nb="roi ";
                  }  
       }
   }
}




// fonction choix de carte aleatoire
carte* alea_carte(carte **&cart)
{ 
 int i,j=0;
 carte *temp;
 temp=new jeu_carte();
 do
     j=rand()%52;
while(cart[j]==0);
 temp=cart[j];
 cart[j]=0;
 return temp;
 }




//fonction qui melange les carte du talon
void melange (carte **&cart, pile *&talon)
{
 int j,i=0;
 pile *ptemp,*nouvelle;
 //ptemp=new pile();
 nouvelle=new pile();
 talon=0;
 random_shuffle(cart,cart+52);
 
 
     do
      {
      nouvelle->c=cart[i];
      nouvelle->pcartesuivante=0;
      i++;
      }
   while(cart[i-1]==0);
    cart[i-1]=0;
    talon=nouvelle;
   ptemp=talon;

     for(i=0;i<52;i++)
       {if(cart[i]!=0)
       {
       nouvelle->c=cart[i];
       nouvelle->pcartesuivante=0;
       while(ptemp->pcartesuivante!=0)
              ptemp=ptemp->pcartesuivante;     //erreur ici 
       ptemp->pcartesuivante=nouvelle;
       }cout<<ptemp->pcartesuivante<<endl;
       cout<<nouvelle->pcartesuivante<<endl;}
   
 ptemp=talon;
 /*while(ptemp->pcartesuivante!=0)
    {
     cout<<ptemp->c->nb<<" de "<<ptemp->c->couleur<<endl;
     ptemp=ptemp->pcartesuivante;
   }*/
  
 } 
 


  
 
//fonction affiche une pile
void affiche_pile(pile**tab)
{
int i;
for(i=0;i<5;i++)
   {
      cout<<"pile "<<i+1<<" : "<<endl;
      cout<<tab[i]->c->nb<<"de "<<tab[i]->c->couleur<<endl; 
   }
} 

 
 
 
    
int main()
{
  srand(time(NULL));
  int i,j,k;
 
 
  carte **cart;
  creation_jeu_de_carte(cart);                      //creation du jeu de carte
  
  
  
  pile **tab;
  tab=new pile*[5];
  for(i=0;i<5;i++)
      {
      tab[i]=new pile();
      tab[i]->c=alea_carte(cart);
      tab[i]->pcartesuivante=0;               //creation et initialisation des tableau
      }
      
      affiche_pile(tab);
  
  
    
  pile **fondation;
  fondation=new pile*[4];
  for(i=0;i<4;i++)
     {
     fondation[i]=new pile();                    //creation des fondations
     fondation[i]=0;
     }
     
     
      
 
 
  pile *ecart;
  ecart=new pile();                              //creation de l'ecart
  ecart=0;

   
  pile *talon;                                  
  talon=new pile();
  melange(cart,talon);                         //creation et initailisation du talon
  
 
  
     
      
      delete []fondation;
      delete []cart;
      delete []tab;
system("pause");
  return 0;
}