ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 2020-04-29 [브롤스타 예제]
    C#/수업내용 2020. 4. 29. 12:39
    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace Study_019
    {
        class APP
        {
            public DataManager dataManager;
     
            public APP()
            {
                dataManager = DataManager.GetInstance();
                dataManager.LoadDatas();
     
                this.PrintProduct();
                Console.WriteLine();
                Console.WriteLine();
     
                this.SelectProduct(1001);
                Console.WriteLine();
                this.SelectProduct(1004);
                this.SelectProduct(1002);
     
     
            }
     
            public void PrintProduct()
            {
                var dataManager = this.dataManager;
                var data = dataManager.GetAll();
     
                foreach(var element in data)
                {
                    if (element.Key == 1004)
                    {
                        Console.WriteLine("스킨 이름: {0}"element.Value.name);
                        dataManager.WaitTime(element.Key);               
                    }
                    else
                    {
                        dataManager.remainTime(element.Key);
                        Console.WriteLine("스킨 이름: {0}"element.Value.name);
                        Console.WriteLine("스킨 이미지: {0}"element.Value.icon_name);
                        Console.WriteLine("가격 : {0}젬"element.Value.price);
                        Console.WriteLine();
                    }
                }
            }
     
            public void SelectProduct(int id)
            {
                var dataManager = this.dataManager;
                var data = dataManager.GetProductDatasById(id);
                int skintype = data.product_skin_grade;
                Console.WriteLine("****선택한 스킨****");
     
                if (data.id == 1004)
                {
                    Console.WriteLine("스킨 이름: {0}"data.name);
                    dataManager.WaitTime(id);
                    Console.WriteLine();
     
                }
                else
                {
                    dataManager.remainTime(id);
                    Console.WriteLine("스킨 이름: {0}"data.name);
                    Console.WriteLine("스킨 이미지: {0}", data.icon_name);
                    dataManager.GetSkinDatas(skintype);
                    Console.WriteLine("가격 : {0}젬"data.price);
                    Console.WriteLine();
                }
            }
     
        }
    }
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
     
     
    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.IO;
     
    namespace Study_019
    {
        class DataManager
        {
            private static DataManager dataManager;
            private Dictionary<int, ProductShop> dicProductShop;
            private Dictionary<int, SkinType> dicSkinType;
     
            private DataManager()
            {
                this.dicProductShop = new Dictionary<int, ProductShop>();
                this.dicSkinType = new Dictionary<int, SkinType>();
     
            }
     
            public static DataManager GetInstance()
            {
                if(DataManager.dataManager == null)
                {
                    DataManager.dataManager = new DataManager();
                }
                return DataManager.dataManager;
            }
     
            public void LoadDatas()
            {
                ProductShop[] arrProductShops = JsonConvert.DeserializeObject<ProductShop[]>(File.ReadAllText("./data/produc_shop.json"));
                SkinType[] arrSkinTypes = JsonConvert.DeserializeObject<SkinType[]>(File.ReadAllText("./data/skin_type.json"));
     
                this.dicProductShop = arrProductShops.ToDictionary(x => x.id, x => x);
                this.dicSkinType = arrSkinTypes.ToDictionary(x => x.id, x => x);
     
                Console.WriteLine("검증 / 카운트 :{0}"this.dicProductShop.Count);
                Console.WriteLine("검증 / 카운트 :{0}"this.dicSkinType.Count);
     
            }
     
            public ProductShop GetProductDatasById(int id)
            {
                return this.dicProductShop[id];
            }
     
            public SkinType GetSkinTypeById(int id)
            {
                return this.dicSkinType[id];
            }
     
            public Dictionary<int, ProductShop> GetAll()
            {
                return this.dicProductShop;
            }
     
            public void GetSkinDatas(int id)
            {
                var data = this.GetSkinTypeById(id);
     
                if (data.form == true)
                {
                    string form = "- 브롤러 전용 외형";
                    Console.WriteLine(form);
                }
                if (data.effect == true)
                {
                    string effect = "- 전용 이펙트";
                    Console.WriteLine(effect);
                }
                if (data.animation == true)
                {
                    string animation = "- 전용 애니메이션";
                    Console.WriteLine(animation);
                }
                if (data.soundeffect == true)
                {
                    string soundeffect = "- 전용 사운드 효과 ";
                    Console.WriteLine(soundeffect);
                }
                if (data.petform == true)
                {
                    string petform = "- 펫 전용 외형";
                    Console.WriteLine(petform);
                }
                if (data.turretform)
                {
                    string turretform = "- 터렛 전용 외형";
                    Console.WriteLine(turretform);
                }
            }
     
     
            public void remainTime(int id)
            {
                var data = dataManager.GetProductDatasById(id);
                DateTime nowtime = DateTime.Now;
                DateTime endtime = data.limitTime;
     
                TimeSpan timeSpan = endtime - nowtime;
                int diffHout = timeSpan.Hours;
                int diffMinute = timeSpan.Minutes;
     
                Console.WriteLine("판매 종료까지 {0}시간 {1}분 남았습니다", diffHout, diffMinute);
            }
     
            public void WaitTime(int id)
            {
                var data = dataManager.GetProductDatasById(id);
                DateTime nowtime = DateTime.Now;
                DateTime sellstarttiem = data.limitTime;
     
                TimeSpan timeSpan = sellstarttiem - nowtime;
                int diffHout = timeSpan.Hours;
                int diffMinute = timeSpan.Minutes;
     
                Console.WriteLine("{0}시간 {1}분 후에 공개 됩니다.", diffHout, diffMinute);
            }
        }
    }
     
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
     

     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace Study_019
    {
        class SkinType
        {
            public int id;
            public bool form;
            public bool effect;
            public bool animation;
            public bool soundeffect;
            public bool petform;
            public bool turretform;
     
            public SkinType()
            {
     
            }
        }
    }
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
     

     

    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;
    using System.Threading.Tasks;
     
    namespace Study_019
    {
        class ProductShop
        {
            public int id;
            public string name;
            public int product_skin_grade;
            public string icon_name;
            public int price;
            public DateTime limitTime;
        }
     
    }
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
     

     

     

     

     

    'C# > 수업내용' 카테고리의 다른 글

    2020-05-01 [2차원 배열 / 단순 이동 ]  (0) 2020.05.01
    2020-04-29 [시간(출석보상) 계산]  (0) 2020.04.29
    2020-04-28  (0) 2020.04.28
    2020-04-21 [json]  (0) 2020.04.21
    2020-04-20 [리스트]  (0) 2020.04.20
Designed by Tistory.