Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Archives
Today
Total
관리 메뉴

행복한 개구리

C# 21.03.11.과제 4 본문

C#/수업과제

C# 21.03.11.과제 4

HappyFrog 2021. 3. 12. 01:41
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Homework000
{
    class App
    {
        public App()
        {
            Console.WriteLine("-App생성자 호출됨-");
            
            //질럿으로 디팟 공격

            Zealot zealot = new Zealot();
            zealot.name = "질럿";
            zealot.dmg = 16;

            SupplyDepot supplydepot = new SupplyDepot();
            supplydepot.name = "서플라이 디팟";
            supplydepot.arm = 1;
            supplydepot.hp = 500;                      

            zealot.Attack(supplydepot);

            //============================================
            //저글링과 드론의 위치 바꾸기

            Zergling zergling = new Zergling();
            zergling.name = "저글링";
            zergling.X = 23;
            zergling.Y = 35;

            Drone drone = new Drone();
            drone.name = "드론";
            drone.X = 64;
            drone.Y = 11;

            zergling.ChangePlace(drone);

            //============================================
            //메딕으로 마린에게 걸린 디버프 제거

            Marine marine = new Marine();
            marine.name = "마린";            
            marine.basicSpeed = 1.875f;
            marine.speed = marine.basicSpeed;

            Medic medic = new Medic();
            medic.name = "메딕";
            medic.mana = 75;
            medic.cureMana = 75;

            Queen queen = new Queen();
            queen.name = "퀸";
            queen.speedEnsnareNum = 0.5f;

            queen.Ensnare(marine);
            medic.Cure(marine);

            //============================================
            //고스트 이동

            Ghost ghost = new Ghost();
            ghost.name = "고스트";
            ghost.X = 0;
            ghost.Y = 0;

            Position destination = new Position();
            destination.name = "목적지";
            destination.X = 16;
            destination.Y = 32;

            float finalResult = ghost.HowFar(destination);

            Console.WriteLine("{0}이 ({1},{2})지점으로 이동합니다. 거리는 {3}입니다.", ghost.name, destination.X, destination.Y, finalResult);


        }
    }
}

 

 

 

1.질럿으로 디팟 공격하기

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

namespace Homework000
{
    class SupplyDepot
    {
        //멤버 변수 정의
        public string name;
        public float hp;
        public float burnHp;
        public float arm;
        public float maxHp = 500;

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

        //멤버 메서드 정의
        public void Hit(float enemyDmg)
        {
            this.hp -= enemyDmg;
            float per = this.hp / maxHp * 100;
            Console.WriteLine("남은 체력 : {0}, {1}%", this.hp, per);
        }   

    }
}

 

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

namespace Homework000
{
    class Zealot
    {
        //멤버 변수 정의
        public string name;
        public float hp;       
        public float dmg;        

        //생성자
        public Zealot()
        {
            Console.WriteLine("-Zealot이 생성되었습니다.-");
        }

        //멤버 메서드 정의
        public void Attack(SupplyDepot target)
        {
            Console.WriteLine("{0}이 {1}을 공격합니다.", this.name, target.name);
            float realDmg = this.dmg - target.arm;
            
            for (int i = 0; i<3; i++)
            {                
                target.Hit(realDmg);
            }
            
        }
    }
}

 

 

 

2. 저글링과 드론 위치바꾸기

 

 

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

namespace Homework000
{
    class Zergling
    {
        public float X;
        public float Y;
        public string name;
        public Zergling()
        {
            Console.WriteLine("-Zergling이 생성되었습니다.-");
        }

        public void ChangePlace(Drone target)
        {
            Console.WriteLine("위치를 바꾸기 전 : {0}({1},{2}) / {3}({4},{5})",
                this.name, this.X, this.Y, target.name, target.X, target.Y);
            float telX = this.X;
            float telY = this.Y;

            this.X = target.X;
            target.X = telX;
            this.Y = target.Y;
            target.Y = telY;

            Console.WriteLine("위치가 성공적으로 바뀌었습니다." +
                " {0}({1},{2}) / {3}({4},{5})", this.name, this.X, this.Y, target.name, target.X, target.Y);
            
        }
    }
}

 

 

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

namespace Homework000
{
    class Drone
    {
        public float X;
        public float Y;
        public string name;
        public Drone()
        {
            Console.WriteLine("-Drone이 생성되었습니다.-");
        }
    }
}

 

3. 마린에게 걸린 퀸의 인스네어를 메딕의 큐어스킬로 제거하기

 

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

namespace Homework000
{    
    class Marine
    {
        public string name;
        public float basicSpeed;
        public float speed;
        public Marine()
        {
            Console.WriteLine("-Marine가 생성되었습니다.-");
        }                
    }
}

 

 

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

namespace Homework000
{
    class Queen
    {
        public string name;
        public string skillName;
        public float speedEnsnareNum;

        public Queen()
        {
            Console.WriteLine("-Queen이 생성되었습니다.-");
        }

        public void Ensnare(Marine target)
        {
            Console.WriteLine("{0}이 {1}에게 인스네어를 시전합니다.", this.name, target.name);
            float slow = target.speed * this.speedEnsnareNum;
            Console.WriteLine("인스네어가 적중하여 {0}의 이동속도가 25초간 {1}만큼 하락합니다.", target.name, slow);

        }
    }
}

 

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

namespace Homework000
{
    class Medic
    {
        public string name;
        public float mana;
        public float cureMana;
        public Medic()
        {
            Console.WriteLine("-Medic이 생성되었습니다.-");
        }

        public void Cure(Marine target)
        {
            if (this.mana >= cureMana)
            {
                Console.WriteLine("{0}이 {1}에게 큐어를 시전합니다.", this.name, target.name);
                target.speed = target.basicSpeed;
                Console.WriteLine("{0}의 이동속도가 {1}로 회복됐습니다.", target.name, target.speed);
            }
            else
            {
                Console.WriteLine("{0}이 큐어를 시전할 마나가 부족합니다.", this.name);
            }

        }
    }
}

 

4. 고스트 지정위치로 이동하기

 

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

namespace Homework000
{
    class Ghost
    {
        public string name;
        public float X;
        public float Y;
        
        public Ghost()
        {
            Console.WriteLine("-Ghost가 생성되었습니다.-");
        }

        //반환타입을 void가 아닌 float으로 해봤다.
        public float HowFar(Position target)
        {
            Double dX = Math.Pow(target.X - this.X, 2);
            Double dY = Math.Pow(target.Y - this.Y, 2);
            Double distance = Math.Sqrt(dX + dY);
            float result = (float)distance;

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

namespace Homework000
{
    class Position
    {
        public string name;
        public float X;
        public float Y;
        public Position()
        {
            Console.WriteLine("-Position이 지정되었습니다.-");
        }
    }
}

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

C#21.03.15.과제 6  (0) 2021.03.15
C# 21.03.12~14.과제 5  (0) 2021.03.12
C# 21.03.10.과제 3  (0) 2021.03.10
C# 21.03.09.과제 2  (0) 2021.03.09
C# 과제 21.08.20. 기본 데이터 형식 연습  (0) 2021.03.08