Tableaux statiques/dynamiques

Fermé
ggggb Messages postés 1 Date d'inscription vendredi 24 janvier 2014 Statut Membre Dernière intervention 24 janvier 2014 - Modifié par dsy73 le 25/01/2014 à 08:09
Bonjour,

Dans le cadre d'un projet en informatique, nous devons créer un démineur en langage Pascal. Nous étions partis sur des tableaux statiques, puis nous nous sommes vite rendus compte de l'interet des tableaux dynamique.
En effet, notre but est de créer un démineur, et de faire un menu permettant de jouer en modes différents :
-facile
-intermédiaire
-dificile
-mode personnalisé où l'utilisateur pourra choisir lui meme les parametres ( nombres de mines, dimensions.. )

Notre premier programme avec les tableaux statique nosu permettait de faire fonctionner le jeu en niveau facile, puis le niveau intermediaire et difficile n'affichait que les tableaux.

Nous sommes donc partis sur des tableaux dynamiques qui nous ont posés beaucoup de problèmes car le peu de temps qu'il nous reste nous empeche de tout recommencer, en effet le projet est a rendre dimanche soir.

C'est pourquoi je me permet de solliciter votre aide, a vous intrnautes, qui sauraient peut etre résoudre notre porblème et rendre un travail décent.

Merci d'avance.







Program Demineur;

type
zone = (none,zero,un,deux,trois,quatre,cinq,six,sept,huit);
vide = boolean;
flag = boolean;
mine = boolean;
coord = record x,y,a,b,c,d:integer; end;
cases = record fl : flag; zo:zone; mi:mine; vi:vide; end;
plateau = array of array of cases; //Tableau dynamique à deux dimensions

Var
p: plateau;
pos:coord;
m,n,nbmines,i,j : Integer;
choix : integer;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Procedure Prologue; //Ecran d'accueil
var choix:integer;
Begin

writeln('');
writeln(' _____ ______ __ __ _____ _ _ ______ _ _ _____ ');
writeln('| __ \ | ____|| \/ ||_ _|| \ | || ____|| | | || __ \ ');
writeln('| | | || |__ | \ / | | | | \| || |__ | | | || |__) |');
writeln('| | | || __| | |\/| | | | | . ' || __| | | | || _ / ');
writeln('| |__| || |____ | | | | _| |_ | |\ || |____ | |__| || | \ \ ');
writeln('|_____/ |______||_| |_||_____||_| \_||______| \____/ |_| \_\');
writeln('');
writeln('');
writeln('');


writeln('Veuillez choisir un niveau de difficulté : - 1 pour facile - 2 pour moyen - 3 pour difficile - 4 pour une personnalisation');
readln(choix);

writeln('Votre choix est : ', choix);

If choix=1 Then
begin
Writeln('10x9, avec 9 mines');
end;

If choix=2 Then
begin
Writeln('20x18, avec 45 mines');
end;

If choix=3 Then
begin
Writeln('40x36, avec 36 mines');
end;

If choix=4 Then
begin
Writeln('personnalisable');
end;

End;


/////////////////////////////////////////////////////////////////////////////////////////////////////////

Procedure Initialiser(var p: plateau); //Redirection du menu jusqu'au tableau correspondant
Var c, choix : Integer;

Begin

If choix = 1 then
begin
m:=10;
n:=9;
nbmines:=9;
end;

If choix = 2 then
begin
m:=20;
n:=18;
nbmines:=45;
end;

If choix = 3 then
begin
m:=40;
n:=36;
nbmines:=36;
end;

If choix = 4 then //choix personnalisable
begin
Writeln('Entrez les dimensions de votre plateau de jeu : ');
Read(m); writeln('x'); Read(n);
While (m<0) or (n<0) do begin
Writeln('Tu as déjà vu un plateau avec des coordonnées négatives?');
Writeln('');
Writeln('Entrez les dimensions de votre plateau de jeu : ');
Read(m); writeln('x'); Read(n);
end;
writeln('');
Writeln('Saisissez le nombre de mines de votre plateau :');
Read(nbmines);
end;

Setlength(p,m,n); //Tableau dynamique

For i:= 0 to high(p) do
Begin
For j:= 0 to high(p[0]) do
p[i,j].vi:=true;
End;

For c:=1 to nbmines do // Disposition des mines
begin
i:=random(high(p)+1);
j:=random(high(p[0])+1);
While p[i,j].mi = true do
Begin
i:=random(high(p)+1);
j:=random(high(p[0])+1);
end;
p[i,j].mi:=true; // Si la mine tombe sur une case vide, alors cette dernière porte désormais une mine
end;

End;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Procedure Afficher(p: plateau); //Le plateau est la modélisation du tableau
//Var i, j : Integer;

Begin
For j:= 0 to high(p[0]) do
begin
For i:= 0 to high(p) do
begin
write('|');
If p[i,j].mi=true then write('*')
Else write('O');
end;

write('|');
writeln('');
end;

writeln('');
writeln('');

End;

/////////////////////////////////////////////////////////////////////////////////////////////////

Function isValide(c,d:integer):boolean;
Begin
exit((c>=0) AND (c<=high(p)) AND (d>=0) AND (d<=high(p[0])) );
End;

/////////////////////////////////////////////////////////////////////////////////////////////////

Procedure Jouer(Var p:plateau);
Var
fin:boolean;
voisin:integer;

Begin

fin:=false;
pos.x:=0;
pos.y:=0;


Repeat
voisin:=0;

If (p[pos.x][pos.y].mi=true) and (p[pos.x][pos.y].fl=false) then
Begin
fin:=true;
writeln('fin');
Exit;
End;

If p[pos.x][pos.y].vi=true then
Begin
If isValide(pos.x-1,pos.y-1) Then if p[pos.x-1][pos.y-1].mi=true then voisin:=voisin+1;
If isValide(pos.x-1,pos.y+1) Then if p[pos.x-1][pos.y+1].mi=true then voisin:=voisin+1;
If isValide(pos.x,pos.y-1) Then if p[pos.x][pos.y-1].mi=true then voisin:=voisin+1;
If isValide(pos.x,pos.y+1) Then if p[pos.x][pos.y+1].mi=true then voisin:=voisin+1;
If isValide(pos.x+1,pos.y-1) Then if p[pos.x+1][pos.y-1].mi=true then voisin:=voisin+1;
If isValide(pos.x+1,pos.y+1) Then if p[pos.x+1][pos.y+1].mi=true then voisin:=voisin+1;
If isValide(pos.x-1,pos.y) Then if p[pos.x-1][pos.y].mi=true then voisin:=voisin+1;
If isValide(pos.x+1,pos.y) Then if p[pos.x+1][pos.y].mi=true then voisin:=voisin+1;
End;

If voisin=0 then p[pos.x][pos.y].zo:=zero;
If voisin=1 then p[pos.x][pos.y].zo:=un;
If voisin=2 then p[pos.x][pos.y].zo:=deux;
If voisin=3 then p[pos.x][pos.y].zo:=trois;
If voisin=4 then p[pos.x][pos.y].zo:=quatre;
If voisin=5 then p[pos.x][pos.y].zo:=cinq;
If voisin=6 then p[pos.x][pos.y].zo:=six;
If voisin=7 then p[pos.x][pos.y].zo:=sept;
If voisin=8 then p[pos.x][pos.y].zo:=huit;

Afficher(p);

Until fin=true
//Until p[pos.x][pos.y]=boom;
End;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Begin

Randomize();
Prologue;
Initialiser(p);
Jouer(p);

End.