Advertisement
barnabe0057

TP_Fonctions

Feb 20th, 2022
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. using System;
  2.  
  3. namespace MNS // Note: actual namespace depends on the project name.
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             float aire = CalculAireRectangle(8f, 5f);
  10.  
  11.             AfficherMonstreAleatoire();
  12.             Thread.Sleep(100);
  13.             AfficherMonstreAleatoire();
  14.  
  15.             Console.WriteLine(aire);
  16.  
  17.             Console.WriteLine(CalculPuissance(2,10));
  18.         }
  19.  
  20.         public static float CalculAireRectangle(float largeur, float longueur)
  21.         {
  22.             return largeur * longueur;
  23.         }
  24.  
  25.         public static void AfficherMonstreAleatoire()
  26.         {
  27.             Random r = new Random();
  28.  
  29.             int nombreAleatoire = r.Next(0, 3);
  30.             string nomMonstre = "";
  31.             string adjectifMonstre = "";
  32.  
  33.             switch (nombreAleatoire)
  34.             {
  35.                 case 0:
  36.                     nomMonstre = "Gobelin";
  37.                     break;
  38.                 case 1:
  39.                     nomMonstre = "Dragon";
  40.                     break;
  41.                 case 2:
  42.                     nomMonstre = "Zombie";
  43.                     break;
  44.                 default:
  45.                     break;
  46.             }
  47.  
  48.             nombreAleatoire = r.Next(0, 3);
  49.  
  50.             switch (nombreAleatoire)
  51.             {
  52.                 case 0:
  53.                     adjectifMonstre = "enragé";
  54.                     break;
  55.                 case 1:
  56.                     adjectifMonstre = "géant";
  57.                     break;
  58.                 case 2:
  59.                     adjectifMonstre = "violet";
  60.                     break;
  61.                 default:
  62.                     break;
  63.             }
  64.  
  65.             Console.WriteLine(nomMonstre + " " + adjectifMonstre);
  66.         }
  67.  
  68.         public static int CalculPuissance(int nombre, int puissance)
  69.         {
  70.             int resultat = 1;
  71.  
  72.             for (int i = 0; i < puissance; i++)
  73.             {
  74.                 resultat *= nombre;
  75.             }
  76.  
  77.             return resultat;
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement