C#프로그래밍

저글링, 마린, 메딕

다모아 2023. 7. 24. 11:50

1. 저글링 클래스

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

namespace LearnDotnet
{
    internal class Zergling
    {
        //멤버변수
        int hp;
        int damage;
        float moveSpeed;
        //생성자메서드
        public Zergling(int hp, int damage, float moveSpeed)
        {
            this.hp = hp;
            this.damage = damage;
            this.moveSpeed = moveSpeed;
            Console.WriteLine("저글링이 생성되었습니다.");
            Console.WriteLine("생명력 : {0}", this.hp);
            Console.WriteLine("공격력 : {0}", this.damage);
            Console.WriteLine("이동속도 : {0}", this.moveSpeed);
        }
        //멤버메서드
        public void Move()
        {
            Console.WriteLine("저글링이 이동했습니다.");
        }
        public void Attack()
        {
            Console.WriteLine("저글링이 공격했습니다.");
        }
        public void Die()
        {
            Console.WriteLine("저글링이 사망했습니다.");
        }
        public void PrintProperties()
        {
            Console.WriteLine("생명력 : {0}", this.hp);
            Console.WriteLine("공격력 : {0}", this.damage);
            Console.WriteLine("이동속도 : {0}", this.moveSpeed);
        }
    }
}

 

1. 저글링 App 클래스

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

namespace LearnDotnet
{
    internal class App
    {
        //생성자 메서드
        public App()
        {
            Zergling zergling = new Zergling(35, 5, 2.612f);

            zergling.Move();
            zergling.Attack();
            zergling.Die();
            zergling.PrintProperties();
        }
    }
}

 

2. 마린 App클래스

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

namespace LearnDotnet
{
    internal class App
    {
        //생성자 메서드
        public App()
        {
            Marine marine0 = new Marine(40, 6, 1.875f);
            int marine0Hp = marine0.GetHp();
            Console.WriteLine("마린의 생명력: {0}", marine0Hp);

            int marine0Damage = marine0.GetDamage();
            Console.WriteLine("마린의 공격력: {0}", marine0Damage);

            float marine0MoveSpeed = marine0.GetMoveSpeed();
            Console.WriteLine("마린의 이동속도: {0}", marine0MoveSpeed);
        }
    }
}

 

2. 마린 클래스

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

namespace LearnDotnet
{
    internal class Marine
    {
        //멤버변수,필드[데이터]
        int hp;
        int maxHp;
        int damage;
        float moveSpeed;

        //생성자 메서드
        public Marine(int hp, int damage, float moveSpeed)
        {
            this.hp = hp;
            this.damage = damage;
            this.moveSpeed = moveSpeed;
            Console.WriteLine("마린이 생성되었습니다.");
            Console.WriteLine("생명력 : {0}", this.hp);
            Console.WriteLine("공격력 : {0}", this.damage);
            Console.WriteLine("이동속도 : {0}", this.moveSpeed);
        }
        //멤버 메서드[기능]
        public void MoveStop()
        {

        }
        public void Move()
        {

        }
        public void Attack()
        {

        }
        public void Die()
        {

        }
        //생명력을 반환하는 메서드
        public int GetHp()
        {
            //반환하고 싶은 값
            return this.hp; //메서드를 종료하고 반환값이 있는 경우
        }
        public int GetDamage()
        {
            //공격력을 반환하는 메서드
            return this.damage;
        }
        public float GetMoveSpeed()
        {
            return this.moveSpeed;
        }
    }
}

 

3. 메딕 App클래스

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

namespace LearnDotnet
{
    internal class App
    {
        //생성자 메서드
        public App()
        {
            Medic medic = new Medic(60, 5.86f, 1.875f);
            medic.MoveStop();
            medic.Move();
            medic.Heal();
            medic.Die();
            medic.PrintProperties();
        }
    }
}

 

3. 메딕 클래스

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

namespace LearnDotnet
{
    internal class Medic
    {
        //멤버변수
        int hp;
        float heal;
        float moveSpeed;

        //생성자메서드
        public Medic(int hp, float heal, float moveSpeed)
        {
            this.hp = hp;
            this.heal = heal;
            this.moveSpeed = moveSpeed;

            Console.WriteLine("메딕이 생성되었습니다.");
            Console.WriteLine("생명력 : {0}", this.hp);
            Console.WriteLine("초당치료량 : {0}", this.heal);
            Console.WriteLine("이동속도 : {0}", this.moveSpeed);
        }
        //멤버메서드
        public void MoveStop()
        {
            Console.WriteLine("메딕이 정지했습니다.");
        }
        public void Move()
        {
            Console.WriteLine("메딕이 이동했습니다.");
        }
        public void Heal()
        {
            Console.WriteLine("메딕이 치료({0})했습니다.", this.heal);
        }
        public void Die()
        {
            Console.WriteLine("메딕이 사망했습니다.");
        }
        public void PrintProperties()
        {
            Console.WriteLine("생명력 : {0}", this.hp);
            Console.WriteLine("초당치료량 : {0}", this.heal);
            Console.WriteLine("이동속도 : {0}", this.moveSpeed);
        }
    }
}

 

4. 마린 클래스 [이동 목표 위치]

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

namespace LearnDotnet
{
    internal class Marine
    {
        //멤버변수,필드[데이터]
        int hp;
        int maxHp;
        int damage;
        float moveSpeed;
        int x, y;

        //생성자 메서드
        public Marine(int hp, int damage, float moveSpeed, int x, int y)
        {
            this.hp = hp;
            this.damage = damage;
            this.moveSpeed = moveSpeed;
            this.x = x;
            this.y = y;
            Console.WriteLine("마린이 생성되었습니다.");
            Console.WriteLine("생명력 : {0}", this.hp);
            Console.WriteLine("공격력 : {0}", this.damage);
            Console.WriteLine("이동속도 : {0}", this.moveSpeed);
            Console.WriteLine("위치: ({0},{1})", this.x, this.y);
        }
        //멤버 메서드[기능]
        public void MoveStop()
        {

        }
        public void Move(int x, int y) //이동 목표 좌표
        {
            // (5,0) -> (x,y) 이동했습니다.
            Console.WriteLine("({0},{1}) -> ({2},{3})로 이동했습니다.", this.x, this.y, x, y);
            this.x = x;
            this.y = y;
        }
        public void Attack()
        {

        }
        public void Die()
        {

        }
        //생명력을 반환하는 메서드
        public int GetHp()
        {
            //반환하고 싶은 값
            return this.hp; //메서드를 종료하고 반환값이 있는 경우
        }
        public int GetDamage()
        {
            //공격력을 반환하는 메서드
            return this.damage;
        }
        public float GetMoveSpeed()
        {
            return this.moveSpeed;
        }
        public void PrintProperties()
        {
            Console.WriteLine("생명력 : {0}", this.hp);
            Console.WriteLine("공격력 : {0}", this.damage);
            Console.WriteLine("이동속도 : {0}", this.moveSpeed);
            Console.WriteLine("위치: ({0},{1})", this.x, this.y);
        }
    }
}

 

4. 마린 App클래스[이동 목표 추가]

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

namespace LearnDotnet
{
    internal class App
    {
        //생성자 메서드
        public App()
        {
            Marine marine = new Marine(40, 6, 1.875f, 5, 0);
            marine.Move(4,0);
            marine.PrintProperties();
        }
    }
}

 

5. 저글링 클래스 [이동 목표 위치]

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

namespace LearnDotnet
{
    internal class Zergling
    {
        //멤버변수
        int hp;
        int damage;
        float moveSpeed;
        int x, y;

        //생성자메서드
        public Zergling(int hp, int damage, float moveSpeed)
        {
            this.hp = hp;
            this.damage = damage;
            this.moveSpeed = moveSpeed;
            Console.WriteLine("저글링이 생성되었습니다.");
            Console.WriteLine("생명력 : {0}", this.hp);
            Console.WriteLine("공격력 : {0}", this.damage);
            Console.WriteLine("이동속도 : {0}", this.moveSpeed);
        }
        //멤버메서드
        public void SetPosition(int x, int y)
        {
            this.x = x;
            this.y = y;
            Console.WriteLine("위치 : ({0},{1})", x, y);

        }
        public void Move()
        {
            Console.WriteLine("저글링이 이동했습니다.");
        }
        public void Attack()
        {
            Console.WriteLine("저글링이 공격했습니다.");
        }
        public void Die()
        {
            Console.WriteLine("저글링이 사망했습니다.");
        }
        public void PrintProperties()
        {
            Console.WriteLine("생명력 : {0}", this.hp);
            Console.WriteLine("공격력 : {0}", this.damage);
            Console.WriteLine("이동속도 : {0}", this.moveSpeed);
            Console.WriteLine("위치 : ({0},{1})", this.x, this.y);
        }
    }
}

 

5. 저글링 App클래스 [이동 목표 위치]

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

namespace LearnDotnet
{
    internal class App
    {
        //생성자 메서드
        public App()
        {
            Marine marine = new Marine(40, 6, 1.875f, 5, 0);

            Zergling zergling = new Zergling(35, 5, 2.61f);
            zergling.SetPosition(4, 0);
            zergling.PrintProperties();
        }
    }
}

6.  App클래스 [this를 매개변수로 사용, Attack]

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

namespace LearnDotnet
{
    internal class App
    {
        //생성자 메서드
        public App()
        {
            Marine marine = new Marine(40, 6, 1.875f, 5, 0);

            Zergling zergling = new Zergling(35, 5, 2.61f);
            zergling.SetPosition(4, 0);

            //마린이 저글링 공격
            marine.Attack(zergling);
        }
    }
}

 

6. 저글링 클래스 [this를 매개변수로 사용, Attack]

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

namespace LearnDotnet
{
    internal class Zergling
    {
        //멤버변수
        int hp;
        int damage;
        float moveSpeed;
        int x, y;

        //생성자메서드
        public Zergling(int hp, int damage, float moveSpeed)
        {
            this.hp = hp;
            this.damage = damage;
            this.moveSpeed = moveSpeed;
            Console.WriteLine("저글링이 생성되었습니다.");
            Console.WriteLine("생명력 : {0}", this.hp);
            Console.WriteLine("공격력 : {0}", this.damage);
            Console.WriteLine("이동속도 : {0}", this.moveSpeed);
        }
        //멤버메서드
        public void SetPosition(int x, int y)
        {
            this.x = x;
            this.y = y;
            Console.WriteLine("위치 : ({0},{1})", x, y);

        }
        public void Move()
        {
            Console.WriteLine("저글링이 이동했습니다.");
        }
        public void Attack()
        {
            Console.WriteLine("저글링이 공격했습니다.");
        }
        public void Die()
        {
            Console.WriteLine("저글링이 사망했습니다.");
        }
        //피해를 받는 메서드
        public void HitDamage(Marine marine, int damage)
        {
            this.hp -= damage;
            Console.WriteLine("공격자 : {0}", marine);
            Console.WriteLine("피해({0})을 받았습니다, 생명력 : {1}", damage, this.hp);
        }
        public void PrintProperties()
        {
            Console.WriteLine("생명력 : {0}", this.hp);
            Console.WriteLine("공격력 : {0}", this.damage);
            Console.WriteLine("이동속도 : {0}", this.moveSpeed);
            Console.WriteLine("위치 : ({0},{1})", this.x, this.y);
        }
    }
}

 

6. 마린 클래스 [this를 매개변수로 사용, Attack]

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

namespace LearnDotnet
{
    internal class Marine
    {
        //멤버변수,필드[데이터]
        int hp;
        int maxHp;
        int damage;
        float moveSpeed;
        int x, y;

        //생성자 메서드
        public Marine(int hp, int damage, float moveSpeed, int x, int y)
        {
            this.hp = hp;
            this.damage = damage;
            this.moveSpeed = moveSpeed;
            this.x = x;
            this.y = y;
            Console.WriteLine("마린이 생성되었습니다.");
            Console.WriteLine("생명력 : {0}", this.hp);
            Console.WriteLine("공격력 : {0}", this.damage);
            Console.WriteLine("이동속도 : {0}", this.moveSpeed);
            Console.WriteLine("위치: ({0},{1})", this.x, this.y);
        }
        //멤버 메서드[기능]
        public void MoveStop()
        {

        }
        public void Move(int x, int y) //이동 목표 좌표
        {
            // (5,0) -> (x,y) 이동했습니다.
            Console.WriteLine("({0},{1}) -> ({2},{3})로 이동했습니다.", this.x, this.y, x, y);
            this.x = x;
            this.y = y;
        }
        //저글링을 공격하다
        public void Attack(Zergling target)
        {
            Console.WriteLine("{0}을 공격했습니다.", target);
            target.HitDamage(this ,this.damage); //공격력 만큼 피해를 받는 메서드
        }
        public void Die()
        {

        }
        //생명력을 반환하는 메서드
        public int GetHp()
        {
            //반환하고 싶은 값
            return this.hp; //메서드를 종료하고 반환값이 있는 경우
        }
        public int GetDamage()
        {
            //공격력을 반환하는 메서드
            return this.damage;
        }
        public float GetMoveSpeed()
        {
            return this.moveSpeed;
        }
        public void PrintProperties()
        {
            Console.WriteLine("생명력 : {0}", this.hp);
            Console.WriteLine("공격력 : {0}", this.damage);
            Console.WriteLine("이동속도 : {0}", this.moveSpeed);
            Console.WriteLine("위치: ({0},{1})", this.x, this.y);
        }
    }
}

 

7. 메딕 클래스 [힐주기 IncreaseHp]

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

namespace LearnDotnet
{
    internal class Medic
    {
        //멤버변수
        int hp;
        float heal;
        float moveSpeed;

        //생성자메서드
        public Medic(int hp, float heal, float moveSpeed)
        {
            this.hp = hp;
            this.heal = heal;
            this.moveSpeed = moveSpeed;

            Console.WriteLine("메딕이 생성되었습니다.");
            Console.WriteLine("생명력 : {0}", this.hp);
            Console.WriteLine("초당치료량 : {0}", this.heal);
            Console.WriteLine("이동속도 : {0}", this.moveSpeed);
        }
        //멤버메서드
        public void MoveStop()
        {
            Console.WriteLine("메딕이 정지했습니다.");
        }
        public void Move()
        {
            Console.WriteLine("메딕이 이동했습니다.");
        }
        public void Heal(Marine target)
        {
            Console.WriteLine("{0}을 치료({1})를 했습니다.", target, this.heal);
            target.IncreaseHp(this.heal);
            
        }
        public void Die()
        {
            Console.WriteLine("메딕이 사망했습니다.");
        }
        public void PrintProperties()
        {
            Console.WriteLine("생명력 : {0}", this.hp);
            Console.WriteLine("초당치료량 : {0}", this.heal);
            Console.WriteLine("이동속도 : {0}", this.moveSpeed);
        }
    }
}

 

7. 마린 클래스 [힐받기 IncreaseHp]

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

namespace LearnDotnet
{
    internal class Marine
    {
        //멤버변수,필드[데이터]
        int hp;
        int maxHp;
        int damage;
        float moveSpeed;
        int x, y;

        //생성자 메서드
        public Marine(int maxHp, int damage, float moveSpeed, int x, int y)
        {
            this.maxHp = maxHp;
            this.hp = maxHp;
            this.damage = damage;
            this.moveSpeed = moveSpeed;
            this.x = x;
            this.y = y;
            Console.WriteLine("마린이 생성되었습니다.");
            Console.WriteLine("생명력 : {0}", this.hp);
            Console.WriteLine("공격력 : {0}", this.damage);
            Console.WriteLine("이동속도 : {0}", this.moveSpeed);
            Console.WriteLine("위치: ({0},{1})", this.x, this.y);
        }
        //멤버 메서드[기능]
        public void MoveStop()
        {

        }
        //피해를 받는 메서드
        public void HitDamage(int damage)
        {
            this.hp -= damage;
            Console.WriteLine("피해를 받았습니다. 생명력 : {0}", this.hp);
        }
        public void IncreaseHp(float heal)
        {
            this.hp += (int)heal;
            if(this.hp > this.maxHp)
            {
                this.hp = this.maxHp;
            }
            Console.WriteLine("생명력 : {0}", this.hp);
        }
        public void Move(int x, int y) //이동 목표 좌표
        {
            // (5,0) -> (x,y) 이동했습니다.
            Console.WriteLine("({0},{1}) -> ({2},{3})로 이동했습니다.", this.x, this.y, x, y);
            this.x = x;
            this.y = y;
        }
        //저글링을 공격하다
        public void Attack(Zergling target)
        {
            Console.WriteLine("{0}을 공격했습니다.", target);
            target.HitDamage(this ,this.damage); //공격력 만큼 피해를 받는 메서드
        }
        public void Die()
        {

        }
        //생명력을 반환하는 메서드
        public int GetHp()
        {
            //반환하고 싶은 값
            return this.hp; //메서드를 종료하고 반환값이 있는 경우
        }
        public int GetDamage()
        {
            //공격력을 반환하는 메서드
            return this.damage;
        }
        public float GetMoveSpeed()
        {
            return this.moveSpeed;
        }
        public void PrintProperties()
        {
            Console.WriteLine("생명력 : {0}", this.hp);
            Console.WriteLine("공격력 : {0}", this.damage);
            Console.WriteLine("이동속도 : {0}", this.moveSpeed);
            Console.WriteLine("위치: ({0},{1})", this.x, this.y);
        }
    }
}

 

7. App 클래스 [힐주기 힐받기]

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

namespace LearnDotnet
{
    internal class App
    {
        //생성자 메서드
        public App()
        {
            Marine marine = new Marine(40, 6, 1.875f, 5, 0);
            marine.HitDamage(3);

            Medic medic = new Medic(60, 5.8f, 1.875f);
            medic.Heal(marine);
        }
    }
}