수업 015 (04.24 2020) 복습 Inventory + percentage
2020. 4. 24. 11:36
728x90
1. Inventory Sample
2. App.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
namespace Study._016
{
class App
{
Dictionary<int, AchievementData> dicAchievementData;
Dictionary<int, RewardData> dicRewardData;
public App()
{
// 파일 불러오기
// 배열 > 객체
AchievementData[] arrAchievementDatas = JsonConvert.DeserializeObject<AchievementData[]>(json);
// 객체 > 사전
this.dicAchievementData = new Dictionary<int, AchievementData>();
foreach (AchievementData data in arrAchievementDatas)
{
}
// 파일 불러오기
// 배열 > 객체
RewardData[] arrRewardDats = JsonConvert.DeserializeObject<RewardData[]>(jsonReward);
// 객체 > 사전
this.dicRewardData = new Dictionary<int, RewardData>();
foreach (RewardData data2 in arrRewardDats)
{
}
// Reward Data 불러오기
var achievementData = this.dicAchievementData[1002];
var rewardData = this.dicRewardData[achievementData.reward_id1];
var rewardData2 = this.dicRewardData[achievementData.reward_id2];
// 경험치 퍼센트
float currentEXP = 14084f;
float percent = currentEXP / goalEXP * 100;
// 소수점 버림: Math.Truncate(값)
// 데이터 출력
Console.WriteLine("Description: {0}", achievementData.description);
Console.WriteLine("Icon: {0}", rewardData.icon_name);
Console.WriteLine("Icon: {0}", rewardData2.icon_name);
}
}
}
|
2. AchievementData.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._016
{
class AchievementData
{
public int id;
public string name;
public int goal;
public int reward_id1;
public int reward_id2;
public int reward_amount1;
public int reward_amount2;
public string description;
}
}
|
3. RewardData.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study._016
{
class RewardData
{
public int id;
public string name;
public int reward_type;
public string icon_name;
}
}
|
4. Result
728x90
'C# > Study' 카테고리의 다른 글
수업 016 (04.27 2020) Maple Story (0) | 2020.04.28 |
---|---|
수업 015 (04.24 2020) 조건연산자(?:) F9,F5,F11 swap ref (0) | 2020.04.24 |
수업 014 (04.23 2020) - DateTime (0) | 2020.04.24 |
수업 014 (04.23 2020) 복습 - json, dictionary..etc (0) | 2020.04.23 |
수업 013 (04.22 2020) dictionary, json // Achievement (0) | 2020.04.22 |