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 302 303 304 305 306 307
| program Project2;
{$APPTYPE CONSOLE}
uses
sysutils;
const DimX = 5 ;
DimY = 5 ;
var T1 : Array [1..DimX,1..DimY] of integer ;
i,j,a,b,nbMax,explosion,x1,y1,x2,y2,accord : integer ;
procedure PremiereInitialisation (i,j,DimX,DimY,nbMax : Integer);
begin
for i := 1 to DimX do
for j := 1 to DimY do
T1[i,j] := (random(nbMax) + 1);
end; //Procédure d'initialisation de la première grille ------------------------
procedure Verification (i,j,DimX,DimY,explosion : integer);
begin
while explosion <> 0 do
begin
explosion := 0;
for j := 1 to DimY do
for i := 1 to DimX - 2 do
begin
if T1[i,j] = T1[i+1,j] then
begin
if T1[i,j] = T1[i+2,j] then
begin
explosion := 1;
for a := 1 to 3 do T1[a,1] := random(nbMax) + 1 ;
for b := 1 to j-1 do
begin;
T1[i,b+1] := T1[i,b];
T1[i+1,b+1] := T1[i+1,b];
T1[i+2,b+1] := T1[i+2,b];
end;
end;
end;
end;
for i := 1 to DimX do
for j := 1 to DimY - 2 do
begin
if T1[i,j] = T1[i,j+1] then
begin
if T1[i,j] = T1[i,j+2] then
begin
explosion := 1;
for a := 1 to 3 do T1[i,a] := random(nbMax) + 1 ;
for b := 1 to j-2 do
begin
T1[i,j+2] := T1[i,j];
end;
end;
end;
end;
end;
end; //Procédure qui vérifie qu'il n'y a pas de chiffres placés à 3 sur la même ligne ou la même colonne
procedure AfficheLaGrille (i,j,DimX,DimY : Integer);
begin
for j := 1 to DimY do
begin
for i := 1 to DimX do write(T1[i,j]:7);
writeln;
writeln;
end;
end; //Procédure qui affiche la grille -----------------------------------------
procedure SelectionDesCoordonnees (x1,x2,y1,y2 : integer);
begin
readln(x1);
readln(y1);
readln(x2);
readln(y2);
end; //Procédure qui demande au joueur de séléctionner les coordonnées des 2 cases qu'il veut inverser
procedure VerificationEmplacementDesCases (x1,x2,y1,y2,accord : integer);
begin
if ((x1 = x2-1) or (x1 = x2+1) and (y1 = y2))
or ((y1 = y2-1) or (y1 = y2+1) and (x1 = x2))
then accord := 1
else accord := 0;
end; //Procédure qui vérifie que les 2 cases séléctionées sont bien placées côtes à côtes
procedure Inversion (x1,x2,y1,y2 : integer);
var a1,a2 : integer;
begin
if (x1 <= DimX) and (x2 <= DimX) and (y1 <= DimY) and (y1 <= DimY) then
begin
a1 := T1[x1,y1];
a2 := T1[x2,y2];
T1[x1,y1] := a2;
T1[x2,y2] := a1;
writeln('test ok'); //test
end;
end;
procedure VerificationCasesCotesACotes_x_3 (i,j,DimX,DimY,accord : integer);
begin
if accord = 1 then
begin
for j := 1 to DimY do
for i := 1 to DimX - 2 do
begin
if T1[i,j] = T1[i+1,j] then
begin
if T1[i,j] = T1[i+2,j] then accord := 1
else accord := 0
end;
end;
end;
end; //Procédure qui vérifie qu'il y ait bien 3 cases placées côtes à côtes en ligne
procedure VerificationCasesCotesACotes_y_3 (i,j,DimX,DimY,accord : integer);
begin
if accord = 1 then
begin
for j := 1 to DimY do
for i := 1 to DimX - 2 do
begin
if T1[i,j] = T1[i,j+1] then
begin
if T1[i,j] = T1[i,j+2] then accord := 1
else accord := 0
end;
end;
end
end; //Procédure qui vérifie qu'il y ait bien 3 cases placées côtes à côtes en colonne
procedure Suppression_x_3 (i,j,DimX,DimY : integer);
begin
for j := 1 to DimY do
for i := 1 to DimX - 2 do
begin
if T1[i,j] = T1[i+1,j] then
begin
if T1[i,j] = T1[i+2,j] then
begin
T1[i,j] := 0;
T1[i+1,j] := 0;
T1[i+2,j] := 0;
end;
end;
end;
end; //Procedure pour que les 3 cases côtes à côtes en ligne prennent la valeur 0
procedure Suppression_y_3 (i,j,DimX,DimY : integer);
begin
for i := 1 to DimX do
for j := 1 to DimY - 2 do
begin
if T1[i,j] = T1[i+1,j] then
begin
if T1[i,j] = T1[i+2,j] then
begin
T1[i,j] := 0;
T1[i,j+1] := 0;
T1[i,j+2] := 0;
end;
end;
end;
end; //Procedure pour que les 3 cases côtes à côtes en colonne prennent la valeur 0
procedure Compression (i,j,DimX,DimY : integer);
var verification : integer;
begin
verification := 0;
while (verification = 0) and (i <= DimX) and (j <= DimY) do
begin
for j := 1 to DimY - 1 do
for i := 1 to DimX do
begin
verification := 0;
if T1[DimX - i,j] = 0 then
begin
T1[DimX - i,j] := T1[DimX - i - 1,j];
T1[DimX - i - 1,j] := 0;
verification := 0;
end;
end;
end;
end; //Procédure qui compresse les chiffres vers le bas ------------------------
procedure ReinitialisationHaut (i,DimX : integer);
begin
for i := 1 to DimY do
begin
if T1[i,1] = 0 then T1[i,j] := (random(nbMax)) + 1 ;
end;
end; //Procédure qui réinitialise les chiffres nuls du haut --------------------
begin
randomize () ;
nbMax := 3 ;
PremiereInitialisation (i,j,DimX,DimY,nbMax);
//Initialisation de la première grille -------------------------------------
explosion := 1;
Verification (i,j,DimX,DimY,explosion);
//Vérifie qu'il n'y a pas de chiffres placés à 3 sur la même ligne ou la même colonne
AfficheLaGrille (i,j,DimX,DimY);
//Affichage de la première grille
while explosion <> 2 do
begin
SelectionDesCoordonnees (x1,x2,y1,y2);
//Demande au joueur de séléctionner les coordonnées des 2 cases qu'il veut inverser
Inversion (x1,x2,y1,y2);
//inversion des 2 cases ----------------------------------------------------
AfficheLaGrille (i,j,DimX,DimY); //teste
accord := 1;
VerificationEmplacementDesCases (x1,x2,y1,y2,accord);
//Vérifie que les 2 cases séléctionées sont bien placées côtes à côtes -----
writeln (accord);
VerificationCasesCotesACotes_x_3 (i,j,DimX,DimY,accord);
//Vérifie qu'il y ait bien 3 cases placées côtes à côtes en ligne ----------
writeln (accord);
VerificationCasesCotesACotes_y_3 (i,j,DimX,DimY,accord);
//Vérifie qu'il y ait bien 3 cases placées côtes à côtes en Colonne --------
writeln (accord);
if accord = 0 then
begin
Inversion (x1,x2,y1,y2);
//inversion des 2 cases ----------------------------------------------------
writeln('Vous n''avez pas séléctionner de chiffres places l''un a coté de l''autre. Veuillez reessayer.')
end;
if accord = 1 then
begin
Suppression_x_3 (i,j,DimX,DimY);
//les 3 cases côtes à côtes en ligne prennent la valeur 0 ------------------
Suppression_x_3 (i,j,DimX,DimY);
//les 3 cases côtes à côtes en colonne prennent la valeur 0 ----------------
Compression (i,j,DimX,DimY);
//Compresse les chiffres vers le bas ---------------------------------------
ReinitialisationHaut (i,DimX);
//Réinitialise les chiffres nuls du haut -----------------------------------
AfficheLaGrille (i,j,DimX,DimY);
//Affichage de la première grille ------------------------------------------
end;
end;
readln;
end. |
Partager