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

[C# 6일차] Method return 연습_StarCraft Templer to Archon

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

App Class

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

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

            Templer templer0 = new Templer();
            Templer templer1 = new Templer();

            Archon archon = templer0.Merge(templer1);
            archon.Move(2, 3);
        }
    }
}

 

Templer Class

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

namespace Study06
{
    class Templer
    {
        //생성자
        public Templer()
        {
            Console.WriteLine("Templer 생성");
        }
        public Archon Merge(Templer templer)
        {
            Console.WriteLine("Templer 합체 ({0}+{1})", this, other);
            return new Archon();
        }
    }
}

 

Archon Class

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

namespace Study06
{
    class Archon
    {
        int x = 0;
        int y = 0;
        //생성자
        public Archon()
        {
            Console.WriteLine("Archon 생성");
            Console.WriteLine("현재 위치 ({0},{1})", this.x, this.y);
        }

        public void Move(int x, int y)
        {
            this.x = this.x + x;
            this.y = this.y + y;
            Console.WriteLine("x축으로 {0}만큼, y축으로 {1}만큼 이동.  현재위치: ({2},{3})", x, y, this.x, this.y);
        }
    }
}

 

실행결과

728x90