using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Mission
{
public class App
{
GenericInventory inven2 = new GenericInventory(5);
public App()
{
DataManager.Instance.LoadMissionDatas();
DataManager.Instance.LoadMissionInfos();
DataManager.Instance.LoadRewardItemDatas();
GameStart();
}
public void GameStart()
{
Dictionary<int, MonsterData> dicMonsterdatas = new Dictionary<int, MonsterData>();
Dictionary<int, ItemData> dic = new Dictionary<int, ItemData>();
DataManager.Instance.LoadItemDatas();
DataManager.Instance.LoadMonsterDatas();
Console.WriteLine("플레이어 설정을 시작합니다.");
Console.Write("플레이어의 이름을 입력하세요: ");
string heroName = Console.ReadLine();
Hero hero = new Hero(heroName);
while (true)
{
Console.Clear();
Console.WriteLine("[플레이어 사냥 시뮬레이터]");
Console.WriteLine("----------------------------------");
Console.WriteLine("[몬스터 목록]");
Console.WriteLine("(1) 고블린");
Console.WriteLine("(2) 오우거");
Console.WriteLine("(3) 트 롤");
Console.WriteLine("----------------------------------");
Console.WriteLine("(4) 인벤토리 열기");
Console.WriteLine("(5) 아이템 꺼내기");
Console.WriteLine("(6) 미션창 열기");
Console.WriteLine("----------------------------------");
Console.WriteLine("[플레이어: <{0}>]", heroName);
//Console.WriteLine("체력: {0}", hero.heroHp);
//Console.WriteLine("공격력: {0}", hero.heroDmg);
//Console.WriteLine("현재 무기: ");
Console.WriteLine("----------------------------------");
Console.Write("번호를 입력하세요: ");
int num = Convert.ToInt32(Console.ReadLine());
switch (num)
{
case 1:
HuntMonster(num);
break;
case 2:
HuntMonster(num);
break;
case 3:
HuntMonster(num);
break;
case 4:
inven2.DisplayInventory();
Console.WriteLine("계속하려면 아무 키나 누르십시오 . . .");
Console.ReadKey();
break;
case 5:
Console.Write("꺼낼 아이템의 이름을 입력해주세요: ");
string iName = Console.ReadLine();
if (iName == "장검")
{
inven2.setItem<Item>(DataManager.Instance.GetItem(100).id);
Console.WriteLine("장검을 인벤토리에서 찾았습니다.");
Console.WriteLine("장검을 인벤토리에서 꺼냅니다.");
}
else if (iName == "단검")
{
inven2.setItem<Item>(DataManager.Instance.GetItem(101).id);
Console.WriteLine("단검을 인벤토리에서 꺼냈습니다.");
Console.WriteLine("단검을 인벤토리에서 꺼냅니다.");
}
else if (iName == "활")
{
inven2.setItem<Item>(DataManager.Instance.GetItem(102).id);
Console.WriteLine("활을 인벤토리에서 꺼냈습니다.");
Console.WriteLine("활을 인벤토리에서 꺼냅니다.");
}
else if (iName == "도끼")
{
inven2.setItem<Item>(DataManager.Instance.GetItem(103).id);
Console.WriteLine("도끼을 인벤토리에서 꺼냈습니다.");
Console.WriteLine("도끼을 인벤토리에서 꺼냅니다.");
}
else
{
Console.WriteLine("유효한 입력이 아닙니다");
}
Console.WriteLine("계속하려면 아무 키나 누르십시오 . . .");
Console.ReadKey();
break;
case 6:
OpenMission();
Console.ReadKey();
break;
}
}
}
public void HuntMonster(int num)
{
int selectNum = num;
int missionNum = 0;
if (selectNum== 1)
{
selectNum = 1000;
missionNum = 500;
}
else if (selectNum== 2)
{
selectNum = 1001;
missionNum = 501;
}
else if (selectNum == 3)
{
selectNum = 1002;
missionNum = 502;
}
Monster monster = new Monster(DataManager.Instance.GetMonster(selectNum));
Console.WriteLine("----------------------------------");
Console.WriteLine("{0}을(를) 사냥합니다.", monster.GetName());
var curruntMission = DataManager.Instance.dicMissionInfos.FirstOrDefault(x => x.Value.id == missionNum);
var maxMission = DataManager.Instance.dicMissionDatas.FirstOrDefault(x => x.Value.id == missionNum);
curruntMission.Value.progress += 1;
if (curruntMission.Value.progress == maxMission.Value.goal)
{
Console.WriteLine("미션: {0}을(를) 완료하셨습니다.", maxMission.Value.name);
Console.WriteLine("보상: {0}을(를) 획득 하셨습니다.", maxMission.Value.reward_item_name);
ItemData rewardItemData = new ItemData(maxMission.Value.reward_item_id,
maxMission.Value.reward_item_name);
Item rewardItem = new Item(rewardItemData);
inven2.AddItem(rewardItem);
curruntMission.Value.state = 2;
}
else if (curruntMission.Value.progress > maxMission.Value.goal)
{
curruntMission.Value.progress -= 1;
Item mItem = new Item(DataManager.Instance.GetItem(monster.data.item_id));
Console.WriteLine("{0}을(를) 획득하셨습니다.", mItem.data.name);
inven2.AddItem(mItem);
}
else
{
curruntMission.Value.state = 1;
Item mItem = new Item(DataManager.Instance.GetItem(monster.data.item_id));
Console.WriteLine("{0}을(를) 획득하셨습니다.", mItem.data.name);
inven2.AddItem(mItem);
}
Console.WriteLine("----------------------------------");
Console.WriteLine("계속하려면 아무 키나 누르십시오 . . .");
Console.ReadKey();
}
public void OpenMission()
{
Console.WriteLine("----------------------------------");
Console.WriteLine("[미션 창]");
int index = 1;
foreach (var missionData in DataManager.Instance.dicMissionDatas)
{
var missionInfo = DataManager.Instance.dicMissionInfos[missionData.Key];
string missionStatue = null ;
if(missionInfo.state == 0 || missionInfo.state ==1) { missionStatue = "진행중"; }
else { missionStatue = "완료"; }
Console.WriteLine("({0}). {1} 진척도: {2}/{3}, 보상: {4}x{5} ======= {6}", index++,
missionData.Value.name,
missionInfo.progress,
missionData.Value.goal,
missionData.Value.reward_item_name,
missionData.Value.reward_item_amount,
missionStatue);
}
Console.WriteLine("----------------------------------");
Console.WriteLine("닫기를 원하시면 아무키를 눌러주세요.");
}
}
}
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace Mission
{
public class DataManager
{
public static readonly DataManager Instance = new DataManager();
Dictionary<int, ItemData> dic = new Dictionary<int, ItemData>();
Dictionary<int, MonsterData> dicMonsterdatas = new Dictionary<int, MonsterData>();
public Dictionary<int, MissionData> dicMissionDatas = new Dictionary<int, MissionData>();
public Dictionary<int, RewardItemData> dicRewardItemDatas = new Dictionary<int, RewardItemData>();
public Dictionary<int, MissionInfo> dicMissionInfos = new Dictionary<int, MissionInfo>();
private DataManager() { }
public void LoadItemDatas()
{
dic.Add(100, new ItemData(100, "장검"));
dic.Add(101, new ItemData(101, "단검"));
dic.Add(102, new ItemData(102, "활"));
dic.Add(103, new ItemData(103, "도끼"));
}
public void LoadMonsterDatas()
{
dicMonsterdatas.Add(1000, new MonsterData(1000, "고블린", 100, 15));
dicMonsterdatas.Add(1001, new MonsterData(1001, "오우거", 101, 30));
dicMonsterdatas.Add(1002, new MonsterData(1002, "트롤", 102, 50));
}
public ItemData GetItem(int id)
{
return this.dic[id];
}
public MonsterData GetMonster(int id)
{
return this.dicMonsterdatas[id];
}
public void LoadMissionDatas()
{
var json = File.ReadAllText("./mission_data.json");
//Console.WriteLine(json);
MissionData[] missionDatas = JsonConvert.DeserializeObject<MissionData[]>(json);
dicMissionDatas = missionDatas.ToDictionary(x => x.id);
//Console.WriteLine("미션 데이터 로드 완료");
}
public void LoadRewardItemDatas()
{
var json = File.ReadAllText("./reward_item_data.json");
//Console.WriteLine(json);
RewardItemData[] RewardItemDatas = JsonConvert.DeserializeObject<RewardItemData[]>(json);
dicRewardItemDatas = RewardItemDatas.ToDictionary(x => x.id);
//Console.WriteLine("보상 아이템 데이터 로드 완료");
}
public void LoadMissionInfos()
{
var json = File.ReadAllText("./mission_info.json");
//Console.WriteLine(json);
MissionInfo[] MissionInfos = JsonConvert.DeserializeObject<MissionInfo[]>(json);
dicMissionInfos = MissionInfos.ToDictionary(x => x.id);
//Console.WriteLine("미션 상황 로드 완료");
}
public void SaveMissionInfos()
{
MissionInfo missionInfo = new MissionInfo();
//직렬화
string json = JsonConvert.SerializeObject(missionInfo);
//Console.WriteLine(json);
File.WriteAllText("./mission_info.json", json);
//Console.WriteLine("미션 현황 저장 완료");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mission
{
public class GenericInventory
{
private List<Item> items;
int capacity;
//생성자
public GenericInventory(int capacity)
{
this.capacity = capacity;
this.items = new List<Item>(capacity);
}
public void AddItem(Item item)
{
this.items.Add(item);
Console.WriteLine("{0}을(를) 인벤토리에 저장합니다.", item.data.name);
}
public T setItem<T>(int id) where T : Item
{
for (int i = 0; i < this.items.Count; i++)
{
var item = this.items[i];
if (item.data.id == id)
{
this.items.Remove(item);
return (T)item;
}
}
return null;
}
public void DisplayInventory()
{
Console.WriteLine("----------------------------------");
Console.WriteLine("<인벤토리 목록>");
for (int i = 0; i < this.items.Count; i++)
{
Console.WriteLine("[{0}]", items[i].data.name);
}
Console.WriteLine("----------------------------------");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mission
{
public class Hero
{
string heroName;
//public int heroHp = 100;
//public int heroDmg = 10;
enum weaponType
{
LongSword = 0,
ShortSword = 1,
}
public Hero(string name)
{
this.heroName = name;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mission
{
public class Item
{
public ItemData data
{
get;
private set;
}
public Item(ItemData data)
{
this.data = data;
}
public string GetName()
{
return this.data.name;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mission
{
//아이템의 정보
public class ItemData
{
public int id;
public string name;
//public int damage;
public ItemData(int id, string name)
{
this.id = id;
this.name = name;
//this.damage = damage;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace Mission
{
public class MissionData
{
public int id;
public string name;
public int goal;
public string reward_item_name;
public int reward_item_id;
public int reward_item_amount;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mission
{
public class MissionInfo
{
public int id;
public int progress;
public int state;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mission
{
public class Monster
{
public MonsterData data
{
get;
private set;
}
public Monster(MonsterData data)
{
this.data = data;
}
public string GetName()
{
return this.data.name;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mission
{
public class MonsterData
{
public int id;
public string name;
public int item_id;
public int monsterHP;
//public int monsterDmg;
public MonsterData(int id, string name, int item_id, int monsterHP)
{
this.id = id;
this.name = name;
this.item_id = item_id;
this.monsterHP = monsterHP;
//this.monsterDmg = monsterDmg;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mission
{
public class RewardItemData
{
public int id;
public string item_name;
}
}
전에 포스팅한 몬스터 사냥 시뮬레이터에 미션창을 추가한 버전.
'KDT > C# 프로그래밍' 카테고리의 다른 글
신규 유저와 기존 유저 (0) | 2023.07.28 |
---|---|
몬스터 잡고 아이템 드롭 후 아이템 가방에 넣기 (0) | 2023.07.28 |
아이템 정보 저장하기 (0) | 2023.07.27 |
대리자 연습(3) (0) | 2023.07.27 |
대리자 연습(2) (0) | 2023.07.27 |