Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' of gitlab.com:FeelZoR/sbada
Browse files Browse the repository at this point in the history
  • Loading branch information
Feelzor committed Jan 24, 2019
2 parents 685aafd + 50e1efc commit 83e0479
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 7 deletions.
12 changes: 9 additions & 3 deletions p_combinaisons.adb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
with sequential_IO;
with text_io; use text_io;
with sequential_IO, p_jeu;
with text_io; use text_io, p_jeu, p_jeu.p_score_io;


package body p_combinaisons is
Expand Down Expand Up @@ -287,8 +287,14 @@ package body p_combinaisons is
-- {Génère Fout.txt et foutcont.txt contenant respectivement toutes les solutions et les solutions contigües}
f: p_cases_io.file_type;
fout, foutcont: text_io.file_type;

fscore : p_score_io.file_type;
begin
begin
open(fscore, IN_FILE,"score");
exception
when others => create(fscore, IN_FILE, "score");
end;
close(fscore);
open(f, IN_FILE, "CarreGaudi");
CreeVectGaudi(f, V);
triVectGaudi(V);
Expand Down
61 changes: 59 additions & 2 deletions p_jeu.adb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ package body p_jeu is

procedure enregistrerScore(score: in TR_Score) is
-- {} => {le score a été enregistré dans le fichier de scores}
f: p_score_io.file_type;
f :p_score_io.file_type;
begin
create(f, APPEND_FILE, "score");
open(f, APPEND_FILE, "score");
write(f, score);
close(f);
end enregistrerScore;
Expand All @@ -92,6 +92,7 @@ package body p_jeu is
if not abandon then enregistrerScore((pseudo, compterPoints));
else chrono.stop;
end if;

delete(fichierJeu);
close(fichierSolution);
jeuEnCours := false;
Expand Down Expand Up @@ -126,4 +127,60 @@ package body p_jeu is
result := SOLUTION_INVALIDE;
end if;
end verifSol;

function Nbscores(f : in p_score_io.file_type) return integer is
--{f ouvert et f- = <>} => {copmpte de le Nb de score du fichier}
tmp : TR_Score;
i: integer := 0;
begin
while not end_of_file(f) loop
read(f,Tmp);
i := i+1;
end loop;
return i;
end Nbscores;


procedure CopieFicherScore(f : in out p_score_io.file_type ; V : out TV_Score) is
-- {f ouvert, V de taille suffisante} => {Copie les elements vers v}
tmp : TR_Score;
i: integer;
begin
i := v'first;
reset(f,IN_FILE);
while not end_of_file(f) loop
read(f,tmp);
v(i) := tmp;
i := i+1;
end loop;
close(f);
end CopieFicherScore;

procedure permut(a, b: in out TR_Score) is -- type des valeurs du vecteur
-- {} => {les valeurs de a et b ont été échangées}
temp: TR_Score ;
begin
temp := a;
a := b;
b := temp;
end permut;

procedure triBullesScores(V : in out TV_Score) is
-- {} => {V trié par ordre croissant}
i : integer := V'first;
permutation: boolean := true;
begin
while permutation loop
permutation := false;
for j in reverse i+1..V'last loop
if V(j).score > V(j-1).score then
permut(V(j), V(j-1));
permutation := true;
end if;
end loop;
i := i+1;
end loop;
end triBullesScores;


end p_jeu;
13 changes: 13 additions & 0 deletions p_jeu.ads
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package p_jeu is
end T_Chrono;

package p_score_io is new sequential_IO(TR_Score); use p_score_io;
type TV_Score is array (positive range <>) of TR_Score;

FREQUENCE_MAJ : constant duration := 1.0;
SOLUTION_CORRECTE : constant integer := 0;
Expand Down Expand Up @@ -47,4 +48,16 @@ package p_jeu is
procedure verifSol(solution: in string; result: out integer);
-- {} => {Vérifie si la solution est correcte}

function Nbscores(f : in p_score_io.file_type) return integer;
--{} => {copmpte de le Nb de score du fichier}

procedure CopieFicherScore(f : in out p_score_io.file_type ; V : out TV_Score);
--{f ouvert, V de taille suffisante} => {Copie les elements vers v}

procedure permut(a, b: in out TR_Score) ;
-- {} => {les valeurs de a et b ont été échangées}

procedure triBullesScores(V : in out TV_Score);
-- {} => {V trié par ordre croissant}

end p_jeu;
42 changes: 40 additions & 2 deletions p_vue_graph.adb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
with p_fenbase, Forms, p_combinaisons, p_jeu, Ada.Strings, Ada.Strings.Fixed, text_io, X.Strings;
use p_fenbase, Forms, p_combinaisons, p_jeu, Ada.Strings, Ada.Strings.Fixed, text_io, p_combinaisons.p_cases_io;
use p_fenbase, Forms, p_combinaisons, p_jeu, Ada.Strings, Ada.Strings.Fixed, text_io, p_combinaisons.p_cases_io, p_jeu.p_score_io;


package body p_vue_graph is
Expand Down Expand Up @@ -132,8 +132,9 @@ package body p_vue_graph is
changerCouleurTexte(fenetre,"3" , FL_DOGERBLUE);
ajouterBouton(fenetre, "jeu", "Jouer au jeu", 35 , 430, 200 , 50);
ajouterBouton(fenetre, "Solution", "Afficher Solutions", 265 , 430 , 200 , 50);
ajouterBouton(fenetre, "Fermer", "Quitter", 200 , 505 , 100 , 50);
ajouterBouton(fenetre, "Fermer", "Quitter", 200 , 580 , 100 , 50);
ajouterBouton(fenetre, "Contigue", "Non", 200 , 375 , 50 , 30);
ajouterBouton(fenetre, "Scoreboard", "Scoreboard", 190 , 505 , 120 , 50);
ajouterTexte(fenetre, "TexTContigue : ", "Seulement contigue : ", 50,375,150,30);
ajouterTexte(fenetre, "Textintro", "Bienvenue dans le programme du carre de Subirachs", 50,100,400,30);
ajouterTexte(fenetre, "Textintro2", "Sur cet ecran, vous pouvez choisir le nombre d'elements d'une", 50,130,400,30);
Expand Down Expand Up @@ -240,6 +241,39 @@ package body p_vue_graph is
appuiBoutonRegles(attendreBouton(fenetre), fenetre);
end fenetreRegles;

procedure fenetreScores is
fenetre: TR_Fenetre;
fscore : p_score_io.file_type;
i : integer ;
begin
open(fscore, IN_FILE, "score");
i := 1;
reset(fscore,IN_FILE);
if Nbscores(fscore) > 0 then
reset(fscore,IN_FILE);
declare
VScore : TV_Score(1..Nbscores(fscore));
begin
reset(fscore,IN_FILE);
CopieFicherScore(fscore,VScore);
triBullesScores(VScore);
fenetre:= DebutFenetre("Scoreboard",500,600);
while i <= 10 and i <= VScore'last loop
ajouterTexte(fenetre, "Joueurs" &integer'image(i) , " Joueur : " & VScore(i).pseudo, 50,50 + (50*i),250,30);
ajouterTexte(fenetre, "Score" &integer'image(i) , "Points : " & integer'image(VScore(i).Score), 250,50 + (50*i),250,30);
i := i+1;
end loop;
ajouterBouton(fenetre, "valider", "Valider", 200 , 560 , 100 , 30);
finFenetre(fenetre);
montrerFenetre(fenetre);
if attendreBouton(fenetre) /= "00" then
cacherFenetre(fenetre);
fenetreaccueil;
end if;
end;
end if;
end fenetreScores;

procedure ouvreFenetreSolutions(nomFichier: in string; fenetre: TR_Fenetre) is
begin
open(fichierSolution, IN_FILE, nomFichier);
Expand Down Expand Up @@ -285,6 +319,9 @@ package body p_vue_graph is
CacherFenetre(fenetre);
chrono.fermer;
chronoJeu.fermer;
elsif Elem = "Scoreboard" then
CacherFenetre(fenetre);
fenetreScores;
else
appuiBoutonAccueil(attendreBouton(fenetre),fenetre);
end if;
Expand Down Expand Up @@ -346,6 +383,7 @@ package body p_vue_graph is
if Elem = "pseudo" or Elem ="valider" then
begin
if ConsulterContenu(fenetre,"pseudo") /= "Pseudo" then
pseudo := (others => ' ');
pseudo(ConsulterContenu(fenetre,"pseudo")'range) := ConsulterContenu(fenetre,"pseudo");
cacherFenetre(fenetre);
else
Expand Down
3 changes: 3 additions & 0 deletions p_vue_graph.ads
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ package p_vue_graph is
procedure fenetreaccueil;
--{} => {Affiche la fenetre d'Accueil}

procedure fenetreScores;
--{} => {Affiche la fenetre Scoreboard}

procedure appuiBoutonAccueil (Elem : in string; fenetre : in out TR_Fenetre);
--{} => {Affiche la fenetre Solutions}

Expand Down

0 comments on commit 83e0479

Please sign in to comment.