Advertisement
gandalfbialy

Untitled

Apr 25th, 2025
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Gra
  4. {
  5.     public abstract class Postac
  6.     {
  7.         public string Nazwa;
  8.         public int Hp;
  9.  
  10.         public Postac(string nazwa, int hp)
  11.         {
  12.             this.Nazwa = nazwa;
  13.             this.Hp = hp;
  14.         }
  15.  
  16.         public abstract void PrzedstawSie();
  17.     }
  18.  
  19.     public interface IBohater
  20.     {
  21.         void Walcz();
  22.     }
  23.  
  24.     public class Wojownik : Postac, IBohater
  25.     {
  26.         public Wojownik(string nazwa, int hp) : base(nazwa, hp) { }
  27.  
  28.         public override void PrzedstawSie()
  29.         {
  30.             Console.WriteLine($"Witaj! Jestem {Nazwa} i mam aż {Hp} hp➕!!");
  31.         }
  32.  
  33.         public void Walcz()
  34.         {
  35.             Console.WriteLine($"Roaaaaaaar!! {Nazwa} rzuca oszczepem w przeciwników! 😎");
  36.         }
  37.     }
  38.  
  39.     public class Program()
  40.     {
  41.         static void 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