Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Krzysztof_Paluch
  8. {
  9.     class Program
  10.     {
  11.  
  12.  
  13.          static void Main(string[] args)
  14.         {
  15.             Wojownik postac1 = new Wojownik("Gracz1");
  16.             Wojownik postac2 = new Wojownik("Gracz2");
  17.  
  18.  
  19.             postac1.Wyswietl();
  20.             Console.WriteLine("");
  21.             postac2.Atak();
  22.             postac2.Wyswietl();
  23.  
  24.  
  25.             //postac1.nazwa = "Gracz1";
  26.             //postac1.Wyswietl();
  27.             //postac1.Atak();
  28.             //postac1.Wyswietl();
  29.             //postac1.Atak();
  30.             //postac1.Wyswietl();
  31.  
  32.         }
  33.  
  34.  
  35.         class Wojownik
  36.  
  37.         {
  38.             public string nazwa;
  39.             private int sila;
  40.             private int zdrowie;
  41.             private bool zyje;
  42.  
  43.             public Wojownik()
  44.             {
  45.             }
  46.  
  47.             public Wojownik(string n) //// Przeciążenie n, dodanie wartosci do nawiasu
  48.             {
  49.                 nazwa = n; /// oraz dodanie do konstruktora
  50.                 sila = 10;
  51.                 zdrowie = 100;
  52.                 zyje = true;
  53.             }
  54.  
  55.             public void Atak()
  56.             {
  57.                 zdrowie -= 10;
  58.                 if (this.zdrowie <= 0)
  59.                 {
  60.                     zyje = false;
  61.                 }
  62.             }
  63.             public void Leczenie()
  64.             {
  65.                 if (zdrowie<100)
  66.                 {
  67.                     zdrowie += 30;
  68.  
  69.                     if (zdrowie>100)
  70.                     {
  71.                         zdrowie = 100;
  72.                     }
  73.                 }
  74.             }
  75.  
  76.             public void Wyswietl()
  77.             {
  78.                 Console.WriteLine($"Nazwa: {nazwa}");
  79.                 Console.WriteLine($"Sila: {sila} ");
  80.                 Console.WriteLine($"Zdrowie: {zdrowie}");
  81.                 Console.WriteLine($"Zyje: {zyje}");
  82.  
  83.             }
  84.  
  85.  
  86.         }
  87.  
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement