NS2A2

Bài 2 C#

Dec 20th, 2020 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 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 Test
  8. {  
  9.     class Dog
  10.     {
  11.         private string _name;
  12.         private int _MP = 100;
  13.  
  14.         public string Name { get; set; }
  15.         public int MP = 100;
  16.  
  17.         /*public Dog(string name)
  18.         {
  19.             Name = name;
  20.         }*/
  21.        
  22.         public void InputName()
  23.         {
  24.             Name = Console.ReadLine();
  25.         }
  26.         public void ShowMP()
  27.         {
  28.             Console.WriteLine("MP = " + MP);
  29.         }
  30.         public void Bark()
  31.         {
  32.             if (Name.Length != 0)
  33.             {
  34.                 Console.WriteLine(Name + " bark");
  35.                 MP -= 20;
  36.             }
  37.             else Console.WriteLine("Sorry");
  38.         }
  39.  
  40.     }
  41.     class RunMain
  42.     {
  43.         static void Main(string[] args)
  44.         {
  45.             Dog a = new Dog();
  46.             a.InputName();
  47.             a.Bark();
  48.             a.ShowMP();
  49.             a.Bark();
  50.             a.ShowMP();
  51.             a.Bark();
  52.             a.ShowMP();
  53.             Console.ReadKey();
  54.         }
  55.     }
  56. }
  57.  
Add Comment
Please, Sign In to add comment