Advertisement
Guest User

Untitled

a guest
Jan 25th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 7.33 KB | None | 0 0
  1. with p_fenbase ; use p_fenbase ;
  2. with Forms ; use Forms;
  3. with ada.calendar; use ada.calendar;
  4. with p_twist; use p_twist;
  5. with ada.io_exceptions; use ada.io_exceptions;
  6. with p_vue_graph; use p_vue_graph;
  7. with text_io; use text_io;
  8. use p_twist.p_int_io;
  9. use p_twist.p_piece_io;
  10.  
  11. procedure twist_graph2 is
  12.   Facc, FJeu,Freg,Fwin : TR_Fenetre; --Fenêtres
  13.   V : TV_Grille; --Grille
  14.   f : text_io.file_type; --fichier level
  15.   VP : TV_Piece; --Pièces
  16.   g : p_piece_io.file_type; --fichier pièces
  17.   matRotD,matRetH,matRotG,matRetV : TV_Matrice; --matrice contenant une pièce transformée
  18.   possible : boolean;--booléen de placement
  19.   n : level;--numero du niveau
  20.   nump,m : T_NumPiece; --numero piece
  21.   EX_FinJeu,EX_WIN,EX_Restart : exception;--exception
  22.   NewLine    : constant Character  := Character'Val (10);--retour a la ligne lors d'affichage
  23.   tromper : boolean := false;--booléen pour réentrer n
  24.   BoutonDebut : string(1..7);--choix à l'accueil
  25. begin
  26.   loop
  27.     begin
  28.       --ouverture fichier
  29.       open(f,in_file,"defis.txt");
  30.       open(g,in_file,"fpieces");
  31.       --initialisation des fenêtres
  32.       InitialiserFenetres;
  33.       InitFenetreAccueil(Facc);
  34.       InitFenetreWin(Fwin);
  35.       InitFenetreJeu(FJeu);
  36.       InitRegle(Freg);
  37.       --si l'utilisateur à mal saisi n mettre des indications
  38.       if tromper then
  39.         ChangerTexte(FAcc,"Erreur","Erreur les niveaux vont");
  40.         ChangerTexte(FAcc,"Erreur2","de 1 a 101");
  41.       end if;
  42.       MontrerFenetre(Facc);--affichage fenetre accueil
  43.       tromper := true;
  44.       CreeVectPiece(g,VP);--creation de VP via g
  45.       BoutonDebut := "       ";
  46.       while BoutonDebut /= "BoutonV" and BoutonDebut /= "BoutonQ" loop --tant que l'utilisateur ne quitte ou ne valide pas
  47.       --bloc traitement fenetre accueil
  48.          declare
  49.            Bouton : string := (AttendreBouton(Facc));--recuperation information bouton
  50.          begin
  51.            if (Bouton'last-Bouton'first) = (BoutonDebut'last-BoutonDebut'first) then
  52.              BoutonDebut := Bouton;
  53.            end if;
  54.            if Bouton = "BoutonR" then
  55.              MontrerFenetre(Freg);--affichage fenetre regle
  56.              tromper := false;
  57.            --bloc traitement fenetre regle
  58.            declare
  59.              Bouton1 : string := (AttendreBouton(Freg));
  60.            begin
  61.              if Bouton1 = "BoutonQuitter" then
  62.                raise EX_Restart;
  63.              end if;
  64.            end;
  65.            elsif Bouton = "BoutonQ" then
  66.              raise EX_FinJeu;
  67.            elsif Bouton = "BoutonV" then
  68.              n := integer'value(ConsulterContenu(Facc,"niveau"));--recuperation numero niveau
  69.              CacherFenetre(Facc);
  70.              InitJeu(f,n,V);--initialise la grille en fonction du niveau via f
  71.              MontrerFenetre(Fjeu);--affiche la fenetre de jeu
  72.              InitNiveau(Fjeu,f,n,V);--initialise le niveau
  73.              ReinitTransfo(Fjeu);--reinitialise les exemples de transformations
  74.              AfficheGrille(Fjeu,V,VP);--affiche la grille
  75.              AffichePiecesNonPlacees(Fjeu,VP);--affiche les pièces non placés
  76.            end if;
  77.          end;
  78.        end loop;
  79.        while not PartieGagne(VP) loop
  80.        --bloc traitement fenetre jeu
  81.          declare
  82.            Bouton2 : String := (AttendreBouton(Fjeu));
  83.          begin
  84.        --reinitialisation
  85.            ChangerContenu(Fjeu,"Messageerreur","");
  86.            ReinitTransfo(Fjeu);
  87.            --affichage
  88.            AfficheGrille(Fjeu,V,VP);
  89.            AffichePiecesNonPlacees(Fjeu,VP);
  90.            if Bouton2 = "BoutonQuitter" then
  91.              raise EX_FinJeu;--fermer le jeu
  92.            end if;
  93.            if Bouton2 = "BoutonRegle" then
  94.              MontrerFenetre(Freg);--affiche les règles
  95.              declare
  96.                Bouton3 : string := (AttendreBouton(Freg));
  97.              begin
  98.                if Bouton3 = "BoutonQuitter" then
  99.                  CacherFenetre(Freg);
  100.                end if;
  101.              end;
  102.            end if;
  103.            if Bouton2(Bouton2'first) = 'P' or Bouton2(Bouton2'first) = 'N' then --si selection d'une piece
  104.              nump := integer'value(Bouton2(Bouton2'first+1..Bouton2'first+2));--recuperation numero de piece
  105.              AffichePieceTourner(Fjeu,VP,nump,matRotD,matRotG,matRetV,matRetH);--affiche 4 transformations possibles de la pièces
  106.              declare
  107.                Bouton4 : String := (AttendreBouton(Fjeu));
  108.              begin
  109.                if Bouton4(Bouton4'first) = 'R' or Bouton4(Bouton4'first) = 'T'  then--si une transformation est selectionnee : l'effectuee
  110.                  if integer'value(Bouton4(Bouton4'first+1..Bouton4'first+2)) = 1 then
  111.                    rotG(VP,nump);
  112.                  elsif integer'value(Bouton4(Bouton4'first+1..Bouton4'first+2)) = 2 then
  113.                    rotD(VP,nump);
  114.                  elsif integer'value(Bouton4(Bouton4'first+1..Bouton4'first+2)) = 3 then
  115.                    retH(VP,nump);
  116.                  else
  117.                    retV(VP,nump);
  118.                  end if;
  119.                elsif Bouton4(Bouton4'first) = 'C' or Bouton4(Bouton4'first) = 'D'  then --si une case est selectionnee placé la pièce
  120.                  placer(V,VP,nump,integer'value(Bouton4(Bouton4'first+3..Bouton4'first+3)),Bouton4(Bouton4'first+1),possible);
  121.                  if not possible then --si placement impossible afficher message d'erreur
  122.                    ChangerContenu(Fjeu,"Messageerreur",NewLine&"               Impossible de placer la piece");
  123.                  end if;
  124.                  --reinitialisation
  125.                  ReinitTransfo(Fjeu);
  126.                  --affichage
  127.                  AfficheGrille(Fjeu,V,VP);
  128.                  AffichePiecesNonPlacees(Fjeu,VP);
  129.                end if;
  130.              end;
  131.            elsif Bouton2(Bouton2'first) = 'C' or Bouton2(Bouton2'first) = 'D' then --si une case est selectionnee
  132.              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
  133.              if m /= 0 then
  134.                retirer(V,VP,m);--si une pièce est présente sur la case : retirer la pièce
  135.              end if;
  136.            end if;
  137.          end;
  138.        end loop;
  139.        if PartieGagne(VP) then--si toutes les pièces ont été placés afficher fenetre de victoire
  140.          raise EX_WIN;
  141.        end if;
  142.        exit;
  143.      exception
  144.        when EX_FinJeu => exit;
  145.        when EX_Restart => CacherFenetre(Facc);
  146.                           CacherFenetre(Freg);
  147.                           close(f);
  148.                           close(g);
  149.        when constraint_error => CacherFenetre(Facc);
  150.        when ADA.IO_EXCEPTIONS.STATUS_ERROR => close(f);
  151.                                               close(g);
  152.        when EX_WIN => CacherFenetre(Fjeu);
  153.                       MontrerFenetre(Fwin);
  154.                       declare
  155.                         Bouton5 : string := AttendreBouton(Fwin);
  156.                       begin
  157.                         if Bouton5 = "BoutonQuitter" then
  158.                           exit;
  159.                         elsif Bouton5 = "BoutonNewGame" then
  160.                           CacherFenetre(Fwin);
  161.                           tromper := false;
  162.                           BoutonDebut := "       ";
  163.                         end if;
  164.                       end;
  165.     end;
  166.     end loop;
  167.  end twist_graph2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement