[C#] DeepCopy

2025. 2. 10. 20:48·Language/C#
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TeamProejct_Dungeon
{
    public enum ItemType
    {
        Armour,
        Weapon,
        Consumable
    }
    public class IItem
    {
        public virtual string name { get; set; }

        public virtual double buyPrice { get; set; } // 구매 가격
        public virtual double sellPrice { get; set; } // 판매 가격 85퍼센트의 가격 판매 
        public virtual ItemType type { get; set; }
        public virtual string Description() { return null; }


        // 부모 virtual deepcopy 메소드 선언
        // new Armour(this.name, ~
        // new Weapon
        // new Consumalbe(
        // name = this.name
        // ?? 

        public virtual IItem DeepCopy() // Deep Copy 함수 
        {
            return null;
        }
        public virtual void Use() { }//장착. 혹은 소비.
        public virtual void UnUse() { }//장착 해제(포션은 제외)

    }

    //상속해가지고 3가지 클래스 만드는 거로. 생성자에서 type 변수는 열거형 맞춰서.

    public class Armour : IItem // 방어구
    {
        public override string name { get; set; }
        public override double buyPrice { get; set; }
        public override double sellPrice { get; set; }
        public override ItemType type { get; set; }

        public int defend; // 방어력
        public override string Description() { return $"방어력이 {defend}만큼 상승하였습니다."; }

        public override void Use() { GameManager.player.equipDfs += defend; }// 장착시 장비 방어력 증가
        public override void UnUse() { GameManager.player.equipDfs -= defend; }// 해제시 장비 방어력 감소

        public Armour(string name, double buyPrice, int defend = 0)
        {
            this.name = name;
            this.buyPrice = buyPrice;
            this.sellPrice = Math.Round(buyPrice * 0.85);
            this.defend = defend;
            type = ItemType.Armour;

        }

        public override IItem DeepCopy()
        {
            return new Armour(this.name, this.buyPrice, this.defend);
        }

    }

    public class Weapon : IItem // 무기
    {
        public override string name { get; set; }
        public override double buyPrice { get; set; }
        public override double sellPrice { get; set; }

        public int attack;
        public override ItemType type { get; set; }

        public override string Description() { return $"공격력이 {attack}만큼 상승하였습니다"; }

        public override void Use() { GameManager.player.equipAtk += attack; } // 장착시 공격력 상승
        public override void UnUse() { GameManager.player.equipAtk -= attack; } // 장착시 공격력 감소

        public Weapon(string name, double buyPrice, int attack = 0)
        {
            this.name = name;
            this.buyPrice = buyPrice;
            this.sellPrice = Math.Round(buyPrice * 0.85);
            this.attack = attack;
            type = ItemType.Weapon;
        }

        public override IItem DeepCopy()
        {
            return new Weapon(this.name, this.buyPrice, this.attack);
        }
    }

    public class Consumable : IItem // 소비
    {
        public override string name { get; set; }
        public override double buyPrice { get; set; }
        public override double sellPrice { get; set; }

        public override ItemType type { get; set; }

        public static int amt = 0; // 포션 수량

        public int pHeatlh; // 체력포션의 체력 올려주는 값

        public int pStrength; // 힘포션의 공격력양
        public override string Description() { return null; }

        public override void Use()
        {
            if (amt <= 0) // 포션이 없을 때 
            {
                Console.WriteLine("포션이 없습니다. 포션을 구매해주세요."); // 포션 구매 요청
                return;
            }

            if (pHeatlh > 0)
            {
                GameManager.player.hp += pHeatlh; // 체력 상승
                Text.TextingLine($"{this.pHeatlh} 를 회복했습니다.", ConsoleColor.Green);
            }
            if (pStrength > 0)
            {
                GameManager.player.atk += pStrength; // 공격력 상승
                Text.TextingLine($"{this.pStrength} 만큼 공격력이 상승했습니다.", ConsoleColor.Green);
            }

            if (GameManager.player.hp > GameManager.player.maxHp) // 체력 회복 후, 최대 체력보다 높으면
            {
                GameManager.player.hp = GameManager.player.maxHp; // 최대 체력으로 보정

            }
            amt--; // 포션 수량 감소
        }

        public Consumable(string name, double buyPrice, int health, int strength, int amount = 1)
        {
            this.name = name;
            this.buyPrice = buyPrice;
            sellPrice = Math.Round(buyPrice * 0.85);
            pHeatlh = health; // 체력 포션 상승값
            pStrength = strength; // 힘 포션 상승값

            type = ItemType.Consumable;
            amt += amount;


        }

        public override IItem DeepCopy()
        {
            return new Consumable(this.name, this.buyPrice, this.pHeatlh, this.pStrength);
        }



    }

    // 데이터베이스 
    public static class ItemDatabase
    {

        static public List<Armour> armourList = new List<Armour>
        {
            new Armour("천 갑옷",100,3),
            new Armour("불사의 갑옷",200,5),
            new Armour("스파르타의 갑옷",300,10)
        };

        static public List<Weapon> weaponList = new List<Weapon>
        {
            new Weapon("나무 칼",50,3),
            new Weapon("여포의 창",100, 7),
            new Weapon("스파르타의 칼", 200 ,10)
        };

        static public List<Consumable> consumableList = new List<Consumable>
        {
            new Consumable("힐링 포션",50,30,0),
            new Consumable("힘 포션",100,0,7),
            new Consumable("만병통치약",200,10,10)
        };
    }

}

'Language > C#' 카테고리의 다른 글

[C#] TextRPG 상점 구현  (0) 2025.02.11
[C#] 얕은 복사  (0) 2025.02.10
[C#] List  (0) 2025.02.07
[C#] Convert.ToInt32() vs int.Parse()  (0) 2025.02.06
[C#] 상속  (0) 2025.02.06
'Language/C#' 카테고리의 다른 글
  • [C#] TextRPG 상점 구현
  • [C#] 얕은 복사
  • [C#] List
  • [C#] Convert.ToInt32() vs int.Parse()
Xenawn
Xenawn
제넌 게임개발 블로그
  • Xenawn
    Xenawn
    Xenawn
  • 전체
    오늘
    어제
    • 분류 전체보기 (79)
      • Language (24)
        • C++ (4)
        • C# (20)
      • Game Engine (32)
        • Unity (19)
        • Unity API (1)
        • Game Project (12)
      • Git (2)
      • Algorithm (11)
        • BOJ [C++] (10)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    프레임
    C++
    게임개발
    내일배움캠프
    1181
    FizzBuzz
    백준
    CPP
    POTION
    문자열 보간
    FPS
    headbob
    Unity
    블랙잭
    객체
    BOJ
    포션
    c#
    카메라 움직임
    스파르타내일배움캠프 #스파르타내일배움캠프til
    리스트
    걸음fps
    유니티
    string format
    프로퍼티
    클래스
    배열
    알고리즘
    fps cam
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
Xenawn
[C#] DeepCopy

개인정보

  • 티스토리 홈
  • 포럼
  • 로그인
상단으로

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.