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
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using System.Collections;
using System.Threading;
namespace Study_015
{
class App
{
public App()
{
//현재 시간 출력하기
Console.WriteLine("현재 시간 : {0}",DateTime.Now.ToString());
//현재 시간 저장하기
//string savejson = JsonConvert.SerializeObject(DateTime.Now);
//File.WriteAllText("./lastTime_data.json", savejson);
GameTimeInfo gameTimeInfo = new GameTimeInfo();
//저장한 시간 불러오기
string loadjson= File.ReadAllText("./lastTime_data.json");
gameTimeInfo.strLastLoginTime = JsonConvert.DeserializeObject<string>(loadjson);
//저장된 시간
DateTime lastTime= Convert.ToDateTime(gameTimeInfo.strLastLoginTime);
Console.WriteLine("마지막으로 저장된 시간: {0}",lastTime);
//현재시간
DateTime currentTime = DateTime.Now;
//시간 간의 차이값 구하기(시간 빼기)
TimeSpan result = currentTime - lastTime;
if (result.Minutes >= 10)
{
Console.WriteLine("\n하트가 지급되었습니다.");
gameTimeInfo.strLastLoginTime=DateTime.Now.ToString();
File.WriteAllText("./lastTime_data.json", savejson);
}
else
{
DateTime rewardDateTime = lastTime.AddMinutes(10);
Console.WriteLine("{0}분 {1}초를 더 기다려야합니다", remainTimeSpan.Minutes, remainTimeSpan.Seconds);
}
}
}
}
|
2. GameTimeInfo 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 GameTimeInfo
{
public string strLastLoginTime;
public GameTimeInfo()
{
}
}
}
|
3. 결과값
1) 마지막 시간 저장 후 10분이 지났을 때
2) 하트를 받고 10분이 안 지났을 때
'C# > 수업내용' 카테고리의 다른 글
2020.04.26. 승급하기 연습 (메이플 스토리) (0) | 2020.04.26 |
---|---|
2020.04.24. 수업내용 - 승급하기(바람의 나라) (0) | 2020.04.25 |
2020.04.23. 수업내용 - json 파일 읽고 쓰기(불러오기, 저장하기) 3, 파일 2개 연습 (0) | 2020.04.23 |
2020.04.23. 수업내용 - json 파일 읽고 쓰기(불러오기, 저장하기) 2 (0) | 2020.04.23 |
2020.04.22. 수업내용 - json 파일 읽고 쓰기(불러오기, 저장하기) (0) | 2020.04.22 |