본문 바로가기
KDT/C# 프로그래밍

23/07/27 대리자 연습

by 잰쟁 2023. 7. 27.
728x90

App 클래스

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

namespace starcraft
{
    public class App
    {

        //생성자
        public App()
        {
            //영웅 생성
            Hero hero = new Hero();
            hero.HitDamage(3, (hp, maxHp) => {
                Console.WriteLine("진짜 공격을 받았습니다.({0}/{1})", hp, maxHp);
            });
        }
    }
}

 

Hero 클래스

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

namespace starcraft
{
    public class Hero
    {
        //맴버 
        public int hp;
        public int maxHp;
        
        //생성자
        public Hero()
        {
            Console.WriteLine("영웅이 생성되었습니다.");
            this.maxHp = 10;
            this.hp = maxHp;
        }

        //남은 체력 메서드
        public void HitDamage(int damage,Action<int,int> callback)
        {           
            Console.WriteLine("(-{0}) 데미지를 받았습니다.",damage); //진짜로 데미지 받은거 아님
            this.hp -= damage;
            callback(this.hp,this.maxHp);
        }
    }
}

 

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

23/07/27 과제(복습)  (0) 2023.07.27
23/07/27 아이템 정보 저장하기  (0) 2023.07.27
23/07/27 Action 대리자  (0) 2023.07.27
23/07/27 데이터매니저 데이터로드  (0) 2023.07.27
23/07/27 람다  (0) 2023.07.27