스토리지

과제 4 본문

Unity/수업과제

과제 4

ljw4104 2021. 3. 12. 09:28
using System;

namespace Study02
{
    public class Dragoon
    {
        private int hp;
        private int shieldHp;
        private int damage;
        private string name;
        public Dragoon()
        {
            Console.WriteLine("Dragoon 생성됨.");
            name = "드라군";
        }

        public Dragoon(int hp, int shieldHp)
        {
            Console.WriteLine("Dragoon 생성됨.");
            name = "드라군";
            this.hp = hp;
            this.shieldHp = shieldHp;
        }

        public int GetHp()
        {
            return hp;
        }

        public int GetShieldHp()
        {
            return shieldHp;
        }

        public int GetDamage()
        {
            return damage;
        }

        public void setHp(int hp)
        {
            this.hp = hp;
        }

        public void setShieldHp(int shieldHp)
        {
            this.shieldHp = shieldHp;
        }

        public void setAttack(int damage)
        {
            this.damage = damage;
        }

        public bool Damaged(int damage)
        {
            bool isDead = false;
            if (shieldHp - damage < 0)
            {
                this.hp -= damage - this.shieldHp;
                this.shieldHp = 0;
                if (this.hp < 0)
                    return !isDead;
                return isDead;
            }
            else if (hp <= 0)
            {
                Die();
                return !isDead;
            }
            else
            {
                this.shieldHp -= damage;
                return isDead;
            }
        }

        public void AttackLurker(Lurker lurker, Observer observer)
        {
            if (observer == null)
            {
                Console.WriteLine("럴커가 버로우 상태이므로 안보여서 공격 불가능");
            }
            else
            {
                if(lurker.Damaged(this.damage))
                {
                    Console.WriteLine("럴커가 생존함. 체력 : {0}/{1}", lurker.hp - damage, lurker.hp);
                }
                else
                {
                    Console.WriteLine("럴커가 사망함.");
                }
            }
        }

        public void Die()
        {
            Console.WriteLine("{0}이(가) 죽었습니다.", name);
        }
    }
}
​
using System;

namespace Study02
{
    public class Spire
    {
        public bool isGreatSpire;
        public Spire()
        {
            Console.WriteLine("Spire 건설됨.");
            isGreatSpire = false;
        }
    }
}
​
using System;

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

            Hydralisk hydralisk = new Hydralisk();
            Console.WriteLine(hydralisk);

            Lurker lurker = new Lurker(120);
            Console.WriteLine(lurker);

            Drone drone = new Drone();
            Console.WriteLine(drone);

            Queen queen = new Queen();
            Console.WriteLine(queen);

            Arbiter arbiter;
            arbiter = new Arbiter();
            Console.WriteLine(arbiter);

            Dragoon dragoon;
            dragoon = new Dragoon();
            Console.WriteLine(dragoon);

            Observatory observatory;
            observatory = null;

            TemplarArchives templarArchives;
            templarArchives = new TemplarArchives();
            Console.WriteLine(templarArchives);

            Console.WriteLine();

            dragoon.setHp(100);
            dragoon.setShieldHp(80);
            lurker.AttackDragoon(dragoon);

            Console.WriteLine();

            Dragoon dragoon2 = new Dragoon();
            dragoon2.setHp(100);
            dragoon2.setShieldHp(80);

            Console.WriteLine();

            Broodling broodling = queen.makeBroodling();
            broodling.damage = 4;
            queen.energy = 140;
            broodling.AttackDragoon(queen, dragoon);

            Console.WriteLine();

            Observer observer;
            if (observatory == null)
            {
                //옵저버토리가 없으면
                observer = new Observer();
                observer = null;
            }
            else
            {
                //옵저버토리가 있으면
                observer = new Observer(observatory);
            }

            Console.WriteLine();

            dragoon2.AttackLurker(lurker, observer);

            Console.WriteLine();

            Spire spire = new Spire();
            Mutalisk mutalisk;
            if (spire == null)
            {
                mutalisk = null;
            }
            else
            {
                mutalisk = new Mutalisk(spire);
            }

            mutalisk.attack = 9;
            Dragoon dragoon3 = new Dragoon(100, 80);
            mutalisk.AttackDragoon(dragoon3);

            Console.WriteLine("Spire 업그레이드함.");
            spire.isGreatSpire = true;

            Console.WriteLine();

            Guardian guardian = mutalisk.ChangeToGuardian(spire);
            if(guardian != null)
            {
                //생성 후 동작
            }
        }
    }
}

 

using System;

namespace Study02
{
    public class Mutalisk
    {
        public int hp;
        public int attack;
        public int targetNum;
        public Mutalisk(Spire spire)
        {
            Console.WriteLine("Mutalisk 생성됨.");
        }

        public Guardian ChangeToGuardian(Spire spire)
        {
            return spire.isGreatSpire ? new Guardian() : null;
        }

        public void AttackDragoon(Dragoon dragoon)
        {
            Console.WriteLine("뮤탈이 드라군을 공격합니다.");
            bool isDead = dragoon.Damaged(this.attack * 3);

            if (isDead)
            {
                Console.WriteLine("드라군 사망");
            }
            else
            {
                Console.WriteLine("드라군 생존, 체력 : {0}/{1}", dragoon.GetShieldHp(), dragoon.GetHp());
            }
        }
    }
}
using System;

namespace Study02
{
    public class Guardian
    {
        public int hp;
        public int damage;
        public Guardian()
        {
            Console.WriteLine("가디언 생성됨.");
        }
    }
}

 

 

수업내용 코드 + 좀 더 구현
하이브는 미리 업그레이드 되어있다고 가정

 

'Unity > 수업과제' 카테고리의 다른 글

과제 6  (0) 2021.03.16
과제 5  (0) 2021.03.14
과제3  (0) 2021.03.10
과제 2  (0) 2021.03.09
과제 1  (0) 2021.03.09
Comments