using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp16
{
    internal class App
    {

        //생성자
        
        public App() 
        {
            Hero hero = new Hero();

            Console.WriteLine();

            hero.HitDamage(3, (isDie) =>
            {
                Console.WriteLine("상태: {0}",isDie);
            });

            Console.WriteLine();

            hero.HitDamage(3, (isDie) =>
            {
                Console.WriteLine("상태: {0}", isDie);
            });




        }
        
       
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp16
{
    internal class Hero
    {
        int hp;
        int maxHp=4;
        string isDie;
        public Hero()
        {
            Console.WriteLine("플레이어가 생성되었습니다.");
            hp = maxHp;
        }
        public void HitDamage(int damage, Action<string> callback)
        {
            

            hp -= damage;
            Console.WriteLine("플레이어가 데미지를 입었습니다.");
            
            Console.WriteLine("HP: {0}/{1}", hp, maxHp);


            if (hp <= 0) callback(isDie = "죽음");
            else { callback(isDie = "생존"); };
            
        }
    }
}

반응형

'KDT > C# 프로그래밍' 카테고리의 다른 글

아이템 정보 저장하기  (0) 2023.07.27
대리자 연습(3)  (0) 2023.07.27
대리자 연습(1)  (0) 2023.07.27
싱글톤 패턴으로 대리자 호출하기(2)  (0) 2023.07.27
싱글톤 패턴으로 대리자 호출하기  (0) 2023.07.27

+ Recent posts