오늘 배운 테이블 2개를 불러오는 방법과 선생님께서 카페에 올려주신 코드를 참고했습니다.
엑셀데이터
1) achievement_data
2) reward_data
1. App class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
namespace Study_015
{
class App
{
private AchievementData[] arrAchievementDatas;
private RewardData[] arrRewardData;
private Dictionary<int, AchievementData> dicAchievementDatas;
private Dictionary<int, RewardData> dicRewardData;
private GameInfo gameInfo;
public App()
{
#region 테이블 2개 가져오고 저장하고 다시 불러오기
this.Init();
//json 파일 불러오기
this.arrAchievementDatas = JsonConvert.DeserializeObject<AchievementData[]>(jsonData);
this.arrRewardData = JsonConvert.DeserializeObject<RewardData[]>(jsonReward);
//사전에 값 넣기
foreach (AchievementData data in arrAchievementDatas)
{
}
foreach (RewardData reward in arrRewardData)
{
}
//기존유저 가려내기
{
AchievementInfo[] newArrInfo = JsonConvert.DeserializeObject<AchievementInfo[]>(jsonInfo);
//this.gameInfo = JsonConvert.DeserializeObject<GameInfo>(jsonInfo);
foreach(AchievementInfo info in newArrInfo)
{
}
//foreach(KeyValuePair<int, AchievementInfo> pair in this.gameInfo.dicAcievementInfo)
//{
// Console.WriteLine("{0},{1}",pair.Key,pair.Value.count);
//}
}
//신규유저
else
{
foreach (KeyValuePair<int, AchievementData> pair in this.dicAchievementDatas)
{
AchievementData data = pair.Value;
}
this.SaveData();
}
//출력하기
this.PrintAchievement(1000);
//수행하기
//this.DoAchieve(1000);
//저장하기
//this.SaveData();
}
public void Init()
{
this.dicAchievementDatas = new Dictionary<int, AchievementData>();
this.dicRewardData = new Dictionary<int, RewardData>();
//Info (id, count)값을 넣을 dictionary를 생성할 객체생성
gameInfo = new GameInfo();
}
public void PrintAchievement(int id)
{
AchievementData data = this.dicAchievementDatas[id];
RewardData reward = this.dicRewardData[data.reward_id];
AchievementInfo info = this.gameInfo.dicAcievementInfo[id];
foreach (KeyValuePair<int, AchievementData> pair in this.dicAchievementDatas)
{
{
Console.WriteLine("보상종류: {0}\t 보상양: {1}\t 보상아이콘: {2}\t 목표: {3}/{4}"
, reward.reward_name, data.reward_amount, reward.reward_icon, info.count, data.goal);
}
}
}
public void DoAchieve(int id)
{
AchievementData data = this.dicAchievementDatas[id];
RewardData reward = this.dicRewardData[data.reward_id];
AchievementInfo info = this.gameInfo.dicAcievementInfo[id];
foreach (KeyValuePair<int, AchievementData> pair in this.dicAchievementDatas)
{
{
Console.WriteLine("\n업적을 1개 수행했습니다.\n");
Console.WriteLine("보상종류: {0}\t 보상양: {1}\t 보상아이콘: {2}\t 목표: {3}/{4}"
, reward.reward_name, data.reward_amount, reward.reward_icon, info.count, data.goal);
}
}
}
public void SaveData()
{
//딕셔너리->배열->문자열->저장
int index = 0;
foreach (KeyValuePair<int, AchievementInfo> pair in this.gameInfo.dicAcievementInfo)
{
}
string json = JsonConvert.SerializeObject(arrInfo);
File.WriteAllText(path, json);
}
#endregion
}
}
|
2. AchievementData class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_015
{
class AchievementData
{
public int id;
public string name;
public string desc;
public int reward_id;
public int reward_amount;
public int goal;
}
}
|
3. RewardData class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_015
{
class RewardData
{
public int reward_id;
public string reward_name;
public int reward_type;
public string reward_icon;
}
}
|
4. GameInfo class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_015
{
class GameInfo
{
public Dictionary<int, AchievementInfo> dicAcievementInfo;
public GameInfo()
{
this.dicAcievementInfo = new Dictionary<int, AchievementInfo>();
}
}
}
|
5. AchievementInfo class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_015
{
class AchievementInfo
{
public int id;
public int count;
public AchievementInfo(int id, int count)
{
this.id = id;
this.count = count;
}
}
}
|
6. 결과값
1) 처음 실행하고 업적을 1개 수행했을 때
2) 다시 실행해서 출력만 했을 때
3) 저장 파일이 없을 때(신규 유저 일때)
'C# > 수업내용' 카테고리의 다른 글
2020.04.24. 수업내용 - 승급하기(바람의 나라) (0) | 2020.04.25 |
---|---|
2020.04.23. 수업내용 - 시간 지나면 하트주기(DateTime) (0) | 2020.04.24 |
2020.04.23. 수업내용 - json 파일 읽고 쓰기(불러오기, 저장하기) 2 (0) | 2020.04.23 |
2020.04.22. 수업내용 - json 파일 읽고 쓰기(불러오기, 저장하기) (0) | 2020.04.22 |
2020.04.21. 수업내용 - Json 파일 만들고 프로그램에 넣기 (0) | 2020.04.21 |