C#/수업과제

C# 21.03.17.과제 8

HappyFrog 2021. 3. 17. 18:22

 

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

namespace Homework000
{
    public class App
    {
        //생성자 
        public App()
        {
            Zergling zergling = new Zergling();
            Lurker lurker = new Lurker();

            zergling.Move();
            lurker.Move();

            zergling.Attack();
            lurker.Attack();

            lurker.Burrow();
            lurker.Attack();

            zergling.Move();
            zergling.Burrow();

            lurker.UnBurrow();
            lurker.Move();

            lurker.Burrow();
            lurker.Attack();
        }
            
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Homework000
{
    public abstract class ZergUnit : IBurrow
    {        
        public abstract void Burrow();
        public abstract void UnBurrow();
        public abstract void Attack();
        public abstract void Move();
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Homework000
{
    class Zergling : ZergUnit
    {
        public bool isBurrow;

        public override void Move()
        {
            if (isBurrow == true)
            {
                Console.WriteLine("저글링은 버로우 상태에서 움직일 수 없습니다.");
            }
            else
            {
                Console.WriteLine("저글링이 이동합니다.");
            }           
        }

        public override void Attack()
        {
            if(isBurrow == true)
            {
                Console.WriteLine("저글링은 버로우 상태에선 공격할 수 없습니다.");
            }
            else
            {
                Console.WriteLine("저글링이 발톱으로 공격합니다.");
            }
        }

        public override void Burrow()
        {
            if (isBurrow != true)
            {
                Console.WriteLine("저글링이 버로우합니다.");                
            }
            else
            {
                Console.WriteLine("저글링은 이미 버로우 상태입니다.");                
            }
            isBurrow = true;
        }

        public override void UnBurrow()
        {
            if (isBurrow != true)
            {
                Console.WriteLine("저글링은 버로우 상태가 아닙니다.");
            }
            else
            {
                Console.WriteLine("저글링이 버로우를 해제합니다.");
            }
            isBurrow = false;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Homework000
{
    
    class Lurker : ZergUnit
    {
        public bool isBurrow;

        public override void Move()
        {
            if (isBurrow == true)
            {
                Console.WriteLine("럴커는 버로우 상태에서 움직일 수 없습니다.");
            }
            else
            {
                Console.WriteLine("럴커가 이동합니다.");
            }
        }
        public override void Attack()
        {
            if (isBurrow != true)
            {
                Console.WriteLine("버로우 상태에서만 공격할 수 있습니다.");
            }
            else
            {
                Console.WriteLine("럴커가 가시로 공격합니다.");
            }
        }

        public override void Burrow()
        {
            if (isBurrow != true)
            {
                Console.WriteLine("럴커가 버로우합니다.");
            }
            else
            {
                Console.WriteLine("럴커가 이미 버로우 상태입니다.");
            }
            isBurrow = true;
        }

        public override void UnBurrow()
        {
            if (isBurrow != true)
            {
                Console.WriteLine("럴커가 버로우 상태가 아닙니다.");
            }
            else
            {
                Console.WriteLine("럴커가 버로우를 해제합니다.");
            }
            isBurrow = false;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Homework000
{
    interface IBurrow
    {
        void Burrow();
        void UnBurrow();
    }
}

 

=======================================

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

namespace Homework000
{
    public class App
    {
        //생성자 
        public App()
        {
            Ghost ghost = new Ghost();
            Wraith wraith = new Wraith();

            ghost.Move();
            wraith.Move();

            ghost.Attack();
            wraith.Attack();

            ghost.Cloaking();
            wraith.Cloaking();

            ghost.UnCloaking();
            wraith.UnCloaking();
        }            
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Homework000
{
    public abstract class TerranUnit : ICloaking
    {
        public abstract void Cloaking();
        public abstract void UnCloaking();
        public abstract void Attack();
        public abstract void Move();
        
        

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

namespace Homework000
{
    class Ghost : TerranUnit
    {
        public override void Attack()
        {
            Console.WriteLine("고스트가 공격합니다.");
        }

        public override void Cloaking()
        {
            Console.WriteLine("고스트가 투명해집니다...");
        }

        public override void Move()
        {
            Console.WriteLine("고스트가 이동합니다.");
        }

        public override void UnCloaking()
        {
            Console.WriteLine("고스트의 클로킹이 풀립니다.");
        }
    }
    
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Homework000
{    
    class Wraith : TerranUnit
    {


        public override void Attack()
        {
            Console.WriteLine("레이스가 공격합니다.");
        }

        public override void Cloaking()
        {
            Console.WriteLine("레이스가 투명해집니다...");
        }

        public override void Move()
        {
            Console.WriteLine("레이스가 이동합니다.");
        }

        public override void UnCloaking()
        {
            Console.WriteLine("레이스의 클로킹이 풀립니다.");
        }

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

namespace Homework000
{
    interface ICloaking
    {
        void Cloaking();
        void UnCloaking();
        
    }
}

=======================================

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

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

            Marine marine = new Marine(100f);

            marine.Hp = 67;

            Console.WriteLine(marine.Hp);

            SCV scv = new SCV(50f);

            scv.Hp -= 10;

            Console.WriteLine("{0}/{1}", scv.Hp, scv.MaxHp);
        }            
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Homework000
{
    class SCV
    {
        public float Hp
        {
            get;set;
        }
        public float MaxHp
        {
            get;set;
        }

        public SCV(float maxHp)
        {
            this.MaxHp = maxHp;
            this.Hp = this.MaxHp;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Homework000
{
    class Marine
    {
        private float hp;
        private float maxHp;

        public float Hp
        {
            get
            {
                if(this.hp <= 0)
                {
                    return 0;
                }
                return this.hp;
            }
            set
            {
                if(value >= this.maxHp)
                {
                    value = this.maxHp;
                }
                this.hp = value;
            }
        }

        public Marine(float maxHp)
        {
            this.maxHp = maxHp;
            this.hp = this.maxHp;
        }
    }
}

 

=======================================

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

namespace Homework000
{
    public class App
    {
        //생성자 
        public App()
        {
            Marine marine = new Marine(6, 0, 40, 40);

            marine.Hp = 24;
            Console.WriteLine(marine.Hp);

            int i = 0;
            while (i < 1)
            {
                marine.Hp -= 12;
                Console.WriteLine("마린의 남은 HP : {0}", marine.Hp);
                if (marine.Hp <= 0)
                {
                    Console.WriteLine("마린이 죽었습니다.");
                    break;
                }
            }
            
        }            
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Homework000
{
    class Marine
    {
        private int dmg;
        private int arm;
        private int hp;
        private int maxHp;

        public int Hp
        {
            get
            {
                if(this.hp <= 0)
                {
                    return 0;
                }
                return this.hp;
            }
            set
            {
                if(value > this.maxHp)
                {
                    value = this.maxHp;
                }
                this.hp = value;
            }
        }
        public int Dmg
        {
            get;set;
        }
        
        public int Arm
        {
            get;set;
        }


        public Marine(int dmg, int arm, int hp, int maxHp)
        {
            this.dmg = dmg;
            this.arm = arm;
            this.hp = hp;
            this.maxHp = maxHp;
        }
    }
}

=======================================

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

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

            Stack<Item> items;
            items = new Stack<Item>();

            Item item1 = new Item("도란의 반지", 450);
            Item item2 = new Item("도란의 검", 500);
            Item item3 = new Item("삼위일체", 3333);

            items.Push(item1);
            items.Push(item2);
            items.Push(item3);

            Console.WriteLine(items.Count);

            foreach (Item item in items)
            {
                Console.WriteLine("{0} : {1:#,###}gold", item.name, item.price);
            }

            Item itemPopInfo = items.Pop();
            Console.WriteLine("{0} : {1:#,###}gold 가 사라졌습니다.", itemPopInfo.name, itemPopInfo.price);

            Console.WriteLine(items.Count);

            Item itemPeekInfo = items.Peek();
            Console.WriteLine("{0} : {1:#,###}gold", itemPeekInfo.name, itemPeekInfo.price);


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

namespace Homework000
{
    class Item
    {
        public string name;
        public int price;
        public Item(string name, int price)
        {
            this.name = name;
            this.price = price;
        }
    }
}

=======================================