- Program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ram4
{
internal class Program
{
static void Main(string[] args)
{
new App();
}
}
}
- App
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ram4
{
public class App
{
//생성자
public App()
{
Console.WriteLine("App 생성자 실행");
Marin marin = new Marin(40); //매개변수 의미 : 최대 체력
//람다 문
marin.HitDamage(100, () => { //()람다 매개 변수
Console.WriteLine("마린이 죽었습니다.");
});
}
}
}
- Marin
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ram4
{
public class Marin
{
//매개변수
public int hp;
public int maxHp;
//생성자
public Marin(int hp)
{
this.hp = hp;
this.maxHp = hp;
Console.WriteLine($"마린 생성 체력{hp}/{maxHp}");
}
public void HitDamage(int damage, Action action) // 매개 변수로 데미지랑 람다를 받음
{
this.hp -= damage;
Console.WriteLine($"마란이 {damage}의 피해를 받음 {hp}/{maxHp}");
if (this.hp <= 0)
{
action(); // 람다 실행. 글로 가라고!
}
}
}
}
'게임 알고리즘' 카테고리의 다른 글
Action_스위치 온/오프 (0) | 2024.08.19 |
---|---|
Action_아이템 강화 (0) | 2024.08.19 |
Action_버튼 누르기 (0) | 2024.08.19 |
Action_히어로가 몬스터를 때림 (0) | 2024.08.19 |
Action_시즈 탱크 모드 변환 (0) | 2024.08.19 |