Advertisement
moadel

Untitled

Feb 6th, 2021
2,262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 5.40 KB | None | 0 0
  1. with Ecran ,  Lab , Carte ;
  2. use  Ecran ,  Lab , Carte ;
  3.  
  4.  
  5. with Ecran ,  Lab , Carte ;
  6. use  Ecran ,  Lab , Carte ;
  7.  
  8.  
  9. procedure missionpacman is
  10.    
  11.  
  12.  
  13.    function Compter_Cerise(Laby:in Lab.T_Lab) return integer is
  14.  
  15.       Compt:Integer:=0;
  16.      
  17.    begin
  18.      
  19.      
  20.       for Lig in laby'Range(1) loop
  21.      for Col in laby'Range(2) loop
  22.        
  23.        
  24.         if  Laby(Lig,Col)=Cerise then
  25.            Compt:=Compt+1;
  26.         else
  27.            null;
  28.            
  29.            
  30.         end if;
  31.      end loop;
  32.       end loop;
  33.       return Compt;
  34.      
  35.    end Compter_Cerise;
  36.    
  37.    
  38.    
  39.    
  40.    procedure Mettre_Mur (Pac:in out T_Pacman;Labyr:T_lab) is
  41.      
  42.    begin
  43.      
  44.       Pac.Nbrevies:=Pac.Nbrevies-1;
  45.       Suspendretimer;
  46.       Effacerecran;
  47.       Ecrireecran(20,8,"mur touche");
  48.       Reprendretimer;
  49.       Dessinerlabyrinthe(Labyr);
  50.      
  51.      
  52.    end mettre_Mur;
  53.    
  54.    
  55.    
  56.    
  57.    
  58.    procedure Sous_Deplacement (labyr:in Lab.T_Lab; Pac: in out Lab.T_Pacman;Dir:in  T_Direction) is
  59.      
  60.    begin
  61.      
  62.       Pac.Nbrevies:=Maxnbrevies;
  63.  
  64.      
  65.       if Dir=Nord then
  66.    
  67.    
  68.    
  69.      if  labyr(Pac.Posx,Pac.Posy+1) = mur  then
  70.        
  71.         Mettre_Mur(Pac,Labyr);
  72.        
  73.      elsif  Labyr(Pac.Posx,Pac.Posy+1) = Cerise then
  74.        
  75.        
  76.        
  77.         Dessinerbloc(Pac.Posx,Pac.Posy+1,Lab.Vide);
  78.         Pac.Posy:=Pac.Posy+1;
  79.         Dessinerbloc(Pac.Posx,Pac.Posy,Lab.Pacman);
  80.         Dessinerlabyrinthe(Labyr);
  81.        
  82.      elsif  Labyr(Pac.Posx,Pac.Posy+1) = Vide then
  83.        
  84.         Pac.Posy:=Pac.Posy+1;
  85.         Dessinerbloc(Pac.Posx,Pac.Posy,Lab.Pacman);
  86.         Dessinerlabyrinthe(Labyr);
  87.        
  88.      end if;
  89.    
  90.    
  91.       elsif Dir = Sud then
  92.    
  93.      if labyr(Pac.Posx,Pac.Posy-1)=mur  then
  94.        
  95.        
  96.         Mettre_Mur(Pac,Labyr);
  97.        
  98.      elsif  Labyr(Pac.Posx,Pac.Posy-1) = Cerise then
  99.        
  100.        
  101.        
  102.         Dessinerbloc(Pac.Posx,Pac.Posy-1,Lab.Vide);
  103.         Pac.Posy:=Pac.Posy-1;
  104.         Dessinerbloc(Pac.Posx,Pac.Posy,Lab.Pacman);
  105.         Dessinerlabyrinthe(Labyr);
  106.        
  107.      elsif  Labyr(Pac.Posx,Pac.Posy-1) = Vide then
  108.        
  109.         Pac.Posy:=Pac.Posy-1;
  110.         Dessinerbloc(Pac.Posx,Pac.Posy,Lab.Pacman);
  111.         Dessinerlabyrinthe(Labyr);
  112.        
  113.      end if;
  114.    
  115.    
  116.    
  117.       elsif Dir = Est then
  118.    
  119.    
  120.      if labyr(Pac.Posx+1,Pac.Posy)=mur then
  121.        
  122.        
  123.         Mettre_Mur(Pac,Labyr);
  124.        
  125.      elsif  Labyr(Pac.Posx+1,Pac.Posy) = Cerise then
  126.        
  127.        
  128.        
  129.         Dessinerbloc(Pac.Posx+1,Pac.Posy,Lab.Vide);
  130.         Pac.Posx:=Pac.Posx+1;
  131.         Dessinerbloc(Pac.Posx,Pac.Posy,Lab.Pacman);
  132.         Dessinerlabyrinthe(Labyr);
  133.        
  134.      elsif  Labyr(Pac.Posx+1,Pac.Posy) = Vide then
  135.        
  136.         Pac.Posx:=Pac.Posx+1;
  137.         Dessinerbloc(Pac.Posx,Pac.Posy,Lab.Pacman);
  138.         Dessinerlabyrinthe(Labyr);
  139.        
  140.      end if;
  141.    
  142.    
  143.    
  144.       elsif Dir = Ouest then
  145.    
  146.      if  labyr(Pac.Posx-1,Pac.Posy)=mur then
  147.        
  148.         Mettre_Mur(Pac,Labyr);
  149.        
  150.      elsif  Labyr(Pac.Posx-1,Pac.Posy) = Cerise then
  151.        
  152.        
  153.        
  154.         Dessinerbloc(Pac.Posx-1,Pac.Posy,Lab.Vide);
  155.         Pac.Posx:=Pac.Posx-1;
  156.         Dessinerbloc(Pac.Posx,Pac.Posy,Lab.Pacman);
  157.         Dessinerlabyrinthe(Labyr);
  158.        
  159.      elsif  Labyr(Pac.Posx-1,Pac.Posy) = Vide then
  160.        
  161.         Pac.Posx:=Pac.Posx-1;
  162.         Dessinerbloc(Pac.Posx,Pac.Posy,Lab.Pacman);
  163.         Dessinerlabyrinthe(Labyr);
  164.        
  165.      end if;
  166.    
  167.       elsif Dir=Immobile then
  168.    
  169.      null;
  170.    
  171.       end if;
  172.      
  173.      
  174.    end Sous_Deplacement;
  175.    
  176.  
  177.    procedure Deplacement(labyr:in Lab.T_Lab; Pac: in out Lab.T_Pacman;Dir2:in out T_Direction) is
  178.      
  179.    begin
  180.      
  181.       case Dir2 is
  182.    
  183.      when Nord => Sous_Deplacement(Labyr,Pac,Nord);
  184.        
  185.      when Sud => Sous_Deplacement(Labyr,Pac,Sud);
  186.        
  187.      when Est => Sous_Deplacement(Labyr,Pac,Est);
  188.        
  189.      when Ouest => Sous_Deplacement(Labyr,Pac,Ouest);
  190.        
  191.      when Immobile => null;
  192.        
  193.       end case;
  194.      
  195.    end Deplacement;
  196.    
  197.    
  198.    
  199.    
  200.    
  201.    procedure Finjeu(L: in Integer) is
  202.      
  203.    begin
  204.       if L=0 then
  205.      Effacerecran;
  206.      Ecrireecran(10,5,"victoire"& "appuyez sur A pour recommencer");
  207.    
  208.    
  209.       else
  210.    
  211.      Effacerecran;
  212.      Ecrireecran(10,5,"game over"&"appuyez sur A pour recommencer");
  213.    
  214.    
  215.       end if;
  216.      
  217.    end Finjeu;
  218.    
  219.    
  220.    procedure Affiche_Nbcerise(Laby:in Lab.T_Lab) is
  221.       Nbrecerise:Integer;
  222.    begin
  223.       Nbrecerise:=Compter_Cerise(Laby);
  224.      
  225.      
  226.       Ecran.Ecrireecran(0,0,"nbre cerises = " & Integer'Image(Nbrecerise));
  227.      
  228.    end Affiche_Nbcerise;
  229.    
  230.    
  231.    
  232.    
  233.    pacman:Lab.T_Pacman;
  234.    labyrinthe:T_Lab;
  235.    Direction :T_Direction;
  236.    Temps:Integer:=Gettempsecoule;
  237.    Nbcerise:Integer:=Compter_Cerise(Labyrinthe);
  238. begin
  239.    
  240.    while True loop
  241.       Initialisercarte;
  242.       Lab.Initialiserjeu(pacman,labyrinthe);
  243.       Mettreazerotimer;
  244.       while Temps<60000 and  Nbcerise/=0 and  Pacman.Nbrevies/=0  loop
  245.      Direction:=DetecterDirection;
  246.      Ecrireecran(20,12, Integer'Image(Temps));
  247.      Affiche_Nbcerise(Labyrinthe);
  248.      Deplacement(Labyrinthe,Pacman,Direction);
  249.       end loop;
  250.       Finjeu(nbcerise);
  251.       AttendretoucheA;
  252.    end loop;
  253.    
  254.    
  255. end missionpacman ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement