Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with p_fenbase ; use p_fenbase ;
- with Forms ; use Forms;
- with ada.calendar; use ada.calendar;
- with p_twist; use p_twist;
- with ada.io_exceptions; use ada.io_exceptions;
- with p_vue_graph; use p_vue_graph;
- with text_io; use text_io;
- use p_twist.p_int_io;
- use p_twist.p_piece_io;
- procedure twist_graph2 is
- Facc, FJeu,Freg,Fwin : TR_Fenetre; --Fenêtres
- V : TV_Grille; --Grille
- f : text_io.file_type; --fichier level
- VP : TV_Piece; --Pièces
- g : p_piece_io.file_type; --fichier pièces
- matRotD,matRetH,matRotG,matRetV : TV_Matrice; --matrice contenant une pièce transformée
- possible : boolean;--booléen de placement
- n : level;--numero du niveau
- nump,m : T_NumPiece; --numero piece
- EX_FinJeu,EX_WIN,EX_Restart : exception;--exception
- NewLine : constant Character := Character'Val (10);--retour a la ligne lors d'affichage
- tromper : boolean := false;--booléen pour réentrer n
- BoutonDebut : string(1..7);--choix à l'accueil
- begin
- loop
- begin
- --ouverture fichier
- open(f,in_file,"defis.txt");
- open(g,in_file,"fpieces");
- --initialisation des fenêtres
- InitialiserFenetres;
- InitFenetreAccueil(Facc);
- InitFenetreWin(Fwin);
- InitFenetreJeu(FJeu);
- InitRegle(Freg);
- --si l'utilisateur à mal saisi n mettre des indications
- if tromper then
- ChangerTexte(FAcc,"Erreur","Erreur les niveaux vont");
- ChangerTexte(FAcc,"Erreur2","de 1 a 101");
- end if;
- MontrerFenetre(Facc);--affichage fenetre accueil
- tromper := true;
- CreeVectPiece(g,VP);--creation de VP via g
- BoutonDebut := " ";
- while BoutonDebut /= "BoutonV" and BoutonDebut /= "BoutonQ" loop --tant que l'utilisateur ne quitte ou ne valide pas
- --bloc traitement fenetre accueil
- declare
- Bouton : string := (AttendreBouton(Facc));--recuperation information bouton
- begin
- if (Bouton'last-Bouton'first) = (BoutonDebut'last-BoutonDebut'first) then
- BoutonDebut := Bouton;
- end if;
- if Bouton = "BoutonR" then
- MontrerFenetre(Freg);--affichage fenetre regle
- tromper := false;
- --bloc traitement fenetre regle
- declare
- Bouton1 : string := (AttendreBouton(Freg));
- begin
- if Bouton1 = "BoutonQuitter" then
- raise EX_Restart;
- end if;
- end;
- elsif Bouton = "BoutonQ" then
- raise EX_FinJeu;
- elsif Bouton = "BoutonV" then
- n := integer'value(ConsulterContenu(Facc,"niveau"));--recuperation numero niveau
- CacherFenetre(Facc);
- InitJeu(f,n,V);--initialise la grille en fonction du niveau via f
- MontrerFenetre(Fjeu);--affiche la fenetre de jeu
- InitNiveau(Fjeu,f,n,V);--initialise le niveau
- ReinitTransfo(Fjeu);--reinitialise les exemples de transformations
- AfficheGrille(Fjeu,V,VP);--affiche la grille
- AffichePiecesNonPlacees(Fjeu,VP);--affiche les pièces non placés
- end if;
- end;
- end loop;
- while not PartieGagne(VP) loop
- --bloc traitement fenetre jeu
- declare
- Bouton2 : String := (AttendreBouton(Fjeu));
- begin
- --reinitialisation
- ChangerContenu(Fjeu,"Messageerreur","");
- ReinitTransfo(Fjeu);
- --affichage
- AfficheGrille(Fjeu,V,VP);
- AffichePiecesNonPlacees(Fjeu,VP);
- if Bouton2 = "BoutonQuitter" then
- raise EX_FinJeu;--fermer le jeu
- end if;
- if Bouton2 = "BoutonRegle" then
- MontrerFenetre(Freg);--affiche les règles
- declare
- Bouton3 : string := (AttendreBouton(Freg));
- begin
- if Bouton3 = "BoutonQuitter" then
- CacherFenetre(Freg);
- end if;
- end;
- end if;
- if Bouton2(Bouton2'first) = 'P' or Bouton2(Bouton2'first) = 'N' then --si selection d'une piece
- nump := integer'value(Bouton2(Bouton2'first+1..Bouton2'first+2));--recuperation numero de piece
- AffichePieceTourner(Fjeu,VP,nump,matRotD,matRotG,matRetV,matRetH);--affiche 4 transformations possibles de la pièces
- declare
- Bouton4 : String := (AttendreBouton(Fjeu));
- begin
- if Bouton4(Bouton4'first) = 'R' or Bouton4(Bouton4'first) = 'T' then--si une transformation est selectionnee : l'effectuee
- if integer'value(Bouton4(Bouton4'first+1..Bouton4'first+2)) = 1 then
- rotG(VP,nump);
- elsif integer'value(Bouton4(Bouton4'first+1..Bouton4'first+2)) = 2 then
- rotD(VP,nump);
- elsif integer'value(Bouton4(Bouton4'first+1..Bouton4'first+2)) = 3 then
- retH(VP,nump);
- else
- retV(VP,nump);
- end if;
- elsif Bouton4(Bouton4'first) = 'C' or Bouton4(Bouton4'first) = 'D' then --si une case est selectionnee placé la pièce
- placer(V,VP,nump,integer'value(Bouton4(Bouton4'first+3..Bouton4'first+3)),Bouton4(Bouton4'first+1),possible);
- if not possible then --si placement impossible afficher message d'erreur
- ChangerContenu(Fjeu,"Messageerreur",NewLine&" Impossible de placer la piece");
- end if;
- --reinitialisation
- ReinitTransfo(Fjeu);
- --affichage
- AfficheGrille(Fjeu,V,VP);
- AffichePiecesNonPlacees(Fjeu,VP);
- end if;
- end;
- elsif Bouton2(Bouton2'first) = 'C' or Bouton2(Bouton2'first) = 'D' then --si une case est selectionnee
- m := V(integer'value(Bouton2(Bouton2'first+2..Bouton2'first+3)),Bouton2(Bouton2'first+1)).piece; --m = numero de la pièce présente sur la case, m=0 si case vide
- if m /= 0 then
- retirer(V,VP,m);--si une pièce est présente sur la case : retirer la pièce
- end if;
- end if;
- end;
- end loop;
- if PartieGagne(VP) then--si toutes les pièces ont été placés afficher fenetre de victoire
- raise EX_WIN;
- end if;
- exit;
- exception
- when EX_FinJeu => exit;
- when EX_Restart => CacherFenetre(Facc);
- CacherFenetre(Freg);
- close(f);
- close(g);
- when constraint_error => CacherFenetre(Facc);
- when ADA.IO_EXCEPTIONS.STATUS_ERROR => close(f);
- close(g);
- when EX_WIN => CacherFenetre(Fjeu);
- MontrerFenetre(Fwin);
- declare
- Bouton5 : string := AttendreBouton(Fwin);
- begin
- if Bouton5 = "BoutonQuitter" then
- exit;
- elsif Bouton5 = "BoutonNewGame" then
- CacherFenetre(Fwin);
- tromper := false;
- BoutonDebut := " ";
- end if;
- end;
- end;
- end loop;
- end twist_graph2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement