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

namespace _230105
{
    class App
    {
        public App()
        {
            Zergling zergling = new Zergling("저글링", 20, 5);
            Hydralisk hydralisk = new Hydralisk("히드라", 20, 5);

            zergling.Att(hydralisk);
            hydralisk.Hit(zergling);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _230105
{
    class Zergling
    {
        public string name;
        public int maxHp;
        public int hp;
        public int dmg;

        public Zergling(string name, int maxHp, int dmg)
        {
            this.name = name;
            this.maxHp = maxHp;
            this.hp = this.maxHp;
            this.dmg = dmg;
        }

        public void Att(Hydralisk target)
        {
            Console.WriteLine("{0}이 {1}를 공격({2})하였습니다.", this.name, target.name, this.dmg);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _230105
{
    class Hydralisk
    {
        public string name;
        public int maxHp;
        public int hp;
        public int dmg;

        public Hydralisk(string name, int maxHp, int dmg)
        {
            this.name = name;
            this.maxHp = maxHp;
            this.hp = this.maxHp;
            this.dmg = dmg;
        }

        public void Hit(Zergling attacker)
        {
            this.hp = hp - attacker.dmg;
            Console.WriteLine("{0}가 {1}에게 피해-({2})를 받았습니다", this.name, attacker.name, attacker.dmg);
        }
    }
}

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

배열을 활용한 인벤토리 구현2  (0) 2023.01.09
배열을 활용한 인벤토리 구현  (0) 2023.01.06
클래스/메서드 과제4  (0) 2023.01.05
클래스/메서드 과제3  (0) 2023.01.05
클래스/메서드 과제2  (0) 2023.01.05

+ Recent posts