ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 2020-04-17 [1차원배열 ]
    C#/수업내용 2020. 4. 17. 18:26
    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
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace Study_011
    {
        class APP3
        {
            public APP3()
            {
                //캐릭터 생성
                Character Sylvanas = new Character("실바나스");
     
                //레시피 생성
     
                string[] arrFoodIngredientNames = new string[5];
                arrFoodIngredientNames[0= "타조 고기";
                arrFoodIngredientNames[1= "윤기나는 빨간 사과";
     
                //Recipe recipe = new Recipe("타조스튜", "타조 고기", "윤기나는 빨간 사과"); //조리법 이름
                Recipe recipe = new Recipe("타조스튜", arrFoodIngredientNames);
     
                //레시피 이름을 출력
                //Console.WriteLine(recipe.name); // 타조스튜 로 나옴 
                Console.WriteLine(recipe.GetName()); // 조리법 : 타조 스튜  로 노출되게 
     
                //캐릭터가 레시피를 획득한다. 
                Sylvanas.GetRecipe(recipe);
     
                //레시피 생성
                arrFoodIngredientNames = new string[2];
                arrFoodIngredientNames[0= "거대한 알";
                arrFoodIngredientNames[1= "독특한 양념";
     
                recipe = new Recipe("괴물 오믈렛", arrFoodIngredientNames);
                // 캐릭터가 레시피 획득 
                Sylvanas.GetRecipe(recipe);
     
                Sylvanas.UseRecipe("괴물 오믈렛");
     
                arrFoodIngredientNames = new string[2];
                arrFoodIngredientNames[0= "토끼 엉겅퀴풀";
                arrFoodIngredientNames[1= "맑은 샘물";
     
                recipe = new Recipe("엉겅퀴 차", arrFoodIngredientNames);
                Sylvanas.GetRecipe(recipe);
                Sylvanas.ViewHandRecipe();
                Sylvanas.skillRecipe();
     
                //선택한 레시피 정보 출력 
                Sylvanas.PrintRecipeInfo("괴물 오믈렛");
     
                Console.WriteLine("--------------------------------");
     
                // 괴물 오물렛 ( 거대한 알 , 독특한 양념 )
     
     
                //요리를 만든다 // 우선 재료 창조 
     
                Sylvanas.GetFoodIngredient (new FoodIngredient("거대한 알"1));
               Sylvanas.GetFoodIngredient(new FoodIngredient("독특한 양념"1));
     
                //Sylvanas.check();
     
     
                Sylvanas.Cook("괴물 오믈렛");
     
            }
        }
    }
    ================================================================================================================================
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace Study_011
    {
        class Character
        {
            public string name;
            public Recipe[] arrRecipe; // 소지중인 레시피들
            public Recipe[] arrCookRecipe; // 조리가능한 레시피들
            public int recipeIndex; //레시피 배열의 인덱스 
            public int cookrecipeIndex = 0;
     
            public FoodIngredient[] arrFoodIngredients; // 소지하려고하는 재료들 [배열 선언]
            public int foodingredientIndex;
     
     
     
            public Character(string name)
            {
                this.name = name;
                this.arrRecipe = new Recipe[10]; // 레시피 배열 객체 생성 
                this.arrCookRecipe = new Recipe[10];
                this.arrFoodIngredients = new FoodIngredient[10];
                Console.WriteLine(name + "가 생성됨");
     
     
            }
     
            public Recipe GetRecipe(Recipe recipe)
            {
                this.arrRecipe[recipeIndex++= recipe;
                Console.WriteLine("{0}을 습득", recipe.GetName());
                // 제조법 : 타조 스튜를 획득 했습니다. 
     
                return recipe;
            }
     
     
            public void UseRecipe(string recipeName)
            {
     
                for (int i = 0; i < arrRecipe.Length; i++)
                {
                    Recipe recipe = this.arrRecipe[i];
                    if (recipe != null)
                    {
                        if (recipe.name == recipeName)
                        {
                            Console.WriteLine("도는 대상 : {0} / 검색 대상 : {1}  일치"recipe.name, recipeName);
                            Console.WriteLine("----->> 찾았습니다. {0}"recipe.name);
                            Console.WriteLine("{0}을  습득합니다.", recipe.GetName());
     
                            arrCookRecipe[cookrecipeIndex] = arrRecipe[i];
     
                            arrRecipe[i] = null;
     
                            Console.WriteLine("조리배열 : {0} /  {1} ", cookrecipeIndex, arrCookRecipe[cookrecipeIndex].name);
     
                            cookrecipeIndex++;
     
                        }
                        else
                        {
                            Console.WriteLine("도는 대상 : {0} / 검색 대상 : {1}  불일치"recipe.name, recipeName);
                        }
                    }
     
                }
     
                //앞쪽으로 당기기 
     
     
     
            }
     
     
            public void ViewHandRecipe()
            {
                Console.WriteLine("****소지중인레시피****");
                for (int i = 0; i < arrRecipe.Length; i++)
                {
                    Recipe recipe = this.arrRecipe[i];
                    if (recipe == null)
                        Console.WriteLine("[   ]");
                    else
                        Console.WriteLine(recipe.name);
                }
            }
     
            public void skillRecipe()
            {
                Console.WriteLine("****할수있는레시피****");
                for (int i = 0; i < arrCookRecipe.Length; i++)
                {
                    Recipe recipe = this.arrCookRecipe[i];
                    if (recipe == null)
                        Console.WriteLine("[   ]");
                    else
                        Console.WriteLine(recipe.name);
                }
                Console.WriteLine("********************");
            }
     
            public void PrintRecipeInfo(string recipeName)
            {
                //현재배운 레시피 배열의 요소중 name 멤버 변수의 값이
                //recipeName 와 같은 레시피 객체를 찾아낸다.
     
                Recipe foundRecipe = null;
                foreach (Recipe recipe in this.arrCookRecipe)
                {
                    if (recipe != null)
                    {
                        if (recipe.name == recipeName)
                        {
                            foundRecipe = recipe;
                            break;
                        }
     
                    }
     
     
                }
                Console.WriteLine("{0}", foundRecipe.GetName());
                foreach (string ingredient in foundRecipe.arrFoodIngredientNames)
                {
                    Console.WriteLine("재료 : {0}", ingredient);
                }
     
            }
     
            // 우선 캐릭터는 조리법만 주웠다
            // 재료를 습득해야하고, 그 필요재료가 있는지 확인해야한다
            // >> 음식 재료 배열 생성 뒤 거기에 추가하고, 추후 레시피 돌려서 있는지 하면 될거 같음 
     
            public FoodIngredient GetFoodIngredient(FoodIngredient FoodIngredients)
            {
                this.arrFoodIngredients[foodingredientIndex] = FoodIngredients;
                Console.WriteLine("재료 {0}을[를] 습득"FoodIngredients.name);
                foodingredientIndex++;
                return FoodIngredients;
            }
     
            //public void check()
            //{
            //    foreach (FoodIngredient name in arrFoodIngredients)
            //    {
            //        Console.WriteLine(name);
            //    }
            //}
     
     
            public void Cook(string cookName)
            {
                int cookidx = 0;
                foreach (Recipe recipe in arrCookRecipe)
                {
                    if (recipe != null)
                    {
                        if (this.arrCookRecipe[cookidx].name == cookName)
                        {
                            Console.WriteLine("일치하는 레시피 확인 --->> {0}", arrCookRecipe[cookidx].name);
                            //재료가 있는지 확인 
     
     
     
     
                        }
     
                    }
                    cookidx++;
                }
     
            }
     
     
     
     
        }
    }
    ===============================================================================================================================
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace Study_011
    {
        class Recipe
        {
            public string name; // 레시피 이름 (만들어질 음식이름 ) 
            public string[] arrFoodIngredientNames; //만들어질 음식에 필요한 재료이름들 
            
     
            //생성자
     
            public Recipe(string name, string[] arrFoodIngredientNames)
            {
                this.name = name;
                this.arrFoodIngredientNames = arrFoodIngredientNames;
               
            }
     
            public string GetName()
            {
                return "조리법 : " + this.name; //언제나 리턴은 ""값"" 이 와야한다. 
            }
        }
    }
     
    ==============================================================================================================================
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace Study_011
    {
        class Food
        {
            public string name;
           
     
            public Food(string name)
            {
                this.name = name;
            }
     
      
     
        }
     
     
    }
    ===========================================================================================================================
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace Study_011
    {
        class FoodIngredient
        {
            public string name;
            public int amount; 
     
            public FoodIngredient(string name,  int amount)
            {
                this.name = name;
                this.amount = amount;
            }
     
     
        }
    }
     
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
    http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

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

    2020-04-20 [리스트]  (0) 2020.04.20
    2020-04-20 [1차원 배열 활용]  (0) 2020.04.20
    2020-04-16 [1차원배열 활용]  (0) 2020.04.16
    2020-04-14 [Class 선언 및 인스턴스, 변수선언/리턴의 이해]  (0) 2020.04.14
    2020-04-13  (0) 2020.04.13
Designed by Tistory.