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;
- V : TV_Grille;
- f : text_io.file_type;
- VP : TV_Piece;
- g : p_piece_io.file_type;
- matRotD,matRetH,matRotG,matRetV : TV_Matrice;
- possible : boolean;
- n : level;
- nump,m : T_NumPiece;
- EX_FinJeu,EX_WIN,EX_Restart : exception;
- NewLine : constant Character := Character'Val (10);
- tromper : boolean := false;
- BoutonDebut : string(1..7);
- begin
- loop
- begin
- open(f,in_file,"defis.txt");
- open(g,in_file,"fpieces");
- InitialiserFenetres;
- InitFenetreAccueil(Facc);
- InitFenetreWin(Fwin);
- InitFenetreJeu(FJeu);
- InitRegle(Freg);
- if tromper then
- ChangerTexte(FAcc,"Erreur","Erreur les niveaux vont");
- ChangerTexte(FAcc,"Erreur2","de 1 a 101");
- end if;
- MontrerFenetre(Facc);
- tromper := true;
- CreeVectPiece(g,VP);
- BoutonDebut := " ";
- while BoutonDebut /= "BoutonV" and BoutonDebut /= "BoutonQ" loop
- declare
- Bouton : string := (AttendreBouton(Facc));
- begin
- if (Bouton'last-Bouton'first) = (BoutonDebut'last-BoutonDebut'first) then
- BoutonDebut := Bouton;
- end if;
- if Bouton = "BoutonR" then
- MontrerFenetre(Freg);
- tromper := false;
- 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"));
- CacherFenetre(Facc);
- InitJeu(f,n,V);
- MontrerFenetre(Fjeu);
- InitNiveau(Fjeu,f,n,V);
- ReinitTransfo(Fjeu);
- AfficheGrille(Fjeu,V,VP);
- AffichePiecesNonPlacees(Fjeu,VP);
- end if;
- end;
- end loop;
- while not PartieGagne(VP) loop
- declare
- Bouton2 : String := (AttendreBouton(Fjeu));
- begin
- ChangerContenu(Fjeu,"Messageerreur","");
- ReinitTransfo(Fjeu);
- AfficheGrille(Fjeu,V,VP);
- AffichePiecesNonPlacees(Fjeu,VP);
- if Bouton2 = "BoutonQuitter" then
- raise EX_FinJeu;
- end if;
- if Bouton2 = "BoutonRegle" then
- MontrerFenetre(Freg);
- 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
- nump := integer'value(Bouton2(Bouton2'first+1..Bouton2'first+2));
- AffichePieceTourner(Fjeu,VP,nump,matRotD,matRotG,matRetV,matRetH);
- declare
- Bouton4 : String := (AttendreBouton(Fjeu));
- begin
- if Bouton4(Bouton4'first) = 'R' or Bouton4(Bouton4'first) = 'T' then
- 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
- placer(V,VP,nump,integer'value(Bouton4(Bouton4'first+3..Bouton4'first+3)),Bouton4(Bouton4'first+1),possible);
- if not possible then
- ChangerContenu(Fjeu,"Messageerreur",NewLine&" Impossible de placer la piece");
- end if;
- ReinitTransfo(Fjeu);
- AfficheGrille(Fjeu,V,VP);
- AffichePiecesNonPlacees(Fjeu,VP);
- end if;
- end;
- elsif Bouton2(Bouton2'first) = 'C' or Bouton2(Bouton2'first) = 'D' then
- m := V(integer'value(Bouton2(Bouton2'first+2..Bouton2'first+3)),Bouton2(Bouton2'first+1)).piece;
- if m /= 0 then
- retirer(V,VP,m);
- end if;
- end if;
- end;
- end loop;
- if PartieGagne(VP) then
- 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