using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharp
{
// ================================
// [공통 크리처(Creature) 클래스]
// 플레이어와 몬스터의 공통 속성을 포함하는 기본 클래스
// ================================
public enum CreatureType
{
None,
Player = 1,
Monster = 2
}
class Creature
{
private CreatureType type; // 크리처 타입 (Player 또는 Monster)
protected int hp = 0; // 체력
protected int attack = 0; // 공격력
protected Creature(CreatureType 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; }
// 생존 여부를 확인하는 메서드
public bool IsDead() { return hp <= 0; }
// 데미지를 받을 때 호출되는 메서드
public void OnDamaged(int damage)
{
hp -= damage;
if (hp < 0)
hp = 0;
}
}
// ================================
// [플레이어 클래스 및 직업 구분]
// ================================
public enum PlayerType
{
None = 0,
Knight = 1,
Archer = 2,
Mage = 3
}
class Player : Creature
{
protected PlayerType type = PlayerType.None;
// Player는 직접 생성할 수 없으며, 하위 클래스를 통해 생성됨
protected Player(PlayerType type) : base(CreatureType.Player)
{
this.type = type;
}
public PlayerType GetPlayerType() { return type; }
}
// ================================
// [플레이어 직업 클래스]
// ================================
class Knight : Player
{
public Knight() : base(PlayerType.Knight)
{
SetInfo(100, 10); // 체력 100, 공격력 10
}
}
class Archer : Player
{
public Archer() : base(PlayerType.Archer)
{
SetInfo(75, 12); // 체력 75, 공격력 12
}
}
class Mage : Player
{
public Mage() : base(PlayerType.Mage)
{
SetInfo(50, 15); // 체력 50, 공격력 15
}
}
// ================================
// [몬스터 클래스 및 타입 구분]
// ================================
public enum MonsterType
{
None = 0,
Slime = 1,
Orc = 2,
Skeleton = 3
}
class Monster : Creature
{
protected MonsterType type = MonsterType.None;
// Monster는 직접 생성할 수 없으며, 하위 클래스를 통해 생성됨
protected Monster(MonsterType type) : base(CreatureType.Monster)
{
this.type = type;
}
public MonsterType GetMonsterType() { return type; }
}
// ================================
// [몬스터 종류 클래스]
// ================================
class Slime : Monster
{
public Slime() : base(MonsterType.Slime)
{
SetInfo(10, 1); // 체력 10, 공격력 1
}
}
class Orc : Monster
{
public Orc() : base(MonsterType.Orc)
{
SetInfo(20, 2); // 체력 20, 공격력 2
}
}
class Skeleton : Monster
{
public Skeleton() : base(MonsterType.Skeleton)
{
SetInfo(15, 5); // 체력 15, 공격력 5
}
}
}
Creature 클래스는 플레이어(Player) 와 몬스터(Monster) 의 공통 속성과 기능을 포함합니다.
public enum CreatureType
{
None,
Player = 1,
Monster = 2
}
CreatureType 열거형(Enum)을 활용하여 크리처의 타입을 Player와 Monster로 구분합니다.
class Creature
{
private CreatureType type; // 크리처 타입 (Player 또는 Monster)
protected int hp = 0; // 체력
protected int attack = 0; // 공격력
protected Creature(CreatureType 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; }
public bool IsDead() { return hp <= 0; }
public void OnDamaged(int damage)
{
hp -= damage;
if (hp < 0)
hp = 0;
}
}
✔ hp, attack 속성을 통해 체력과 공격력을 저장
✔ SetInfo(int hp, int attack) 메서드로 초기 상태 설정 가능
✔ OnDamaged(int damage) 메서드로 데미지를 받을 때 체력 감소
✔ IsDead() 메서드로 생존 여부를 확인
플레이어는 기사(Knight), 궁수(Archer), 마법사(Mage) 등의 직업을 가질 수 있으며, Creature 클래스를 상속(Inheritance) 받아 확장합니다.
public enum PlayerType
{
None = 0,
Knight = 1,
Archer = 2,
Mage = 3
}
플레이어의 직업을 구분하는 PlayerType 열거형을 정의했습니다.
class Player : Creature
{
protected PlayerType type = PlayerType.None;
protected Player(PlayerType type) : base(CreatureType.Player)
{
this.type = type;
}
public PlayerType GetPlayerType() { return type; }
}
✔ Creature를 상속하여 기본적인 체력, 공격력, 데미지 처리 등의 기능을 상속받음
✔ type 필드를 통해 플레이어의 직업 타입을 저장
✔ GetPlayerType() 메서드를 통해 플레이어의 타입을 가져올 수 있음
기사(Knight), 궁수(Archer), 마법사(Mage) 클래스는 Player 클래스를 상속하여 직업별로 고유한 체력(HP)과 공격력(Attack) 을 설정합니다.
class Knight : Player
{
public Knight() : base(PlayerType.Knight)
{
SetInfo(100, 10); // 체력 100, 공격력 10
}
}
class Archer : Player
{
public Archer() : base(PlayerType.Archer)
{
SetInfo(75, 12); // 체력 75, 공격력 12
}
}
class Mage : Player
{
public Mage() : base(PlayerType.Mage)
{
SetInfo(50, 15); // 체력 50, 공격력 15
}
}
✔ Player 클래스를 상속하여 각 직업별 특성(체력, 공격력) 정의
✔ SetInfo(HP, Attack) 메서드를 사용해 초기 체력과 공격력을 설정
✔ 클래스마다 다른 직업 타입(PlayerType) 사용
몬스터도 Creature 클래스를 상속하며, 다양한 몬스터 타입을 가지도록 설계되었습니다.
public enum MonsterType
{
None = 0,
Slime = 1,
Orc = 2,
Skeleton = 3
}
몬스터의 종류를 구분하는 MonsterType 열거형을 정의했습니다.
class Monster : Creature
{
protected MonsterType type = MonsterType.None;
protected Monster(MonsterType type) : base(CreatureType.Monster)
{
this.type = type;
}
public MonsterType GetMonsterType() { return type; }
}
✔ Creature 클래스를 상속하여 몬스터의 체력, 공격력, 데미지 처리 기능을 상속받음
✔ type 필드를 통해 몬스터의 종류를 저장
✔ GetMonsterType() 메서드를 통해 몬스터의 타입을 가져올 수 있음
각 몬스터(Slime, Orc, Skeleton) 클래스는 Monster 클래스를 상속하여 몬스터별 고유한 체력과 공격력을 설정합니다.
class Slime : Monster
{
public Slime() : base(MonsterType.Slime)
{
SetInfo(10, 1); // 체력 10, 공격력 1
}
}
class Orc : Monster
{
public Orc() : base(MonsterType.Orc)
{
SetInfo(20, 2); // 체력 20, 공격력 2
}
}
class Skeleton : Monster
{
public Skeleton() : base(MonsterType.Skeleton)
{
SetInfo(15, 5); // 체력 15, 공격력 5
}
}
✔ Monster 클래스를 상속하여 몬스터별 체력과 공격력 정의
✔ SetInfo(HP, Attack) 메서드를 사용해 초기 체력과 공격력을 설정
✔ 클래스마다 다른 몬스터 타입(MonsterType) 사용