C#

마린 vs 저글링

송현호 2023. 7. 21. 17:45
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;

namespace learndotnet
{
    internal class Zergling
    {
        public int hp;
        int maxHp = 35;
        int damage = 5;
        int armor = 0;
        public Zergling()
        {
            hp = maxHp;
            Console.WriteLine("저글링이 생성되었습니다.");
        }

        public void Attack(Marine target)
        {
            if (this.hp > 0)
            {
                if (target.hp > 0)
                {
                    Console.WriteLine("저글링이 {0}의 데미지를 입혔습니다.", damage);
                    target.HitDamage(this.damage);
                }
                else
                {
                    Console.WriteLine("타겟이 이미 죽었습니다.");
                }
            }
            else
            {
                return;
            }
        }
        public void HitDamage(int damage)
        {
            this.hp -= damage;
            if (this.hp <= 0)
            {
                Console.WriteLine("저글링이 죽었습니다.");
            }
        }
    }
}​
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();
            Zergling zergling = new Zergling();

            marine.Attack(zergling);
            zergling.Attack(marine);
            marine.Attack(zergling);
            zergling.Attack(marine);
            marine.Attack(zergling);
            zergling.Attack(marine);
            marine.Attack(zergling);
            zergling.Attack(marine);
            marine.Attack(zergling);
            zergling.Attack(marine);
            marine.Attack(zergling);
            zergling.Attack(marine);
            marine.Attack(zergling);
            zergling.Attack(marine);

        }
    }
}​
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace learndotnet
{
    internal class Marine
    {
        public int hp;
        int maxHp = 40;
        int damage = 6;
        int armor = 0;
        string target;

        public Marine()
        {
            hp = maxHp;
            Console.WriteLine("마린이 생성되었습니다.");
        }

        public void Attack(Zergling target)
        {
            if (this.hp > 0)
            {
                if (target.hp > 0)
                {
                    Console.WriteLine("마린이 {0}의 데미지를 입혔습니다.", damage);
                    target.HitDamage(this.damage);
                }
                else
                {
                    Console.WriteLine("타겟이 이미 죽었습니다.");
                }
            }

            else
            {
                return;
            }
        }
        public void HitDamage(int damage)
        {
            this.hp -= damage;
            if (this.hp <= 0)
            {
                Console.WriteLine("저글링이 죽었습니다.");
            }
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace learndotnet
{
    internal class Program
    {
        static void Main(string[] args)
        {
            new App();
        }
    }
}