유니티3D 프로그래밍

C# 1주차 4일 수업 내용 (21.03.11) 본문

C#/수업내용

C# 1주차 4일 수업 내용 (21.03.11)

tjdgus9955 2021. 3. 11. 09:48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Study00
{
    public class App
    {
        User user;
        //생성자
        public App()
        {
            Console.WriteLine("App 생성자를 호출함");
            Console.WriteLine("user: " + user);

            user = new User();
            user.name = "홍길동";
            Console.WriteLine(user.name);

            User user1 = new User();
            user1.name = "임꺽정";
            Console.WriteLine(user1.name);

            user1 = null;
            user1 = user;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Study00
{
    public class User
    {    
        //멤버 변수
        public string name;

        //생성자
        public User()
        {
            Console.WriteLine("User생성자 호출됨");
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Study00
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Main메서드 실행");
            new App();
        }
    }
}

 

 

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

namespace Study00
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Main메서드 실행");
            new App();

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

namespace Study00
{
    public class App
    {
        //생성자
        public App()
        {
            Console.WriteLine("App 생성자 호출됨");
            Barracks barracks = new Barracks();
            Marine marine1 = barracks.CreateMarine();
            marine1.name = "홍길동";
            marine1.hp = 75;
            marine1.damage = 5;

            Marine marine2 = barracks.CreateMarine();
            marine2.name = "임꺽정";
            marine2.hp = 75;
            marine2.damage = 5;

            marine1.Attack(marine2);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Study00
{
    public class Barracks
    {
        //멤버변수
        float hp;

        //생성자
        public Barracks()
        {
            Console.WriteLine("Barracks 생성자 호출됨");
        }
        
        //멤버 매서드
        public Marine CreateMarine()
        {
            return new Marine();
        }

        public void Destroy()
        {
            Console.WriteLine("파괴되었습니다.");
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Study00
{
    public class Marine
    {
        //멤버변수
        public string name;
        public float hp = 50;
        public float damage = 5;

        public Marine()
        {
            Console.WriteLine("Marine 생성자 호출됨");
        }

        public void Attack(Marine target)
        {
            //타겟에게 피해를 줍니다.
            Console.WriteLine("{0}이(가) {1}을 공격합니다.", this.name, target.name);
            target.Hit(this.damage);     
        }

        public void Hit(float damage)
        {
            this.hp -= damage;
            if(this.hp <= 0)
            {
                this.Die();
            }
            Console.WriteLine("{0}가 피해를({1})을 받았습니다..", this.name, damage);
        }
        public void Die()
        {
            Console.WriteLine("{0}가 죽었습니다.", this.name);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Study00
{
    public class App
    {
        //생성자
        public App()
        {
            Console.WriteLine("App 생성자 호출됨");
            Console.WriteLine();

            Hydra hydra;
            hydra = new Hydra();
            Console.WriteLine(hydra);
            Console.WriteLine();

            Firebat firebat;
            firebat = new Firebat();
            Console.WriteLine(firebat);
            Console.WriteLine();

            Ghost ghost;
            ghost = new Ghost();
            Console.WriteLine(ghost);
            Console.WriteLine();

            Gateway gateway;
            gateway = new Gateway();
            Console.WriteLine(gateway);
            Console.WriteLine();

            Factory factroy;
            factroy = new Factory();
            Console.WriteLine(factroy);
            Console.WriteLine();

            Goliath goliath = new Goliath();
            Console.WriteLine(goliath);
            Console.WriteLine();

            Valture valture = new Valture();
            Console.WriteLine(valture);
            Console.WriteLine();

            DarkTemplar darkTemplar = new DarkTemplar();
            Console.WriteLine(darkTemplar);
            Console.WriteLine();

            SCV scv = new SCV();
            Console.WriteLine(scv);
            Console.WriteLine();

            Observer observer = new Observer();
            Console.WriteLine(observer);
            Console.WriteLine();
        }
    }
}