반응형
using System;
using System.Collections;
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; }
public bool IsEquipped { get; set; } = false;
public int amt { get; set; }
// 부모 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;
GameManager.player.dfs += defend;
Text.TextingLine($"{name} 아이템 장착 ! ", ConsoleColor.Magenta);
}
public override void UnUse() // 해제시 장비 방어력 감소
{
GameManager.player.equipDfs -= defend;
GameManager.player.dfs -= defend;
Text.TextingLine($"{name} 아이템 해제 ! ", ConsoleColor.Magenta);
}
public Armour(string name, double buyPrice, int defend)
{
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;
GameManager.player.atk += attack;
Text.TextingLine($"{name} 아이템 장착 ! ", ConsoleColor.Magenta);
}
public override void UnUse() // 장착시 공격력 감소
{
GameManager.player.equipAtk -= attack;
GameManager.player.atk -= attack;
Text.TextingLine($"{name} 아이템 해제 ! ", ConsoleColor.Magenta);
}
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 int pHeatlh; // 체력포션의 체력 올려주는 값
public int pStrength; // 힘포션의 공격력양
public override string Description() { return null; }
public override void Use()
{
Text.TextingLine($"{name} 아이템 사용 ! ", ConsoleColor.Magenta);
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)
};
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static ForArt;
namespace TeamProejct_Dungeon
{
public class Shop
{
//List<List<Armour>> ShopList;
//------갑옷류--------
//1. 2. 3.for(int i ~~~~)
//아머리스트[(int)ItemType.Armour][i]
//------무기류--------
//무기템리스트
//----소모품---
//7.8.9.소모품
//----서비스류-----
//휴식
//플레이어한테 maxhp 50% 만큼 더한 다음. 최대치 안넘는지 검사.
//반환할 때는 게임매니저 인벤토리한테 AddItem 써가지고 추가.(DeepCopy())
private List<List<IItem>> shopList; // 접근
public Shop()
{
// 아이템 데이터베이스에서 종류별 아이템 리스트를 추가
shopList = new List<List<IItem>>
{
new List<IItem>(ItemDatabase.armourList),
new List<IItem>(ItemDatabase.weaponList),
new List<IItem>(ItemDatabase.consumableList)
};
}
// switch case 써서 카테고리 나누기
public void DisplayItems() // DisplayItems를 호출하면 => Buy호출
{
while (true)
{
Console.Clear();
AsciiArt.Draw(imagePath, 20);
Console.WriteLine("--- 상점 목록 ---");
Text.TextingLine("1. 갑옷", ConsoleColor.White);
Text.TextingLine("2. 무기", ConsoleColor.White);
Text.TextingLine("3. 소비", ConsoleColor.White);
Text.TextingLine("4. 휴식", ConsoleColor.White);
Text.TextingLine("5. 판매\n", ConsoleColor.White);
Text.TextingLine("0. 나가기", ConsoleColor.White);
Text.TextingLine("구매하고싶은 목록을 선택해주세요");
int index = 1;
int category = Text.GetInput(null, 1, 2, 3, 4, 5, 0);
Console.Clear();
switch (category - 1)
{
case (int)ItemType.Armour:
AsciiArt.Draw(imagePath, 20);
Console.WriteLine("----------갑옷류----------");
for (int i = 0; i < shopList[0].Count; i++)
{
Console.WriteLine($"{index}. {shopList[0][i].name} - 가격: {shopList[0][i].buyPrice}");
index++;
}
Buy(category); // 구매 호출
break;
case (int)ItemType.Weapon:
AsciiArt.Draw(imagePath, 20);
Console.WriteLine("----------무기류----------");
for (int i = 0; i < shopList[1].Count; i++)
{
Console.WriteLine($"{index}. {shopList[1][i].name} - 가격: {shopList[1][i].buyPrice}");
index++;
}
Buy(category); // 구매 호출
break;
case (int)ItemType.Consumable:
AsciiArt.Draw(imagePath, 20);
Console.WriteLine("----------소비류----------");
for (int i = 0; i < shopList[2].Count; i++)
{
Console.WriteLine($"{index}. {shopList[2][i].name} - 가격: {shopList[2][i].buyPrice}");
index++;
}
Buy(category); // 구매 호출
break;
case 3:
AsciiArt.Draw(imagePath, 20);
Console.WriteLine("----------휴식중----------");
Rest();
break;
case -1:
return;
case 4:
Sell();
break;
default:
Console.WriteLine("잘못입력하셨습니다.");
break;
}
}
}
public void Buy(int categoryIndex)
{
Console.WriteLine("4. 나가기");
Console.Write("\n구매하려는 물건의 번호를 입력하세요\n");
int category = Text.GetInput(null, 1, 2, 3,4);
if (category == 4) // 나가기
return;
IItem selectedItem = shopList[categoryIndex -1][category - 1];
// 골드 부족 확인
if (GameManager.player.gold < selectedItem.buyPrice)
{
Console.WriteLine("골드가 부족합니다.");
Console.ReadLine();
return;
}
// 구매 처리
GameManager.player.gold -= (int)selectedItem.buyPrice;
GameManager.player.inven.AddItem(selectedItem.DeepCopy());
Console.WriteLine($"{selectedItem.name}을(를) 구매했습니다! 남은 골드: {GameManager.player.gold}");
Console.ReadLine();
}
public void Rest() // 휴식하기
{
Console.WriteLine($"현재 체력은{GameManager.player.hp} 입니다.");
Console.WriteLine($"현재 마나는{GameManager.player.mp} 입니다.");
GameManager.player.hp += GameManager.player.maxHp / 2; // 플레이어 최대체력 50퍼센트 체력 회복
GameManager.player.mp += (int)Math.Round(GameManager.player.maxMp * 0.7); // 플레이어 마나 반올림
if (GameManager.player.hp > GameManager.player.maxHp)
{
GameManager.player.hp = GameManager.player.maxHp; // 최대체력보다 체력이 높으면 최대체력으로 보정
}
if (GameManager.player.mp > GameManager.player.maxMp) // 최대 마나보다 마나가 높으면 최대마나로 보정
{
GameManager.player.mp = GameManager.player.maxMp;
}
Text.TextingLine($"휴식후 현재 체력은{GameManager.player.hp} 입니다.",ConsoleColor.DarkYellow);
Text.TextingLine($"휴식후 현재 마나는{GameManager.player.mp} 입니다.", ConsoleColor.DarkYellow);
Console.ReadLine();
}
public void Sell() // 판매하기
{
Console.Clear();
GameManager.inven.ShowInventory();
GameManager.inven.SellingInventory();
}
}
}
이번 팀프로젝트하면서 느낀점은
다양한 라이브러리를 많이 사용해보고 경험해봐야할 거 같다
프로젝트를 접하는게 거의 처음이다보니
많은 것들이 낯설게 느껴졌다
반응형
'Language > C#' 카테고리의 다른 글
| 인터페이스 (0) | 2025.03.04 |
|---|---|
| [C#] delegate (0) | 2025.02.28 |
| [C#] TextRPG 휴식 (0) | 2025.02.12 |
| [C#] TextRPG 상점 구현 (0) | 2025.02.11 |
| [C#] 얕은 복사 (0) | 2025.02.10 |