Advertisement
moadel

Untitled

Feb 6th, 2021
2,426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 5.45 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.       end if;
  90.      
  91.      
  92.      
  93.       if Dir = Sud then
  94.    
  95.      if labyr(Pac.Posx,Pac.Posy-1)=mur  then
  96.        
  97.        
  98.         Mettre_Mur(Pac,Labyr);
  99.        
  100.      elsif  Labyr(Pac.Posx,Pac.Posy-1) = Cerise then
  101.        
  102.        
  103.        
  104.         Dessinerbloc(Pac.Posx,Pac.Posy-1,Lab.Vide);
  105.         Pac.Posy:=Pac.Posy-1;
  106.         Dessinerbloc(Pac.Posx,Pac.Posy,Lab.Pacman);
  107.         Dessinerlabyrinthe(Labyr);
  108.        
  109.      elsif  Labyr(Pac.Posx,Pac.Posy-1) = Vide then
  110.        
  111.         Pac.Posy:=Pac.Posy-1;
  112.         Dessinerbloc(Pac.Posx,Pac.Posy,Lab.Pacman);
  113.         Dessinerlabyrinthe(Labyr);
  114.        
  115.      end if;
  116.       end if;
  117.      
  118.      
  119.       if Dir = Est then
  120.    
  121.    
  122.      if labyr(Pac.Posx+1,Pac.Posy)=mur then
  123.        
  124.        
  125.         Mettre_Mur(Pac,Labyr);
  126.        
  127.      elsif  Labyr(Pac.Posx+1,Pac.Posy) = Cerise then
  128.        
  129.        
  130.        
  131.         Dessinerbloc(Pac.Posx+1,Pac.Posy,Lab.Vide);
  132.         Pac.Posx:=Pac.Posx+1;
  133.         Dessinerbloc(Pac.Posx,Pac.Posy,Lab.Pacman);
  134.         Dessinerlabyrinthe(Labyr);
  135.        
  136.      elsif  Labyr(Pac.Posx+1,Pac.Posy) = Vide then
  137.        
  138.         Pac.Posx:=Pac.Posx+1;
  139.         Dessinerbloc(Pac.Posx,Pac.Posy,Lab.Pacman);
  140.         Dessinerlabyrinthe(Labyr);
  141.        
  142.      end if;
  143.       end if;
  144.      
  145.      
  146.       if Dir = Ouest then
  147.    
  148.      if  labyr(Pac.Posx-1,Pac.Posy)=mur then
  149.        
  150.         Mettre_Mur(Pac,Labyr);
  151.        
  152.      elsif  Labyr(Pac.Posx-1,Pac.Posy) = Cerise then
  153.        
  154.        
  155.        
  156.         Dessinerbloc(Pac.Posx-1,Pac.Posy,Lab.Vide);
  157.         Pac.Posx:=Pac.Posx-1;
  158.         Dessinerbloc(Pac.Posx,Pac.Posy,Lab.Pacman);
  159.         Dessinerlabyrinthe(Labyr);
  160.        
  161.      elsif  Labyr(Pac.Posx-1,Pac.Posy) = Vide then
  162.        
  163.         Pac.Posx:=Pac.Posx-1;
  164.         Dessinerbloc(Pac.Posx,Pac.Posy,Lab.Pacman);
  165.         Dessinerlabyrinthe(Labyr);
  166.        
  167.      end if;
  168.       end if;
  169.      
  170.      
  171.    end Sous_Deplacement;
  172.    
  173.  
  174.    procedure Deplacement(labyr:in Lab.T_Lab; Pac: in out Lab.T_Pacman;Dir2:in out T_Direction) is
  175.      
  176.    begin
  177.      
  178.       case Dir2 is
  179.    
  180.      when Nord => Sous_Deplacement(Labyr,Pac,Nord);
  181.        
  182.      when Sud => Sous_Deplacement(Labyr,Pac,Sud);
  183.        
  184.      when Est => Sous_Deplacement(Labyr,Pac,Est);
  185.        
  186.      when Ouest => Sous_Deplacement(Labyr,Pac,Ouest);
  187.        
  188.      when Immobile => null;
  189.        
  190.       end case;
  191.      
  192.    end Deplacement;
  193.    
  194.    
  195.    
  196.    
  197.    
  198.    procedure Finjeu(L: in Integer) is
  199.      
  200.    begin
  201.       if L=0 then
  202.      Effacerecran;
  203.      Ecrireecran(10,5,"victoire"& "appuyez sur A pour recommencer");
  204.    
  205.    
  206.       else
  207.    
  208.      Effacerecran;
  209.      Ecrireecran(10,5,"game over"&"appuyez sur A pour recommencer");
  210.    
  211.    
  212.       end if;
  213.      
  214.    end Finjeu;
  215.    
  216.    
  217.    procedure Affiche_Nbcerise(Laby:in Lab.T_Lab) is
  218.       Nbrecerise:Integer;
  219.    begin
  220.       Nbrecerise:=Compter_Cerise(Laby);
  221.      
  222.      
  223.       Ecran.Ecrireecran(0,0,"nbre cerises = " & Integer'Image(Nbrecerise));
  224.      
  225.    end Affiche_Nbcerise;
  226.    
  227.    
  228.    
  229.    
  230.    
  231.    
  232.    
  233.    
  234.    
  235.    
  236.    
  237.    
  238.  
  239.    
  240.    
  241.    
  242.    
  243.    pacman:Lab.T_Pacman;
  244.    labyrinthe:Lab.T_Lab;
  245.    Direction : T_Direction;
  246.    Temps:Integer:=Gettempsecoule;
  247.    Nbcerise:Integer:=Compter_Cerise(Labyrinthe);
  248. begin
  249.    
  250.    while True loop
  251.       Initialisercarte;
  252.       Lab.Initialiserjeu(pacman,labyrinthe);
  253.       Mettreazerotimer;
  254.       while Temps<60000 and  Nbcerise/=0 and  Pacman.Nbrevies/=0  loop
  255.      Direction:=DetecterDirection;
  256.      Ecrireecran(20,12, Integer'Image(Temps));
  257.      Affiche_Nbcerise(Labyrinthe);
  258.      Deplacement(Labyrinthe,Pacman,Direction);
  259.       end loop;
  260.       Finjeu(nbcerise);
  261.       AttendretoucheA;
  262.    end loop;
  263.    
  264.    
  265. end missionpacman ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement