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

Commit

Permalink
scoreboard
Browse files Browse the repository at this point in the history
  • Loading branch information
NilsKrattinger committed Jan 24, 2019
1 parent 191a1ba commit f7879c5
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 4 deletions.
58 changes: 57 additions & 1 deletion p_jeu.adb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ package body p_jeu is
procedure finJeu(abandon: in boolean) is
-- {} => {Finit le jeu}
begin
if not abandon then enregistrerScore((pseudo, compterPoints)); end if;
if not abandon then enregistrerScore((pseudo, compterPoints)); end if;
delete(fichierJeu);
close(fichierSolution);
end finJeu;
Expand Down Expand Up @@ -78,4 +78,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;
14 changes: 14 additions & 0 deletions p_jeu.ads
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package p_jeu is
fichierJeu : text_io.file_type;
pseudo: string(1..20);

type TV_Score is array (positive range <>) of TR_Score;

procedure debutJeu(contigue: in boolean);
-- {} => {Lance le jeu}

Expand All @@ -35,4 +37,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;
43 changes: 40 additions & 3 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 @@ -91,8 +91,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 @@ -192,6 +193,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,130);
ajouterTexte(fenetre, "Score" &integer'image(i) , "Points : " & integer'image(VScore(i).Score), 250,50 + (50*i),3200,130);
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 @@ -234,7 +268,10 @@ package body p_vue_graph is
fenetreRegles;
fenetreJeu;
elsif Elem = "Fermer" then
CacherFenetre(fenetre);
CacherFenetre(fenetre);
elsif Elem = "Scoreboard" then
CacherFenetre(fenetre);
fenetreScores;
else
appuiBoutonAccueil(attendreBouton(fenetre),fenetre);
end if;
Expand Down
3 changes: 3 additions & 0 deletions p_vue_graph.ads
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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 f7879c5

Please sign in to comment.