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
| Program Demineur ;
Uses
crt;
Type coord = record cacher,drapeau,bombe:boolean; cases:word; End;
Type plateau = array of array of coord ;
///////////
// Debug //
///////////
Procedure bug(i:byte);
Begin
Write('BUG', i);
End;
//////////////////////////
// Fonction Initialiser //
//////////////////////////
Procedure Initialiser(var p:plateau);
Var
i,j:word;
Begin
For i:=0 to length(p)-1 do
Begin
For j:=0 to length(p[0])-1 do
Begin
p[i,j].cacher:=True ;
p[i,j].cases:=0;
End;
End;
End;
////////////////////////////////////////
// Fonction Afficher la grille du jeu //
////////////////////////////////////////
Procedure AfficheJeu(p:plateau);
Var
i,j:word;
Begin
For i:=0 to length(p)-1 do
Write('+---');
Writeln('+');
For i:=0 to length(p)-1 do
Begin
For j:=0 to length(p[0])-1 do
Begin
If p[i,j].cacher then write('| # ')
Else
If ((p[i,j].cases)in[1..8])then write('| ', p[i,j].cases,' ')
Else
If (p[i,j].cases=0) then write('| ')
Else
If p[i,j].drapeau then write('| D ')
Else
If p[i,j].bombe then Write('| M ');
End;
Writeln('|');
For j:=0 to length(p)-1 do
Write('+---');
Writeln('+');
End;
End;
///////////////////////////////
// Fonction placer les mines //
///////////////////////////////
Procedure Placement(var p:plateau; k:integer);
Var
i,r1,r2:word;
Begin
i:=k;
Randomize;
While i>0 do
Begin
r1:=random(length(p)-1);
r2:=random(length(p[0])-1);
If(p[r1,r2].bombe=false) then
Begin
p[r1,r2].bombe:=true;
i:=i-1;
End;
End;
End;
///////////////////////////////////////
// Calculer le nombre de mine autour //
///////////////////////////////////////
Procedure chiffreCase(var p:plateau);
Var
i,j,k,l:word;
Begin
For i:=0 to length(p)-1 do
Begin
For j:=0 to length(p[0])-1 do
Begin
For k:=i-1 to i+1 do
Begin
For l:=j-1 to j+1 do
Begin
If (k>=0) and (k<=length(p)) and (l>=0) and (l<=length(p[0])) then
Begin
If p[i,j].bombe then //Au départ je voulais mettre ici la case p[k,l] et sur la case que je traite après mettre p[i,j] mais ça me mene à un runtime error 216 dans ce cas là
Begin
p[k,l].cases:=p[k,l].cases+1; // c'est ici que je voulais mettre p[i,j].
End;
End;
End;
End;
End;
End;
End;
////////////////////////////////
// Fonction dévoiler une case //
////////////////////////////////
Procedure Devoiler(var pl:plateau; i,j:word);
Var
i1,j1:word;
Begin
pl[i,j].cacher:=false;
For i1:=i-1 to i+1 do
Begin
//bug(13);
For j1:=j-1 to j+1 do
Begin
If (i1>=0) and (i1<=length(pl)) and (j1>=0) and (j1<=length(pl[0])) then // j'ai rajouter une condition d'arret si i=0
Begin
If pl[i1,j1].cacher then
Begin
//bug(15);
If pl[i1,j1].cases=0 then
Devoiler(pl,i1,j1)
Else
//bug(16);
If pl[i1,j1].cases in [1..8] then
pl[i1,j1].cacher:=false;
End;
End;
End;
End;
End;
///////////////////////////////
// Fonction poser un drapeau //
///////////////////////////////
Procedure Drap(var pl:plateau;i,j:word);
Begin
pl[i,j].cacher:=false;
pl[i,j].drapeau:=true;
End;
////////////////////////////////////////////////////////////////
// Fonction calculer le nombre de case qu'il reste à devoiler //
////////////////////////////////////////////////////////////////
Function Reste(p:plateau):integer;
Var
i,j:word;
k:integer;
Begin
k:=length(p)*length(p[0]); //J'avais essayer de mettre la procédure que tu avais poster, mais dans tout els cas ça ne marche pas.. :/ Je pense comprendre que l'erreur viendrais du fait que le k baisse à chaque fois que je joue en retestant toute les cases.. alors qu'il faudrait juste qu'il retire le nombre de case découvert en plus et qu'il ne reparte pas à 0
For i:=0 to length(p)-1 do
For j:=0 to length(p[0])-1 do
If not(p[i,j].cacher) then
k:=k-1;
Reste:=k;
End;
/////////////////////////////////
// Fonction pour pouvoir jouer //
/////////////////////////////////
Procedure Jouer(var p:plateau;m:integer);
Var
i,j,c:word;
Resultat:boolean;
Begin
Repeat
Repeat
Writeln('Choisissez les coordonnées où vous voulez jouer.');
Write('Ligne : ');
Readln(i);
Write('Colonne : ');
Readln(j);
Until(p[i,j].cacher);
Resultat:=false;
Writeln('Que voulez-vous faire ?');
Writeln('1) Dévoilez la case.');
Writeln('2) Mettre un drapeau.');
Readln(c);
If (c=1) then
Begin
bug(8);
If (p[i,j].bombe=true) then
Begin
bug(9);
p[i,j].cacher:=false;
Resultat:=True;
End
Else
bug(10);
If (p[i,j].cases) in [1..8] then
Begin
bug(11);
p[i,j].cacher:=false;
End
Else
Begin
bug(20);
Devoiler(p,i,j);
End;
If not(Resultat) then Resultat:=(Reste(p)=0);
clrscr;
AfficheJeu(p);
End;
If (c=2) then
Begin
Drap(p,i,j);
clrscr;
AfficheJeu(p);
End;
Until(Resultat);
End;
/////////////////////////
// Programme principal //
/////////////////////////
Var
p:plateau;
i,j,m:word;
c:integer;
Begin
Writeln('Bonjour, que voulez vous faire.');
Writeln('1)Jouer au démineur mode débutant.');
Writeln('2)Jouer au démineur mode intermédiaire.');
Writeln('3)Jouer au démineur mode expert.');
Writeln('4)Jouer au démineur mode éditable.');
Readln(c);
Begin
If c=1 then
setlength(p,8,8)
Else
Begin
If c=2 then
setlength(p,16,16)
Else
Begin
If c=3 then
setlength(p,24,24)
Else
Begin
If c=4 then
Begin
Writeln('Choisissez les dimensions de votre tableau.(Ligne puis colonne.)');
Readln(i);
Readln(j);
Setlength(p,i,j);
End;
End;
End;
End;
End;
Writeln('ça va ?');
Initialiser(p);
Writeln('choisir nb mine');
Readln(m);
Placement(p,m);
Writeln('ok');
ChiffreCase(p);
Writeln('D''acc');
AfficheJeu(p);
Writeln('Bye');
Jouer(p,m);
Writeln('Tchu');
Readkey;
End. |
Partager