K-digital traning/C#프로그래밍

스타크래프트 - 마린, 저글링, 메딕

내꺼블로그 2023. 7. 24. 11:51

(1) 마린

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;
        int 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}, {1})", this.x, this.y);
            Console.WriteLine("생명력: {0}", this.hp);
            Console.WriteLine("공격력: {0}", this.damage);
            Console.WriteLine("이동속도: {0}", this.moveSpeed);
        }

        //생명력을 반환하는 메서드
        public int GetHp()
        {
            //반환하고 싶은 값
            return this.hp; //메서드를 종료하고 반환값이 있는 경우 반환한다.
        }

        public int GetDamage()
        {
            return this.damage;
        }

        public float GetMoveSpeed()
        {
            return this.moveSpeed;
        }

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

        public void MoveStop()
        {
            Console.WriteLine("정지했습니다.");
        }

        //저글링을 공격하다
        public void Attack(Zergling target)
        {
            Console.WriteLine("{0}을 공격했습니다.", target);
            target.HitDamage(this, this.damage);
        }

        //피해를 받는 메서드
        public void HitDamage(int damage)
        {
            this.hp -= damage;
            Console.WriteLine("피해를 받았습니다. 남은 생명력: {0}", hp);
        }

        //치료받는 메서드
        public void IncreaseHp(float heal)
        {
            Console.WriteLine("치료(+{0})를 받았습니다.", (int)heal);
            this.hp += (int)heal;
            if(this.hp>this.maxHp) this.hp=this.maxHp;
            Console.WriteLine("생명력: {0}/{1}", this.hp, this.maxHp);

        }
        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);
        }
    }
}

 

 

 

 

(2) 저글링

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;
        int y;

        //생성자
        public Zergling(int hp, int damage, float moveSpeed)
        {
            this.hp = hp;
            this.damage = damage;
            this.moveSpeed = moveSpeed;

            Console.WriteLine("저글링이 생성되었습니다.");
        }

        //이동하다
        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 SetPosition(int x, int y)
        {
            this.x = x;
            this.y = y;
            Console.WriteLine("좌표 설정완료: ({0}, {1})", this.x, this.y);
        }

        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);
        }     
        
    }
}

 

 

 

 

(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("메딕이 생성되었습니다.");
        }

        //정지
        public void MoveStop()
        {
            Console.WriteLine("정지했습니다.");
        }

        //걷기
        public void Move()
        {
            Console.WriteLine("이동했습니다.");
        }

        //치료
        public void Heal(Marine target)
        {
            target.IncreaseHp(this.heal);
            //Console.WriteLine("{0}을 치료했습니다, {0}생명력: {1}", target, target.GetHp());
        }

        //사망
        public void Die()
        {
            Console.WriteLine("사망했습니다.");
        }

        //상태출력
        public void PrintProperties()
        {
            Console.WriteLine("생명력: {0}", this.hp);
            Console.WriteLine("초당치료량: {0}", this.heal);
            Console.WriteLine("이동속도: {0}", this.moveSpeed);
        }
    }
}

 

 

(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.81f, 5, 0);
            marine.HitDamage(3);

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

 

 

 

결과

 

'K-digital traning > C#프로그래밍' 카테고리의 다른 글

1차원 배열 인벤토리  (0) 2023.07.25
1차원 배열 인벤토리  (0) 2023.07.24
반복문 for  (0) 2023.07.20
Input, enum 활용  (0) 2023.07.20
열거형(enum)  (0) 2023.07.20