using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ram6
{
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 Ram6
{
public class App
{
//생성자
public App()
{
Console.WriteLine("앱 생성자 실행");
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($"확률: {probability} / 주사위 {dice}\n결과: 강화 성공!");
action(true);
}
else
{
Console.WriteLine($"확률: {probability} / 주사위 {dice}\n결과: 강화 실패!");
action(false);
}
}
}
}
Item
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ram6
{
public class Item
{
//생성자
public Item()
{
Console.WriteLine("아이템 생성자 실행");
}
}
}