ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 2020-04-28
    C#/수업내용 2020. 4. 28. 18:17
    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.IO;
     
    namespace Study_018
    {
        class APP
        {
            public GameInfo gameInfo;
            public DataManager datamanager;
     
            public APP()
            {
                datamanager = DataManager.GetInstance();
                datamanager.LoadDatas();
                gameInfo = new GameInfo();
     
                
     
                Console.WriteLine("==============상점==============");
                this.PrintProductShop(1000);
                Console.WriteLine();
                Console.WriteLine();
                this.PrintProductShop(1001);
                Console.WriteLine();
                Console.WriteLine();
                this.PrintProductShop(1002);
     
     
                this.BuyProduct(1000);
                this.PrintProductShop(1000);
     
                this.SaveUserInfo();
     
     
     
            }
     
            public void PrintProductShop(int id)
            {
                var data = this.datamanager.GetProductDatasById(id);
                var count = 0;
     
                int price = data.price;
                string strprice = string.Format("{0:n0}", price);
                var name = string.Format(data.name, data.product_amount);
           
                switch (data.product_buy_type) // 구매타입 (제한없음 / 매일 구매 / 계정제한 )
                {
                    case 0// 제한 없음 
                        Console.WriteLine("이름 : {0}", name);
                        Console.WriteLine("가격: 다이아 {0}개 / {1}:{2}", strprice, data.str_Mileage, data.Mileage_amount);
                        if (data.limit_time_bool == true)
                        {
                            this.gameInfo.RemainTime(id);
                        }
                        break;
     
                    case 1// 매일 구매 
     
                        break;
     
                    case 2// 계정 제한 
                        if (data.price_type == 0// 다이아 구매 
                        {
                            if (data.product_level_limit > 0//다이아 구매 레벨 제한 
                            {
                                Console.WriteLine("이름 : {0}", name);
                                Console.WriteLine("가격: 다이아 {0}개 / {1}:{2}", strprice, data.str_Mileage, data.Mileage_amount);
                                Console.WriteLine("레벨 {0} 이상, {1}/{2}", data.product_level_limit, count, data.product_amount_limit);
                                if (data.limit_time_bool == true)
                                {
                                    this.gameInfo.RemainTime(id);
                                }
                            }
                            else // 다이아 구매 레벨 제한 없을때 
                            {
                                Console.WriteLine("이름 : {0}", name);
                                Console.WriteLine("가격: 다이아 {0}개 / {1}:{2}", strprice, data.str_Mileage, data.Mileage_amount);
                                Console.WriteLine("제한: {0}/{1}", count, data.product_amount_limit);
                                if (data.limit_time_bool == true)
                                {
                                    this.gameInfo.RemainTime(id);
                                }
                            }
     
                        }
                        else // 골드구매 
                        {
                            if (data.product_level_limit > 0//골드구매 레벨제한  
                            {
                                Console.WriteLine("이름 : {0}", name);
                                Console.WriteLine("가격: 골드 {0}개", strprice);
                                Console.WriteLine("레벨 {0} 이상, {1}/{2}", data.product_level_limit, count ,data.product_amount_limit);
                                if (data.limit_time_bool == true)
                                {
                                    this.gameInfo.RemainTime(id);
                                }
                            }
                            else
                            {
                                Console.WriteLine("이름 : {0}", name);
                                Console.WriteLine("가격: 골드 {0}개 ", strprice);
                                if (data.limit_time_bool == true)
                                {
                                    this.gameInfo.RemainTime(id);
                                }
                            }
     
                        }
                        break;
                }
            }
     
            // public bool CheckNewBie()
     
            private void SaveUserInfo()
            {
                var json = JsonConvert.SerializeObject(this.gameInfo);
                File.WriteAllText("./user_info.json", json);
                Console.WriteLine("user_info saved.");
     
            }
     
            public int BuyProduct(int id) // 이 형식으로는 INt가 증가하지 않음 
            {
                var productdata = this.datamanager.GetProductDatasById(id);
                var count = this.datamanager.GetBuyInfo(id).count;
     
                if (count < productdata.product_amount_limit)
                {
                    count++;
                    Console.WriteLine("{0}을 1개 구매했습니다."productdata.name);
     
                }
                else if (count >= productdata.product_amount_limit)
                {
                    Console.WriteLine("더 이상 구매 할 수 없습니다.");
                }
                return count;
            }
     
     
        }
    }
     
    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace Study_018
    {
        class GameInfo
        {
            public int level;
            public BuyInfo buyInfo;
            public List<BuyInfo> listbuyInfos; 
     
            public GameInfo() //캐릭터의 레벨 / 패키지 남은 시간 계산 저장소 
            {
                this.level = 55;
                this.listbuyInfos = new List<BuyInfo>();
                //각각 구매할때마다 어카운트 제한이 하나씩 늘어나야한다. 
                // 데이터 매니저를 부른 후 , 그 제한 값과 비교 할 수 있어야한다. 
               // 각각이란 제한이 있다. 
            }
     
            public void Init()
            {
     
     
            }
     
                
            public void RemainTime(int id)
            {
                var data = DataManager.GetInstance().GetProductDatasById(id);
                DateTime startime = DateTime.Now;
                DateTime EndDate = data.limit_time;
     
                TimeSpan timeSpan = EndDate- startime;
                int diffHour = timeSpan.Hours;
                int diffMinute = timeSpan.Minutes;
                int diffSecond = timeSpan.Seconds;
     
                Console.WriteLine("판매 종료까지 {0}시간 {1}분 남았습니다", diffHour, 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
    25
    26
    27
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace Study_018
    {
        class ProductShop
        {
            public int id;
            public string name;
            public int product_amount;
            public int product_level_limit;
            public int product_amount_limit;
            public int product_buy_type;
            public string icon_name;
            public int price_type;
            public int price;
            public bool Mileage_bool;
            public string str_Mileage;
            public int Mileage_amount;
            public bool limit_time_bool;
            public DateTime limit_time;
     
        }
    }
    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.IO;
     
    namespace Study_018
    {
        class DataManager
        {
            private static DataManager dataManager;
            private Dictionary<int, ProductShop> dicProductshop;
            private Dictionary<int, BuyInfo> dicBuyInfo;
     
            private DataManager()
            {
                dicProductshop = new Dictionary<int, ProductShop>();
                dicBuyInfo = new Dictionary<int, BuyInfo>();
     
            }
     
            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/product_shop.json"));
               BuyInfo[] arrBuyInfos = JsonConvert.DeserializeObject<BuyInfo[]>(File.ReadAllText("./data/buy_info.json"));
     
                this.dicProductshop = arrproductShops.ToDictionary(x => x.id, x => x);
                this.dicBuyInfo = arrBuyInfos.ToDictionary(x => x.id, x => x);
     
                Console.WriteLine("product : {0}"this.dicProductshop.Count);
                Console.WriteLine("buyinfo : {0}"this.dicBuyInfo.Count);
     
            }
     
            public ProductShop GetProductDatasById(int id)
            {
                return this.dicProductshop[id];
            }
     
            public BuyInfo GetBuyInfo(int id)
            {
                return this.dicBuyInfo[id];
            }
     
        }
    }
     
    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace Study_018
    {
        class BuyInfo
        {
            public int id;
            public int count;
            public BuyInfo()
            {
     
            }
        }
    }
     
     
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
     

     

     

     

     

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

    2020-04-29 [시간(출석보상) 계산]  (0) 2020.04.29
    2020-04-29 [브롤스타 예제]  (0) 2020.04.29
    2020-04-21 [json]  (0) 2020.04.21
    2020-04-20 [리스트]  (0) 2020.04.20
    2020-04-20 [1차원 배열 활용]  (0) 2020.04.20
Designed by Tistory.