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

수업 설명 2

by 이지훈26 2021. 8. 30.
using System;
class Program
{
    
    static void Main(string[] args)
    {
        new APP();
    }
}


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

class APP
{
    //생성자
    public APP()
    {
        //여기다가 작성..
        //SCV객체 생성
        SCV scv = new SCV();
        scv.Move(3, 4);
        scv.PrintPosition();
    }
}


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

class SCV
{
    private int x;
    private int y;

    public SCV()
    {
        Console.WriteLine("SCV생성됨 ({0},{1})", this.x, this.y);
    }

    //메서드 정의
    //움직이다
    //tx : 목표 x좌표
    //ty : 목표 y좌표
    public void Move(int tx, int ty)  //(매개변수)
    {
        // x -> tx
        // y -> tx
        this.x = tx;
        this.y = ty;

        Console.WriteLine("({0},{1})로 이동완료", this.x, this.y);
    }

    public void PrintPosition()
    {
        Console.WriteLine("현재 좌표: ({0},{1})", this.x, this.y);
    }
}

'c# > 수업 내용' 카테고리의 다른 글

속성 (Property)  (0) 2021.08.30
구조체(struct )  (0) 2021.08.30
복습 (진행중)  (0) 2021.08.30
질롯 vs 저글링  (0) 2021.08.26
클래스 생성, 인스턴스 생성 연습 (저그)  (0) 2021.08.26