C#

스타크래프트 마린, 메딕 만들기

s0002 2023. 1. 5. 11:58
using System;

namespace Study04
{
    class Program
    {
        static void Main(string[] args)
        {
            new App();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace Study04
{
    class App
    {
        public App()
        {
            Marine marine0 = new Marine("marine0",5,60);
           
            Console.WriteLine();

            marine0.Hit(35);

            Medic medic0 = new Medic("medic0",5.86f,50);

            medic0.Heal(marine0);
            medic0.Heal(marine0);
            medic0.Heal(marine0);
            medic0.Heal(marine0);
            medic0.Heal(marine0);
            medic0.Heal(marine0);
            medic0.Heal(marine0);
            medic0.Heal(marine0);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace Study04
{
    class Marine
    {
        //멤버변수
        public string name;
        public int damage;
        public int hp;
        public int maxHp;
 
        //생성자
        public Marine(string name,int damage, int hp)
        {
            this.name = name;
            this.damage = damage;
            this.hp = hp;
            this.maxHp = hp;
            Console.WriteLine("{0}이 생성되었습니다\n체력: {1}/{2}",this.name, this.hp, this.hp);    
        }

        //멤버메서드
        public void Move()
        {
            Console.WriteLine("{0}이 이동했습니다", this.name);         
        }

        public void Attack(Marine target)
        {
            Console.WriteLine("{0}이 {1}을(를) 공격했습니다", this.name,target.name);
            Hit(this.damage);

        }

        public void Hit(int damage)
        {
            this.hp = this.hp - damage;
            this.damage = damage;

            Console.WriteLine("{0}이(가) (-{1})만큼 피해를 입었습니다\n체력: {2}/{3}", this.name,this.damage, this.hp, this.maxHp);

            if (hp == 0)
            {
                Die();
            }

            Console.WriteLine();
        }
        public void Die()
        {
            Console.WriteLine("{0}이(가) 죽었습니다",this.name);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace Study04
{
    class Medic
    {
        //멤버변수
        string name;
        float healAmount;
        int hp;
        int maxHp=200;

        //생성자
        public Medic(string name,float healAmount, int hp)
        {
            this.name = name;
            this.healAmount = healAmount;
            this.hp = hp;

            Console.WriteLine("{0}이 생성되었습니다", this.name);
            Console.WriteLine("체력:{0}/{1}", this.hp, maxHp);
            Console.WriteLine();
        }

        //멤버메서드
        public void Heal(Marine target)
        {
            target.hp = target.hp + (int)this.healAmount;
            this.hp = this.hp - 5;

            Console.WriteLine("{0}이(가) {1}을(를) 치료했습니다",this.name,target.name);
            Console.WriteLine();
            Console.WriteLine("{0} 체력:{1}/{2}", target.name, target.hp, target.maxHp);
            Console.WriteLine("{0} 체력:{1}/{2}", this.name, this.hp, this.maxHp);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace Study04
{
    class Medic
    {
        //멤버변수
        string name;
        float healAmount;
        int hp;
        int maxHp=200;

        //생성자
        public Medic(string name,float healAmount, int hp)
        {
            this.name = name;
            this.healAmount = healAmount;
            this.hp = hp;

            Console.WriteLine("{0}이 생성되었습니다", this.name);
            Console.WriteLine("체력:{0}/{1}", this.hp, maxHp);
            Console.WriteLine();
        }

        //멤버메서드
        public void Heal(Marine target)
        {
            if (target.hp >= target.maxHp)
            {
                Console.WriteLine("더이상 치료할 수 없습니다");
            }
            else if (this.hp <= 5)
            {
                Console.WriteLine("에너지가 부족합니다");
            }
            else
            {
                target.hp = target.hp + (int)this.healAmount;
                if (target.hp > target.maxHp)
                {
                    target.hp = target.maxHp;
                }
                this.hp = this.hp - 5;

                Console.WriteLine("{0}이(가) {1}을(를) 치료했습니다", this.name, target.name);
                Console.WriteLine("{0} 체력:{1}/{2}", target.name, target.hp, target.maxHp);
                Console.WriteLine("{0} 체력:{1}/{2}", this.name, this.hp, this.maxHp);
                Console.WriteLine();
            }
        }
    }
}