본문 바로가기
C#/수업내용

[C# 5일차] Starcraft Larva-Hydralisk-Lurker 진화

by 왹져박사 2023. 1. 5.
728x90

<분석>

 

[라바 Larva]
--------
진화하기 ---->나는 사라지고 새 생명 만들어짐


[히드라 Hydralisk]
---------
이동하다
잠복하다 (Burrow)


[러커 Lurker]
--------
이동하다
잠복하다(이동불가능)
공격하다(잠복상태에서만 가능)

 


App Class

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

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

            Larva larva = new Larva();
            Hydralisk hydra = larva.Transformate();


            //Hydralisk hydra = new Hydralisk();

            hydra.Move();       //이동했습니다
            hydra.Burrow();     //버로우했습니다. 
            hydra.Move();       //이동할수없습니다.
            hydra.UnBurrow();       //언버로우했습니다. 
            hydra.Move();       //이동했습니다. 
            Console.WriteLine();


            Lurker lurker = hydra.Transformate();

            lurker.Move();
            lurker.Attack();
            lurker.Burrow();
            lurker.Move();
            lurker.Attack();
            lurker.Burrow();
            Console.WriteLine();


        }
    }
}

 

Larva Class

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

namespace Study05
{
    class Larva 
    {
        //생성자
        public Larva()
        {
            Console.WriteLine("라바 생성");
        }

        public Hydralisk Transformate()
        {
            Console.WriteLine("히드라로 진화하였습니다. ");

            return new Hydralisk();
        }
    }
}

 

Hydralisk Class

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

namespace Study05
{
    class Hydralisk 
    {
        enum BurrowType
        {
            UnBurrow = -1, Burrow 
        }

        BurrowType nowType;
        //생성자
        public Hydralisk()
        {
            nowType = Hydralisk.BurrowType.UnBurrow;
        }

        public void Move()
        {
            if (nowType == BurrowType.Burrow)
            {
                Console.WriteLine("이동할수없습니다. ");
            }
            else
            {
                Console.WriteLine("이동했습니다.");
            }
        }

        public void Burrow()
        {
            nowType = BurrowType.Burrow;
            Console.WriteLine("버로우했습니다.");
        }

        public void UnBurrow()
        {
            nowType = BurrowType.UnBurrow;
            Console.WriteLine("언버로우했습니다.");

        }

        public Lurker Transformate()
        {
            Console.WriteLine("러커로 진화하였습니다. ");

            return new Lurker();
        }

    }
}

 

Lurker Class

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

namespace Study05
{
    class Lurker
    {
        enum BurrowType
        {
            UnBurrow = -1, Burrow
        }

        BurrowType nowType;
        //생성자
        public Lurker()
        {
            nowType = BurrowType.UnBurrow;
        }

        public void Move()      //잠복상태에서 이동 불가능
        {
            if(nowType == BurrowType.UnBurrow)
            {
                Console.WriteLine("이동하였습니다. ");
            }
            else
            {
                Console.WriteLine("이동이 불가능합니다. ");

            }
        }

        public void Attack()        //잠복상태에서만 공격 가능
        {
            if(nowType == BurrowType.Burrow)
            {
                Console.WriteLine("공격하였습니다. ");
            }
            else
            {
                Console.WriteLine("공격하지 못하는 상태입니다. ");
            }
        }

        public void Burrow()
        {
            nowType = BurrowType.Burrow;
            Console.WriteLine("버로우했습니다.");
        }

        public void UnBurrow()
        {
            nowType = BurrowType.UnBurrow;
            Console.WriteLine("언버로우했습니다.");

        }

    }
}

 

실행결과

728x90