using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Review10
{
public class Game
{
public Game()
{
this.LoadDatas();
Character user = new Character();
user.AcceptQuest(1001);
user.AcceptQuest(1002);
user.AcceptQuest(1003);
user.PrintAcceptedQuest();
user.onUpdateQuestEventHandler += (sender, args) =>
{
Quest.instance.UpdateQuest(args, 1);
};
user.PlantingCrops();
user.PlantingCrops();
user.PlantingCrops();
user.PlantingCrops();
DataManager.instance.Save(user);
}
private void LoadDatas()
{
DataManager.instance.LoadItemData();
DataManager.instance.LoadCurrencyData();
DataManager.instance.LoadQuestData();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Newtonsoft.Json;
namespace Review10
{
public sealed class DataManager
{
public static readonly DataManager instance = new DataManager();
Dictionary<int, ItemData> dicItemDatas;
Dictionary<int, CurrencyData> dicCurrencyDatas;
Dictionary<int, QuestData> dicQuestDatas;
private DataManager()
{ }
public void LoadItemData()
{
string json = File.ReadAllText("./item_data.json");
ItemData[] arr = JsonConvert.DeserializeObject<ItemData[]>(json);
this.dicItemDatas = new Dictionary<int, ItemData>();
foreach (ItemData data in arr)
{
this.dicItemDatas.Add(data.id, data);
}
}
public void LoadCurrencyData()
{
string json = File.ReadAllText("./currency_data.json");
CurrencyData[] arr = JsonConvert.DeserializeObject<CurrencyData[]>(json);
this.dicCurrencyDatas = new Dictionary<int, CurrencyData>();
foreach (CurrencyData data in arr)
{
this.dicCurrencyDatas.Add(data.id, data);
}
}
public void LoadQuestData()
{
string json = File.ReadAllText("./quest_data.json");
QuestData[] arr = JsonConvert.DeserializeObject<QuestData[]>(json);
this.dicQuestDatas = new Dictionary<int, QuestData>();
foreach (QuestData data in arr)
{
this.dicQuestDatas.Add(data.id, data);
}
}
public ItemData GetItemData(int id)
{
return this.dicItemDatas[id];
}
public CurrencyData GetCurrencyData(int id)
{
return this.dicCurrencyDatas[id];
}
public QuestData GetQuestData(int id)
{
return this.dicQuestDatas[id];
}
public void Save(Character character)
{
string json = JsonConvert.SerializeObject(character.AcceptedQuests);
File.WriteAllText("./character_info.json", json);
Console.WriteLine("saved character_info.json");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Review10
{
enum eReward
{
currncy = 0,
item = 1,
none = -1
}
public sealed class Quest
{
public static readonly Quest instance = new Quest();
private Quest()
{ }
public void PrintQuest()
{
QuestData[] arr = { DataManager.instance.GetQuestData(1000),
DataManager.instance.GetQuestData(1001),
DataManager.instance.GetQuestData(1002),
DataManager.instance.GetQuestData(1003),
DataManager.instance.GetQuestData(1004),
};
foreach (QuestData data in arr)
{
Console.WriteLine("{0}", data.title);
string questObj = string.Format(data.name, data.goal);
Console.WriteLine("{0}", questObj);
Console.WriteLine("------------------------------");
}
}
public void PrintQuest(int id)
{
QuestData data = DataManager.instance.GetQuestData(id);
Console.WriteLine("{0}", data.title);
string questObj = string.Format(data.name, data.goal);
Console.WriteLine("{0}", questObj);
Console.WriteLine("------------------------------");
}
public QuestInfo CreateQuestInfo(int id)
{
QuestInfo questInfo = new QuestInfo();
questInfo.id = id;
questInfo.progress = 0;
return questInfo;
}
public void UpdateQuest(Character.QuestEventHandlerArgs args, int progress)
{
QuestData data = DataManager.instance.GetQuestData(args.Id);
string questObj = string.Format(data.name, data.goal);
Console.WriteLine("({0})이/가 {1}/{2} 만큼 진행되었습니다.", questObj, args.Progress, data.goal);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Review10
{
public class QuestData
{
public int id;
public string title;
public string name;
public int goal;
public int reward_type_0;
public int reward_id_0;
public int reward_val_0;
public int reward_type_1;
public int reward_id_1;
public int reward_val_1;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Review10
{
public class ItemData
{
public int id;
public string name;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Review10
{
public class QuestInfo
{
public int id { get; set; }
public int progress { get; set; }
public QuestInfo() { }
}
}