C#/수업내용

2020.04.29. 수업내용 - 스킨목록 출력하기

dev_sr 2020. 4. 29. 15:40

스킨 목록을 출력하고

선택한 스킨을 따로 상세하게 출력하기

 

 

엑셀 테이블

1)

2) 

 

3)

 

 

 

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Study_19
{
    class App
    {
 
        public App()
        {
            //데이터 매니저 생성
            DataManager datamanager = DataManager.GetInstance();
 
            //데이터 불러오기
            datamanager.LoadData();
 
            //출력하기
            this.PrintProduct();
 
            this.SelectProduct(1002);
 
        }
 
        public void PrintProduct()
        {
            List<ProductData> list = DataManager.GetInstance().GetProductData();
 
            for(int i=0; i<list.Count; i++)
            {
                Console.WriteLine("-----------------------------------------------------------");
                BudgetData budgetData = DataManager.GetInstance().GetBudgetDataByType(list[i].budget_type);
                string name = list[i].name + list[i].name_string;
                DateTime productTime = Convert.ToDateTime(list[i].time);
                DateTime now = DateTime.Now;
 
                TimeSpan leftTime = productTime - now;
 
                Console.WriteLine(name);
                Console.WriteLine(list[i].icon);
 
                if (list[i].price == 0)
                {
                    Console.WriteLine("{0}일 {1}시간 {2}분"leftTime.Days, leftTime.Hours, leftTime.Minutes);
                    Console.WriteLine("곧 공개!");
 
                }
                else
                {
                    Console.WriteLine("{0}일 {1}시간 {2}분"leftTime.Days, leftTime.Hours, leftTime.Minutes);
                    Console.WriteLine("{0}, {1}  {2}"budgetData.icon, budgetData.name, list[i].price);
                }
 
            }
        }
 
 
        public void SelectProduct(int id)
        {
            this.ShowPopUp(id);
            return;
        }
 
        public void ShowPopUp(int id)
        {
            Console.WriteLine("-----------------------------------------------------------");
            Console.WriteLine("**********구매 확인**********");
 
            ProductData productData = DataManager.GetInstance().GetProductDataById(id);
            BudgetData budgetData = DataManager.GetInstance().GetBudgetDataByType(productData.budget_type);
 
            List<SkinDescData> skinData = DataManager.GetInstance().GetSkinDescDataByType(productData);
 
            string name = productData.name + productData.name_string;
 
            DateTime productTime = Convert.ToDateTime(productData.time);
            DateTime now = DateTime.Now;
 
            TimeSpan leftTime = productTime - now;
 
 
            Console.WriteLine("{0}일 {1}시간 {2}분"leftTime.Days, leftTime.Hours, leftTime.Minutes);
 
            Console.WriteLine(name);
 
            Console.WriteLine(productData.desc_string);
 
            if (productData.open_type)
            {
                for (int i = 0; i < skinData.Count; i++)
                {
                    Console.WriteLine(skinData[i].desc);
                }
            }
            else
            {
                Console.WriteLine("곧 출시 됩니다.");
            }
 
            Console.WriteLine(productData.icon);
            Console.WriteLine("[체험]");
            Console.WriteLine("[구매] {0}, {1}  {2}"budgetData.icon, budgetData.name, productData.price);
 
        }
    }
}
 
 

 

 

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
107
108
109
110
111
112
113
114
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Study_19
{
    class DataManager
    {
        private static DataManager instance;
        private Dictionary<int, ProductData> dicProductDatas;
        private Dictionary<int, BudgetData> dicBudgetDatas;
        private Dictionary<int, SkinDescData> dicSkinDescDatas;
 
        private DataManager()
        {
            this.dicProductDatas = new Dictionary<int, ProductData>();
            this.dicBudgetDatas = new Dictionary<int, BudgetData>();
            this.dicSkinDescDatas = new Dictionary<int, SkinDescData>();
 
        }
 
        public static DataManager GetInstance()
        {
            if(DataManager.instance==null)
            {
                DataManager.instance = new DataManager();
                return DataManager.instance;
            }
 
            return DataManager.instance;
        }
 
        public void LoadData()
        {
            string productJson = File.ReadAllText("./data/product_data.json");
            string budgetJosn = File.ReadAllText("./data/budget_data.json");
            string skindescJson = File.ReadAllText("./data/skin_desc_data.json");
 
            this.dicProductDatas = JsonConvert.DeserializeObject<ProductData[]>(productJson).ToDictionary(x => x.id, x => x);
            this.dicBudgetDatas = JsonConvert.DeserializeObject<BudgetData[]>(budgetJosn).ToDictionary(x => x.id, x => x);
            this.dicSkinDescDatas = JsonConvert.DeserializeObject<SkinDescData[]>(skindescJson).ToDictionary(x => x.id, x => x);
 
 
        }
        
        public ProductData GetProductDataById(int id)
        {
            return this.dicProductDatas[id];
        }
 
        public BudgetData GetBudgetDataByType(int type)
        {
            BudgetData data = null;
 
            foreach(var pair in this.dicBudgetDatas)
            {
                if(pair.Value.type==type)
                {
                    data = pair.Value;
                }
            }
            return data;
        }
 
        public List<SkinDescData> GetSkinDescDataByType(ProductData data)
        {
            List<SkinDescData> list = new List<SkinDescData>();
 
            foreach(var pair in this.dicSkinDescDatas)
            {
                
                if(pair.Key==data.desc_type1)
                {
                    list.Add(pair.Value);
                }
                if (pair.Key == data.desc_type2)
                {
                    list.Add(pair.Value);
                }
                if (pair.Key == data.desc_type3)
                {
                    list.Add(pair.Value);
                }
                if (pair.Key == data.desc_type4)
                {
                    list.Add(pair.Value);
                }
                if (pair.Key == data.desc_type5)
                {
                    list.Add(pair.Value);
                }
 
            }
 
            return list;
 
        }
 
        public List<ProductData> GetProductData()
        {
            List<ProductData> list = new List<ProductData>();
            foreach(var pair in this.dicProductDatas)
            {
                list.Add(pair.Value);
            }
            return list;
        }
    }
}
 
 

 

 

3. SkinDescData class

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Study_19
{
    class SkinDescData
    {
        public int id;
        public string desc;
    }
}
 
 

 

 

 

4. BudgetData 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;
using System.Threading.Tasks;
 
namespace Study_19
{
    class BudgetData
    {
        public int id;
        public int type;
        public string name;
        public string icon;
    }
}
 
 

 

 

5. ProductData 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Study_19
{
    class ProductData
    {
        public int id;
        public string name;
        public string name_string;
        public string desc_string;
        public int desc_type1;
        public int desc_type2;
        public int desc_type3;
        public int desc_type4;
        public int desc_type5;
        public string icon;
        public int budget_type;
        public int price;
        public string time;
        public bool open_type;
 
 
    }
}
 
 

 

 

6. 결과 값

1)출시된 캐릭터

 

2) 미출시 캐릭터