C#/수업 내용

[C#] 2021-08-26 오후

JSH1 2021. 8. 26. 15:34
class Program
{
    static void Main(string[] args)
    {
        Zealot zealot = new Zealot();
        Zergling zergling = new Zergling();

        while (true)
        {
            Console.ReadLine();

            if (zergling != null)
            {
                if (zealot == null)
                {
                    Console.WriteLine("{0}: 타겟이 없습니다.", zergling);
                    break;
                }

                else
                {
                    zergling.Attack(zealot);

                    if (zealot.Die())
                    {
                        zealot = null;
                    }
                }
            }

            if (zealot != null)
            {
                if (zergling == null)
                {
                    Console.WriteLine("{0}: 타겟이 없습니다.", zealot);
                    break;
                }

                else
                {
                    zealot.Attack(zergling);

                    if (zergling.Die())
                    {
                        zergling = null;
                    }
                }
            }

        }

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

class Zealot
{
    int hp = 100;
    int shield = 60;
    int damage = 8;

    public Zealot()
    {
        Console.WriteLine("질럿이 생성되었습니다.");
    }

    public void Attack(Zergling zergling)
    {
        Console.WriteLine("질럿이 {0}을 공격합니다.", zergling);
        zergling.Hit(this.damage);
    }

    public void Hit(int damage)
    {
        this.shield -= damage;
        if (this.shield < 0)
        {
            this.hp += this.shield;
            this.shield = 0;
        }

        Console.WriteLine("질럿 hp:{0} ,shield:{1}\n", this.hp, this.shield);
    }

    public bool Die()
    {
        if (hp < 1)
        {
            Console.WriteLine("질럿이 죽었습니다.\n");
            return true;
        }

        return false;
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Zergling
{
    int hp = 35;
    int damage = 5;

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

    public void Attack(Zealot zealot)
    {
        Console.WriteLine("저글링이 {0}을 공격합니다.", zealot);
        zealot.Hit(this.damage);
    }

    public void Hit(int damage)
    {
        this.hp -= damage;
        Console.WriteLine("저글링 hp:{0}\n", this.hp);
    }

    public bool Die()
    {
        if (this.hp < 1)
        {
            Console.WriteLine("저글링이 죽었습니다.");
            return true;
        }

        return false;
    }
}


 

'C# > 수업 내용' 카테고리의 다른 글

[C#] 2021-08-27 오후  (0) 2021.08.27
[C#] class virtual override  (0) 2021.08.27
[C#] 2021-08-26 오전  (0) 2021.08.26
[C#] 2021-08-25 오후  (0) 2021.08.25
[C#] class  (0) 2021.08.25