ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 03/22 델리게이트 연습 7
    C#/수업내용 2021. 3. 22. 17:00
    728x90

     

    Program.cs

    using System;
    
    namespace Study07
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Program");
                new App();
            }
        }
    }
    

     

    App.cs

    using System;
    
    namespace Study07
    {
        public class App
        {
            //생성자 
            public App()
            {
                Goblin goblin = new Goblin();
                goblin.onIdle = OnIdle;            
                goblin.Attack();
            }
            
            public void OnIdle(Goblin goblin)
            {
                goblin.ChangeState(eState.Idle);
                Console.WriteLine("Idle");
            }
        }
    }

     

    Goblin.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    
    namespace Study07
    {
        public delegate void OnIdle(Goblin goblin);
        public enum eState
        {
            Idle, Attack
        }
        public class Goblin
        {
            private eState state;
            public OnIdle onIdle;
            public Goblin()
            {
                Console.WriteLine("Idle");
            }
    
            public void ChangeState(eState state)
            {
                this.state = state;
            }
    
            public void Attack()
            {
                ChangeState(eState.Attack);
                for (int i = 0; i <= 5; i++)
                {
                    Thread.Sleep(500);
                    Console.WriteLine("goblin_attack_{0: 00}", i);
                }
                this.onIdle(this);
    
            }
        }
    }
    
    728x90

    'C# > 수업내용' 카테고리의 다른 글

    03/23 Linq Where 연습  (0) 2021.03.23
    03/23 Linq Find, Where, FindAll, Sort 연습  (0) 2021.03.23
    03/22 델리게이트 연습 6  (0) 2021.03.22
    03/22 델리게이트 연습 5  (0) 2021.03.22
    03/22 델리게이트 연습 4  (0) 2021.03.22
Designed by Tistory.