with Farm ;
with Gada.Text_IO ;
procedure Mission6 is
package F renames Farm ;
package Txt renames GAda.Text_IO ;
procedure Affiche_Base (Jeu : F.T_Jeu) is
begin
Txt.Put_Line("Bienvenue dans Top-Farmer !") ;
Txt.New_Line ;
Txt.Put_Line(" Score : " & Integer'Image(Jeu.Score)) ;
Txt.Put_Line(" Argent : " & Integer'Image(Jeu.Argent) & " chbufs." ) ;
Txt.New_Line ;
if Jeu.Nombre_Enclos = 0 then
Txt.Put_Line(" Aucun enclos.") ;
else
Txt.Put_Line(" La ferme est composée de " & Integer'Image(Jeu.Nombre_Enclos) & " enclos.") ;
end if ;
end Affiche_Base ;
procedure Affiche_Plan (Plan : F.T_Plan) is
Symbole : Character ;
Enclos : F.T_Enclos ;
begin
for Rangee in Plan'Range(1) loop
for Col in Plan'Range(2) loop
Enclos := Plan(Rangee, Col) ;
if Enclos.Bebetes = 0 then Symbole := '.' ;
else
case Plan(Rangee, Col).Animal is
when F.Canard => Symbole := 'C' ;
when F.Vache => Symbole := 'V' ;
when F.Poule => Symbole := 'P' ;
when F.Mouton => Symbole := 'M' ;
end case ;
end if ;
Txt.Put(Symbole) ;
end loop ;
Txt.New_Line ;
end loop ;
end Affiche_Plan ;
procedure Affiche (Jeu : F.T_Jeu) is
begin
Affiche_Base(Jeu) ;
Affiche_Plan(Jeu.Plan) ;
end Affiche ;
function Cout_Enclos (Aire : Float ; Animal : F.T_Animal) return Integer is
Cout_Par_M2 : Float ;
begin
case Animal is
when F.Canard => Cout_Par_M2 := 2.0 ;
when F.Vache => Cout_Par_M2 := 6.0 ;
when F.Poule => Cout_Par_M2 := 1.5 ;
when F.Mouton => Cout_Par_M2 := 4.0 ;
end case ;
return Integer(Cout_Par_M2 * Aire) ;
end Cout_Enclos ;
procedure Ajoute_Enclos (Aire : Float ; Animal : F.T_Animal ; Jeu : in out F.T_Jeu ; Ligne : Integer ; Colonne : Integer) is
Cout : Integer ;
begin
Cout := Cout_Enclos(Aire, Animal) ;
if Jeu.Argent >= Cout then
Jeu.Argent := Jeu.Argent - Cout ;
Jeu.Nombre_Enclos := Jeu.Nombre_Enclos + 1 ;
Jeu.Plan(Ligne, Colonne) := ( Superficie => Aire, Animal => Animal, Bebetes => 8) ;
Txt.Put_Line("Enclos ajouté. Coût = " & Integer'Image(Cout) & " chbufs") ;
else
Txt.Put_Line("Pas assez d'argent. Coût = " & Integer'Image(Cout) & " chbufs") ;
end if ;
end Ajoute_Enclos ;
procedure Bonus (Jeu : in out F.T_Jeu) is
begin
for Rangee in Jeu.Plan'Range(1) loop
for Col in Jeu.Plan'Range(2) loop
Jeu.Score := Jeu.Score + 100 * Jeu.Plan(Rangee,Col).Bebetes ;
end loop ;
end loop ;
end Bonus ;
procedure Plus_De_Carnard (Jeu : in out F.T_Jeu) is
Enclos : F.T_Enclos ;
begin
for Ligne in Jeu.Plan'Range(1) loop
for Colonne in Jeu.Plan'Range(2) loop
Enclos := Jeu.Plan(Ligne, Colonne) ;
case Enclos.Animal is
when F.Canard =>
Enclos.Animal := F.Poule ;
Enclos.Bebetes := 1 ;
Jeu.Plan(Ligne, Colonne) := Enclos ;
when others => null ;
end case ;
end loop ;
end loop ;
end Plus_De_Carnard ;
procedure Reproduction (Jeu : in out F.T_Jeu) is
Enclos : F.T_Enclos ;
Pcent : Integer ;
begin
for Ligne in Jeu.Plan'Range(1) loop
for Colonne in Jeu.Plan'Range(2) loop
Enclos := Jeu.Plan(Ligne, Colonne) ;
if Enclos.Bebetes > 0 then
case Enclos.Animal is
when F.Poule => Pcent := 100 ;
when F.Canard => Pcent := 80 ;
when F.Vache => Pcent := 40 ;
when F.Mouton => Pcent := 60 ;
end case ;
Enclos.Bebetes := (Enclos.Bebetes * (100 + Pcent)) / 100 ;
Jeu.Plan(Ligne, Colonne) := Enclos ;
end if ;
end loop ;
end loop ;
end Reproduction ;
function Lister(Jeu : F.T_Jeu) return F.T_Liste_Enclos is
Resultat : F.T_Liste_Enclos(1..Jeu.Nombre_Enclos) ;
Compte : Integer := 0 ;
begin
for Ligne in Jeu.Plan'Range(1) loop
for Colonne in Jeu.Plan'Range(2) loop
if Jeu.Plan(Ligne, Colonne).Bebetes > 0 then
Compte := Compte + 1 ;
Resultat(Compte) := Jeu.Plan(Ligne, Colonne) ;
end if ;
end loop ;
end loop ;
return Resultat ;
end Lister ;
procedure Afficher_Liste (Liste : F.T_Liste_Enclos) is
Enclos : F.T_Enclos ;
begin
for Index in Liste'Range loop
Enclos := Liste(Index) ;
Txt.Put_Line( "Enclos " & Integer'Image(Index) & " : " & Integer'Image(Enclos.Bebetes)
& " " & F.T_Animal'Image(Enclos.Animal) & "(s)") ;
end loop ;
end Afficher_Liste ;
function Min_Enclos (Liste : F.T_Liste_Enclos) return Integer is
Enclos : F.T_Enclos ;
Min_Animaux : Integer := Integer'Last ;
Indice_Min : Integer ;
begin
for Index in Liste'Range loop
Enclos := Liste(Index) ;
if Enclos.Bebetes < Min_Animaux then
Min_Animaux := Enclos.Bebetes ;
Indice_Min := Index ;
end if ;
end loop ;
return Indice_Min ;
end Min_Enclos ;
function Rangee_Vide (Jeu : F.T_Jeu) return Integer is
Trouve : Boolean := False ;
No_Rangee : Integer := Jeu.Plan'First(1) ;
Resultat : Integer ;
begin
while (not Trouve) and No_Rangee <= Jeu.Plan'Last(1) loop
if Jeu.Plan(No_Rangee, 1).Bebetes = 0 then
Resultat := No_Rangee ;
Trouve := True ;
else
No_Rangee := No_Rangee + 1 ;
end if ;
end loop ;
if not Trouve then
Resultat := -1 ;
end if ;
return Resultat ;
end Rangee_Vide ;
function Assortie (Plan : F.T_Plan ; Rangee : Integer) return Boolean is
Resultat : Boolean ;
Total : Integer := 0 ;
begin
Resultat := ( Plan(Rangee, Plan'Last(2)).Bebetes > 0 ) ;
if Resultat then
for Col in Plan'Range(2) loop
case Plan(Rangee, Col).Animal is
when F.Poule => Total := Total + 1 ;
when F.Mouton => Total := Total + 10 ;
when F.Vache => Total := Total + 100 ;
when F.Canard => Total := Total + 1000 ;
end case ;
end loop ;
Resultat := (Total = 1111) ;
end if ;
return Resultat ;
end Assortie ;
function Nb_Assorties (Jeu : F.T_Jeu) return Integer is
Compte : Integer := 0 ;
begin
for Rangee in Jeu.Plan'Range(1) loop
if Assortie(Jeu.Plan, Rangee) then
Compte := Compte + 1 ;
end if ;
end loop ;
return Compte ;
end Nb_Assorties ;
procedure Bonus_Assorti (Jeu : in out F.T_Jeu) is
Bonus : Integer ;
begin
case Nb_Assorties(Jeu) is
when 0 => Bonus := 0 ;
when 1 => Bonus := 5_000 ;
when 2 => Bonus := 20_000 ;
when 3 => Bonus := 30_000 ;
when 4 => Bonus := 50_000 ;
when 5 => Bonus := 80_000 ;
when 6 => Bonus := 100_000 ;
when others => Bonus := 0 ; end case ;
Jeu.Score := Jeu.Score + Bonus ;
end Bonus_Assorti ;
Enclos_Vide : F.T_Enclos := ( Superficie => 100.0,
Animal => F.Poule,
Bebetes => 0 ) ;
Plan_Initial : F.T_Plan(1..6, 1..4) := (others => (others => Enclos_Vide)) ;
Jeu : F.T_Jeu := ( Score => 0,
Argent => 8000,
Nombre_Enclos => 0,
Plan => Plan_Initial ) ;
begin
Affiche_Base(Jeu) ;
Affiche_Plan(Jeu.Plan) ;
Ajoute_Enclos(100.0, F.Poule, Jeu, 1, 1) ;
Ajoute_Enclos(100.0, F.Poule, Jeu, 1, 2) ;
Ajoute_Enclos(200.0, F.Canard, Jeu, 2, 1) ;
Ajoute_Enclos(200.0, F.Vache, Jeu, 4, 1) ;
Ajoute_Enclos(100.0, F.Mouton, Jeu, 4, 2) ;
Ajoute_Enclos(100.0, F.Poule, Jeu, 4, 3) ;
Ajoute_Enclos(100.0, F.Canard, Jeu, 6, 1) ;
Ajoute_Enclos(100.0, F.Mouton, Jeu, 6, 2) ;
Ajoute_Enclos(5000.0, F.Mouton, Jeu, 6, 4) ;
Bonus(Jeu) ;
Affiche(Jeu) ;
Plus_De_Carnard(Jeu) ;
Affiche(Jeu) ;
Reproduction(Jeu) ;
Bonus(Jeu) ;
Affiche(Jeu) ;
Afficher_Liste( Lister(Jeu) ) ;
Txt.Put_Line("Enclos le moins peuplé : " & Integer'Image(Min_Enclos( Lister(Jeu) ))) ;
Txt.Put_Line("Une rangée vide : " & Integer'Image( Rangee_Vide(Jeu))) ;
Ajoute_Enclos(100.0, F.Canard, Jeu, 4,4) ;
Bonus_Assorti(Jeu) ;
Affiche(Jeu) ;
Ajoute_Enclos(100.0, F.Canard, Jeu, 6,3) ;
Ajoute_Enclos(100.0, F.Vache, Jeu, 6,4) ;
Bonus_Assorti(Jeu) ;
Affiche(Jeu) ;
end Mission6 ;