C#

스타크래프트 템플러 아콘으로 합성/아콘 이동 클래스

s0002 2023. 1. 6. 12:08
using System;

namespace Study06
{
    class Program
    {
        static void Main(string[] args)
        {
            App app = new App();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace Study06
{
    class App
    {
        public App()
        {
            Templar templar0 = new Templar();
            Templar templar1 = new Templar();

            Archon archon = templar0.Merge(templar1);
            archon.Move(2, 3);
            archon.Move(0,0);
            archon.Move(-2, -3);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace Study06
{
    class Templar
    {
        public Templar()
        {
            Console.WriteLine("templar 생성");
            Console.WriteLine();
        }

        public Archon Merge(Templar templar)
        {
            Console.WriteLine("템플러가 합성되었습니다");
            Console.WriteLine();

            Archon archon = new Archon();
            return archon;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace Study06
{
    class Archon
    {
        public Archon()
        {
            Console.WriteLine("archon 생성");
            Console.WriteLine();
        }

        public void Move(int x, int y)
        {
            
            if (x < 0)
                Console.WriteLine("왼쪽으로 {0}만큼 이동합니다", x);

            else if (x > 0)
                Console.WriteLine("오른쪽으로 {0}만큼 이동합니다", x);


            if (y < 0)
                Console.WriteLine("아래쪽으로 {0}만큼 이동합니다", y);

            else if (y > 0)
                Console.WriteLine("위쪽으로 {0}만큼 이동합니다", y);


            if (x==0 && y==0)
                Console.WriteLine("이동하지 않았습니다");

            Console.WriteLine();
        }
    }
}

'C#' 카테고리의 다른 글

클래스/인스턴스/생성자/new 연산자  (0) 2023.01.08
continue/break/멤버변수/지역변수  (0) 2023.01.08
클래스 반환 연습  (0) 2023.01.06
스타듀밸리 피에르 클래스  (0) 2023.01.06
스타듀밸리 캐릭터 클래스  (0) 2023.01.05