Advertisement
gandalfbialy

Untitled

Apr 25th, 2025
248
0
Never
Not a member of Pastebin yet?Sign Up, it unlocks many cool features!
  1. usingSystem;
  2.  
  3. namespace Gra
  4. {
  5.     publicabstractclass Postac
  6.     {
  7.         publicstring Nazwa;
  8.         publicint Hp;
  9.  
  10.         public Postac(string nazwa, int hp)
  11.         {
  12.             this.Nazwa= nazwa;
  13.             this.Hp= hp;
  14.         }
  15.  
  16.         publicabstractvoid PrzedstawSie();
  17.     }
  18.  
  19.     publicinterface IBohater
  20.     {
  21.         void Walcz();
  22.     }
  23.  
  24.     publicclass Wojownik : Postac, IBohater
  25.     {
  26.         public Wojownik(string nazwa, int hp):base(nazwa, hp){}
  27.  
  28.         publicoverridevoid PrzedstawSie()
  29.         {
  30.             Console.WriteLine($"Witaj! Jestem {Nazwa} i mam aż {Hp} hp➕!!");
  31.         }
  32.  
  33.         publicvoid Walcz()
  34.         {
  35.             Console.WriteLine($"Roaaaaaaar!! {Nazwa} rzuca oszczepem w przeciwników! 😎");
  36.         }
  37.     }
  38.  
  39.     publicclass Program()
  40.     {
  41.         staticvoid Main(string[] args)
  42.         {
  43.             Wojownik wojownik =new Wojownik("Ragnarok", 95);
  44.             Postac wojownik2 =new Wojownik("Inny wojownik", 12);
  45.  
  46.             wojownik.PrzedstawSie();
  47.             wojownik.Walcz();
  48.  
  49.             wojownik2.PrzedstawSie();
  50.             // wojownik2.Walcz();
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement
close