C#/C#언어

0317_ interface 연습

minquu 2021. 3. 17. 13:09
반응형

 

 

저그 유닛 -> 럴커, 울트라리스트 

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study07
{
    public class App
    {
        public App() {
            Console.WriteLine("App 생성자");

            Lurker lurker = new Lurker();
            lurker.Burrow();
            lurker.Attack();

            Ultralisk ultralisk = new Ultralisk();
            ultralisk.Attack();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study07
{
    public class ZergUnit
    {
        public ZergUnit() {
            Console.WriteLine("ZergUnit 생성자");
        }
        public virtual void Attack() {
            Console.WriteLine("공격했습니다.");
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study07
{
    interface IBurrow
    {
        void Burrow();
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study07
{
    public class Lurker : ZergUnit, IBurrow
    {
        public Lurker() {
            Console.WriteLine("Lurker 생성자");
        }
        public void Burrow()
        {
            Console.WriteLine("버로우 했습니다.");
        }

        public override void Attack() {
            Console.WriteLine("까시로 공격했습니다.");
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

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

----

 

테란유닛 -> 레이스, 발키리 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study07
{
    public class App
    {
        public App() {
            Console.WriteLine("App 생성자");
            
            Valkyrie valkyrie = new Valkyrie();
            valkyrie.Attack();

            Wraith wraith = new Wraith();
            wraith.Cloaking();
            wraith.Attack();

        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study07
{
    public class TerranUnit
    {
        public TerranUnit() {
            Console.WriteLine("TerranUnit 생성자");
        }
        public virtual void Attack() {
            Console.WriteLine("공격을 합니다.");
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study07
{
    interface ICloaking
    {
        void Cloaking();

    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study07
{
    public class Valkyrie : TerranUnit
    {
        public Valkyrie() {
            Console.WriteLine("Valkyie가 생성됩니다.");
        }

        public override void Attack()
        {
            Console.WriteLine("다중 미사일로 공격합니다.");
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study07
{
    public class Wraith : TerranUnit, ICloaking
    {
        public Wraith() {
            Console.WriteLine("Wraith가 생성됩니다.");
        }
        public void Cloaking() {
            Console.WriteLine("클락킹을 합니다.");
        }
        public override void Attack()
        {
            Console.WriteLine("미사일로 공격합니다.");
        }
    }
}

 

-----

 

프로토스 유닛

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study07
{
    public class App
    {
        public App() {
            Console.WriteLine("App 생성자");
            Observer observer = new Observer();
            observer.Move();
            observer.IFly();
            observer.ITransparent();

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

            Zealot zealot = new Zealot();
            zealot.Move();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study07
{
    public class ProtossUnit
    {
        public ProtossUnit() {
            Console.WriteLine("ProtossUnit 생성자");
        }
        public void Move() {
            Console.WriteLine("움직입니다.");
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study07
{
    interface ITransparent
    {
        void ITransparent();
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study07
{
    interface IFly
    {
        void IFly();
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study07
{
    public class DarkTemplar : ProtossUnit, ITransparent
    {
        public DarkTemplar() {
            Console.WriteLine("DarkTemplar 생성자");
        }
        public void ITransparent() {
            Console.WriteLine("투명 유닛");
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study07
{
    public class Observer : ProtossUnit, IFly, ITransparent
    {
        public Observer() {
            Console.WriteLine("Observer 생성자");
        }
        public void IFly() {
            Console.WriteLine("공중 유닛");
        }
        public void ITransparent()
        {
            Console.WriteLine("투명한 유닛");
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

 

 

반응형