엑셀 테이블
1) 일간 출석 보상 데이터(daily_reward)
2) 연속 출석 보상 데이터(con_reward)
3) 아이템 데이터(item)
각 테이블의 클래스 코드는 생략하였습니다.
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace study_019
{
class App
{
UserInfo userInfo;
RewardItemInfo rewardItemInfo;
RewardItemInfo conRewardItemInfo;
public App()
{
DataManager dataManager = DataManager.GetInstance();
dataManager.LoadData();
//기존 유저
{
Console.WriteLine("기존 유저 입니다.");
this.userInfo = JsonConvert.DeserializeObject<UserInfo>(json);
this.rewardItemInfo=new RewardItemInfo();
this.conRewardItemInfo = new RewardItemInfo();
//이달의 마지막 보상인가
//테이블의 마지막 날짜 반환
int lastDay = this.LastReward();
DateTime now = DateTime.Now;
if(this.userInfo.loginCount<lastDay)
{
//연속 출석인가
{
Console.WriteLine("바로 다음날 접속");
userInfo.DailyInit();
this.GetConReward();
}
//같은 날 또 접속 했나
{
Console.WriteLine("이미 보상을 받았습니다.");
}
//며칠 차를 두고 접속 했나
{
Console.WriteLine("연속 출석 시간을 초기화 합니다. {0}일->{1}일", userInfo.conDailyCount, 1);
userInfo.loginCount++;
userInfo.conDailyCount = 1;
userInfo.getReward = false;
}
//보상을 안받았다면 보상을 받는다.
if (userInfo.getReward == false)
{
userInfo.lastLoginTime = DateTime.Now;
this.GetRewardItem(this.userInfo.loginCount);
}
}
else
{
Console.WriteLine("로그인 날짜 카운트: "+userInfo.loginCount);
Console.WriteLine("마지막으로 저장된 시간: "+userInfo.lastLoginTime);
Console.WriteLine("더이상 보상을 받을 수 없습니다.");
}
}
//신규 유저
else
{
Console.WriteLine("신규유저 입니다.");
this.userInfo = new UserInfo();
this.rewardItemInfo = new RewardItemInfo();
this.GetRewardItem(userInfo.loginCount);
this.SaveData();
}
this.PrintDailyReward();
this.PrintConReward();
this.PrintUserInventory();
this.SaveData();
}
public void PrintDailyReward()
{
Console.WriteLine("\n-------------------------------------------");
Console.WriteLine("\n**일간 출석 보상**");
Console.WriteLine("연속 출석 {0} 일", userInfo.conDailyCount);
Console.WriteLine();
List<DailyRewardData> dailyList = DataManager.GetInstance().GetDailyRewardData();
ItemData itemdata = null;
foreach (var data in dailyList)
{
itemdata = DataManager.GetInstance().GetItemDataByType(data.item_type);
}
}
public void PrintConReward()
{
Console.WriteLine("\n-------------------------------------------");
Console.WriteLine("\n**연속 출석 보상**");
List<ConRewardData> conRewardList = DataManager.GetInstance().GetConRewardData();
ItemData itemdata = null;
foreach (var data in conRewardList)
{
itemdata = DataManager.GetInstance().GetItemDataByType(data.item_type);
}
}
public void PrintUserInventory()
{
Console.WriteLine("\n-------------------------------------------");
Console.WriteLine("\n**인벤토리**");
foreach (var date in userInfo.inventory)
{
}
}
public void GetRewardItem(int daycount)
{
DailyRewardData data = DataManager.GetInstance().GetDailyRewardDataByDay(daycount);
ItemData itemdata = DataManager.GetInstance().GetItemDataByType(data.item_type);
this.rewardItemInfo.AddItemInfo(itemdata.name, data.amount);
userInfo.getReward = true;
userInfo.AddInventory(rewardItemInfo);
Console.WriteLine("\n-------------------------------------------");
}
public void GetConReward()
{
List<ConRewardData> conRewardList = DataManager.GetInstance().GetConRewardData();
ItemData itemdata = null;
foreach (var data in conRewardList)
{
itemdata = DataManager.GetInstance().GetItemDataByType(data.item_type);
if(this.userInfo.conDailyCount==data.con_day)
{
Console.WriteLine("\n-------------------------------------------");
Console.WriteLine("\n**{0}일 연속 보상 {1} {2:N0}개를 얻었습니다**", data.con_day,itemdata.name, data.con_amount);
this.conRewardItemInfo.AddItemInfo(itemdata.name, data.con_amount);
userInfo.AddInventory(conRewardItemInfo);
Console.WriteLine("\n-------------------------------------------");
}
}
this.PrintUserInventory();
}
//일간 보상 테이블의 마지막 날짜를 찾아서 반환
public int LastReward()
{
int lastDay = DataManager.GetInstance().GetLastDayData();
return lastDay;
}
public void SaveData()
{
Console.WriteLine("\n-------------------------------------------");
Console.WriteLine("\n**데이터를 저장합니다.**");
string saveJson = JsonConvert.SerializeObject(userInfo);
File.WriteAllText(path, saveJson);
}
}
}
|
2. DataManager 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
|
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace study_019
{
class DataManager
{
private static DataManager instance;
private Dictionary<int, ConRewardData> dicConRewardDatas;
private Dictionary<int, DailyRewardData> dicDailyRewardDatas;
private Dictionary<int, ItemData> dicItemDatas;
private DataManager()
{
this.dicConRewardDatas = new Dictionary<int, ConRewardData>();
this.dicDailyRewardDatas = new Dictionary<int, DailyRewardData>();
this.dicItemDatas = new Dictionary<int, ItemData>();
}
public static DataManager GetInstance()
{
if(DataManager.instance==null)
{
DataManager.instance = new DataManager();
return DataManager.instance;
}
return DataManager.instance;
}
public void LoadData()
{
this.dicConRewardDatas = JsonConvert.DeserializeObject<ConRewardData[]>(conJson).ToDictionary(x => x.id, x => x);
this.dicDailyRewardDatas = JsonConvert.DeserializeObject<DailyRewardData[]>(dailyJson).ToDictionary(x => x.id, x => x);
this.dicItemDatas = JsonConvert.DeserializeObject<ItemData[]>(itemJosn).ToDictionary(x => x.id, x => x);
}
public List<DailyRewardData> GetDailyRewardData()
{
List<DailyRewardData> list = new List<DailyRewardData>();
foreach(KeyValuePair<int, DailyRewardData> pair in this.dicDailyRewardDatas)
{
}
return list;
}
public ItemData GetItemDataByType(int type)
{
ItemData data = null;
foreach(var pair in this.dicItemDatas)
{
{
data = pair.Value;
}
}
return data;
}
public List<ConRewardData> GetConRewardData()
{
List<ConRewardData> list = new List<ConRewardData>();
foreach(var pair in this.dicConRewardDatas)
{
}
return list;
}
public DailyRewardData GetDailyRewardDataByDay(int day)
{
DailyRewardData data = null;
foreach(var pair in this.dicDailyRewardDatas)
{
{
data = pair.Value;
}
}
return data;
}
public int GetLastDayData()
{
}
}
}
|
3. UserInfo 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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace study_019
{
class UserInfo
{
public int conDailyCount; // 연속 출석 카운트
public int loginCount; //로그인 카운트
public DateTime lastLoginTime; //마지막으로 접속한 시간
public List<RewardItemInfo> inventory; //보상 받은 아이템을 저장하는 리스트
public bool getReward; //보상을 받았는가?
public UserInfo()
{
}
// 초기화
public void Init()
{
this.inventory = new List<RewardItemInfo>();
this.loginCount = 1;
this.conDailyCount = 1;
Console.WriteLine("첫 로그인");
Console.WriteLine("로그인 한 날 " + loginCount);
Console.WriteLine("연속 로그인 한 날 " + conDailyCount);
Console.WriteLine("받았는가? " + this.getReward);
Console.WriteLine("마지막으로 저장된 시간 " + this.lastLoginTime);
}
public void AddInventory(RewardItemInfo info)
{
}
public void DailyInit()
{
this.loginCount++;
this.conDailyCount++;
this.getReward = false;
Console.WriteLine("\n새로운 날짜에 출석하여 초기화");
Console.WriteLine("로그인 한 날 "+loginCount);
Console.WriteLine("연속 로그인 한 날 "+conDailyCount);
Console.WriteLine("받았는가? "+ this.getReward);
Console.WriteLine("마지막으로 저장된 시간 " + this.lastLoginTime);
}
}
}
|
4. RewardItemInfo 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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace study_019
{
class RewardItemInfo
{
public string name;
public int amount;
public RewardItemInfo()
{
}
public void AddItemInfo(string name, int amount)
{
this.name = name;
this.amount = amount;
}
}
}
|
5. 결과값
1)신규 유저일 때
2)같은 날짜에 또 실행했을 때
3)마지막으로 저장된 시간을 29일로 바꾸고 다시 실행했을때
(2일 연속 출석 했을때)
4)연속 보상 얻기1
5)연속 보상 얻기 2
6) 이달의 마지막 보상
출석할때마다 증가하는 로그인 카운터가
테이블의 마지막 항목의 날짜 데이터와 같아지면
더이상 이 달의 보상은 받을 수 없음
(마지막 보상까지 받고 다음날 다시 로그인하면 더이상 못 받음)
7) 연속 출석을 못했을때
-현재 날짜와 마지막으로 저장된 날짜의 차가 하루보다 크면 연속 출석을 못한 것으로 판정
-출석 보상은 이어서 받고
-연속 출석일은 1일로 초기화
'C# > 수업내용' 카테고리의 다른 글
2020.05.06. 수업내용 - Unity 캐릭터 이동시키기 (0) | 2020.05.06 |
---|---|
2020.05.01. 수업내용 - 2차원 배열(캐릭터 이동하기) (0) | 2020.05.01 |
2020.04.29. 수업내용 - 스킨목록 출력하기 (0) | 2020.04.29 |
2020.04.28. 수업내용 - 상점페이지 (시간) (0) | 2020.04.29 |
2020.04.26. 승급하기 연습 (메이플 스토리) (0) | 2020.04.26 |