using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
namespace Starcraft
{
public class App
{
//생성자
public App()
{
Hero hero = new Hero();
hero.HitDamage(3, (hp, maxHp) =>
{
Console.WriteLine("{0}/{1}", hp, maxHp);
});
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Starcraft
{
public class Hero
{
int hp;
int maxHp = 40;
public Hero()
{
hp = maxHp;
}
public void HitDamage(int damage, Action<int, int> hit)
{
Console.WriteLine("공격받았습니다.");
this.hp -= damage;
hit(this.hp, this.maxHp);
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
namespace Starcraft
{
public class App
{
//생성자
public App()
{
Hero hero = new Hero();
hero.HitDamage(3, (isDie) =>
{
Console.WriteLine("isDie: {0}",isDie);
});
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Starcraft
{
public class Hero
{
int hp;
int maxHp = 40;
public Hero()
{
hp = maxHp;
}
public void HitDamage(int damage, Action<string> callback)
{
this.hp -= damage;
if(this.hp < 0)
{
callback("죽었습니다.");
}
else {
callback("안죽었습니다.");
}
}
}
}
'C#' 카테고리의 다른 글
게임시작 (0) | 2023.07.28 |
---|---|
대리자 연습 3,4 (0) | 2023.07.27 |
싱글톤 패턴으로 대리자 호출 (0) | 2023.07.27 |
인벤토리2 (0) | 2023.07.26 |
몬스터 아이템 드랍 (0) | 2023.07.26 |