
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study06
{
public class App
{
//생성자
public App()
{
Console.WriteLine("App클래스 생성자 호출됨");
Item item = new Item();
Enchant(item, 50, (success) => { //람다식의 매개변수 타입은 bool
if (success)
{
Console.WriteLine("강화 성공 이펙트를 보여 준다.");
}
else
{
Console.WriteLine("강화 실패 이펙트를 보여 준다.");
}
});
}
public void Enchant(Item item, int probability, Action<bool> action)
{
Random rand = new Random();
int dice = rand.Next(0, 100);
if (probability > dice)
{
Console.WriteLine("강화 성공!");
action(true);
}
else
{
Console.WriteLine("강화 실패!");
action(false);
}
}
}
}
'게임 알고리즘' 카테고리의 다른 글
3일차 람다식 연습문제5 (0) | 2024.08.16 |
---|---|
3일차 람다식 연습문제4 (0) | 2024.08.16 |
3일차 람다식 연습문제3 (0) | 2024.08.16 |
3일차 람다식 연습문제2 (0) | 2024.08.16 |
3일차 람다식 연습문제 1 (0) | 2024.08.16 |