스토리지

[3.17] 인터페이스 연습 1 본문

Unity/수업내용(C#)

[3.17] 인터페이스 연습 1

ljw4104 2021. 3. 17. 12:01

1.

using System;
using System.Collections.Generic;

namespace Study07
{
    public class App
    {
        public App()
        {
            Lurker lurker = new Lurker();
            Ultralisk ultralisk = new Ultralisk();

            lurker.Burrow();
            lurker.Attack();

            ultralisk.Attack();
        }
    }
}
using System;

namespace Study07
{
    public class ZergUnit
    {
        public ZergUnit()
        {
            Console.WriteLine("ZergUnit 생성자");
        }

        public virtual void Attack()
        {
            Console.WriteLine("Attack");
        }
    }
}
using System;

namespace Study07
{
    public class Lurker : ZergUnit, IBurrow
    {
        public Lurker()
        {
            Console.WriteLine("Lurker 생성자");
        }

        public override void Attack()
        {
            Console.WriteLine("가시로 공격했습니다.");
        }

        public void Burrow()
        {
            Console.WriteLine("버로우 했습니다.");
        }
    }
}
using System;

namespace Study07
{
    public class Ultralisk : ZergUnit
    {
        public Ultralisk()
        {
            Console.WriteLine("Ultralisk 생성자");
        }

        public override void Attack()
        {
            Console.WriteLine("뿔로 공격했습니다.");
        }
    }
}
using System;

namespace Study07
{
    interface IBurrow
    {
        void Burrow();
    }
}

 

2.

using System;
using System.Collections.Generic;

namespace Study07
{
    public class App
    {
        public App()
        {
            Wraith wraith = new Wraith();
            Valkyrie valkyrie = new Valkyrie();

            wraith.Cloaking();
            wraith.Attack();
            valkyrie.Attack();
        }
    }
}
using System;

namespace Study07
{
    public class TerranUnit
    {
        public TerranUnit()
        {
            Console.WriteLine("TerranUnit 생성자.");
        }

        public virtual void Attack()
        {

        }
    }
}
using System;

namespace Study07
{
    public class Valkyrie : TerranUnit
    {
        public Valkyrie()
        {
            Console.WriteLine("Valkyrie 생성자.");
        }

        public override void Attack()
        {
            Console.WriteLine("미사일로 공중유닛 요격.");
        }
    }
}
using System;

namespace Study07
{
    interface ICloaking
    {
        void Cloaking();
    }
}
using System;

namespace Study07
{
    public class Wraith : TerranUnit, ICloaking
    {
        public Wraith()
        {
            Console.WriteLine("Wraith 생성자.");
        }

        public override void Attack()
        {
            Console.WriteLine("미사일로 지상유닛 공격");
        }

        public void Cloaking()
        {
            Console.WriteLine("클로킹해서 투명해짐");
        }
    }
}

 

 

3.

using System;

namespace Study07
{
    public class App
    {
        public App()
        {
            Zealot zealot = new Zealot();
            zealot.Move();

            Console.WriteLine();

            DarkTemplar darkTemplar = new DarkTemplar();
            darkTemplar.DoTransparent();
            darkTemplar.Move();

            Console.WriteLine();

            Observer observer = new Observer();
            observer.DoTransparent();
            observer.Fly();
            observer.Move();

            Console.WriteLine();
        }
    }
}
using System;

namespace Study07
{
    public class ProtossUnit
    {
        public ProtossUnit()
        {
            Console.WriteLine("ProtossUnit 생성자.");
        }

        public virtual void Move()
        {
            Console.WriteLine("움직이다.");
        }
    }
}
using System;

namespace Study07
{
    interface ITransparent
    {
        void DoTransparent();
    }
}
using System;

namespace Study07
{
    interface IFly
    {
        void Fly();
    }
}
using System;

namespace Study07
{
    public class Zealot : ProtossUnit
    {
        public Zealot()
        {
            Console.WriteLine("Zealot 생성됨.");
        }

        public override void Move()
        {
            Console.WriteLine("발업된 질럿 움직인다.");
        }
    }
}
using System;

namespace Study07
{
    public class Observer : ProtossUnit, ITransparent, IFly
    {
        public Observer()
        {
            Console.WriteLine("Observer 생성자.");
        }

        public void DoTransparent()
        {
            Console.WriteLine("투명해지다.");
        }

        public void Fly()
        {
            Console.WriteLine("날다.");
        }

        public override void Move()
        {
            Console.WriteLine("안보이는 상태에서 날아서 움직임.");
        }
    }
}
using System;

namespace Study07
{
    public class DarkTemplar : ProtossUnit, ITransparent
    {
        public DarkTemplar()
        {
            Console.WriteLine("DarkTemplar 생성자.");
        }

        public void DoTransparent()
        {
            Console.WriteLine("투명해지다.");
        }

        public override void Move()
        {
            Console.WriteLine("안보이는 상태에서 움직이다.");
        }
    }
}

Comments