• Program
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("아이템 생성자 실행");
        }
    }
}

'게임 알고리즘' 카테고리의 다른 글

구조체, 스택, 힙, 값 형식, 참조 형식  (0) 2024.08.19
Action_스위치 온/오프  (0) 2024.08.19
Action_마린이 맞아 죽음  (0) 2024.08.19
Action_버튼 누르기  (0) 2024.08.19
Action_히어로가 몬스터를 때림  (0) 2024.08.19

+ Recent posts