본문 바로가기
C# 언어/C# 기초 문법

[C#] 객체지향 직업선택

by 후야- 2024. 3. 30.

1. 파일 분리 , Player 작업

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

namespace _240330
{
    // 똑같이 열거형
    enum PlayerType
    {
        None = 0,
        Warrial = 1,
        Archer = 2,
        Magition = 3,
    }

    internal class Player
    {
        protected PlayerType type;
        protected int hp = 0;
        protected int attack = 0;

        protected Player(PlayerType type)      // 아무것도 인자가 없으면 사용 불가
        {
            this.type = type;
        }

        public void SetInfo(int hp, int attack)    // 직접 적기
        {
            this.hp = hp;
            this.attack = attack;
        }

        // 외부에서 궁금할 수 있어서
        public int GetHp() { return hp; }
        public int GetAttack() { return attack; }
    }

    class Warrial : Player
    {
        // 생성자
        public Warrial() : base(PlayerType.Warrial)
        {
            SetInfo(100, 10);
        }
    }

    class Archer : Player
    {
        public Archer() : base(PlayerType.Archer)
        {
            SetInfo(80, 12);
        }

    }

    class Magition : Player
    {
        public Magition() : base(PlayerType.Magition)
        {
            SetInfo(70, 15);
        }
    }
}

 

'C# 언어 > C# 기초 문법' 카테고리의 다른 글

[C#] 객체지향  (0) 2024.03.22
직업 선택  (0) 2024.03.19
[C#] 함수  (0) 2024.03.19
[C#] 열거형  (0) 2024.03.19
[C#] 반복문 / break / continue  (0) 2024.03.19