본문 바로가기
KDT/C# 프로그래밍

23/07/24 메딕 마린 힐

by 잰쟁 2023. 7. 24.
728x90
using starcraft;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Starcraft
{
    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);
      
        }
    }
}
using Starcraft;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace starcraft
{
    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("치료 했습니다.");
        }

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

        //힐 생성
        public void Heal(Marine target)
        {
            Console.WriteLine("{0}에게 치료({1})를 했습니다.",target,this.heal);
            target.IncreaseHp(this.heal);
        }

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

        }
    }
}
using starcraft;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Configuration;
using System.Text;
using System.Threading.Tasks;

namespace Starcraft
{
    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 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 int GetHp()
        {
            //반환하고 싶은 값
           return this.hp; //메서드를 종료하고 반환값이 있는 경우
        }

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

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

        //저글링을 공격하다
        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}를 받았습니다, 생명력: {1}", damage, this.hp);
        }

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