ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 2020-04-18/19 [1차원 배열 활용]
    C#/과제 2020. 4. 20. 01:12
    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Xml.Serialization;
     
    namespace practice009
    {
        class Character
        {
            public string name;
            public Recipe[] arrRecipe; //소지중인 레시피들 
            public int recipeindex = 0;
            public Recipe[] arrCookRecipe; // 요리가능 레시피 
            public int arrCoookRecipeindex = 0// 배열에 쓸 인트
     
            public int foundrecipeindex = 0;
     
            public FoodIngredient[] arrmaterial;
            public int materialindex;
     
            public FoodIngredient[] myarrmaterial;
     
     
            public Character(string name)
            {
                this.name = name;
                this.arrRecipe = new Recipe[6];
                this.arrCookRecipe = new Recipe[6];
                this.arrmaterial = new FoodIngredient[6];
                this.myarrmaterial = new FoodIngredient[6];
     
            }
     
            public void GetRecipe(Recipe recipe)
            {
                this.arrRecipe[recipeindex++= recipe;
     
                Console.WriteLine("{0}을 습득했습니다.", recipe.GetName());
     
            }
     
            public void PrintGetRecipe()
            {
                Console.WriteLine("***소지중인 레시피***");
                foreach (Recipe recipe in arrRecipe)
                {
                    if (recipe != null)
                    {
                        Console.WriteLine(recipe.name);
                    }
                    else
                    {
                        Console.WriteLine("[    ]");
                    }
                }
            }
     
            public void UseRecipe(string name) //  우선 같은 값 찾기
            {
                Recipe foundrecipe = null;
     
                for (int i = 0; i < arrRecipe.Length; i++)
                {
                    if (this.arrRecipe != null)
                    {
                        if (this.arrRecipe[i].name == name)
                        {
                            Console.WriteLine("검색: {0} / 검색어 : {1} / 일치"this.arrRecipe[i].name, name);
                            Console.WriteLine("--->> 동일한 레시피 발견");
                            Console.WriteLine("{0}가 사용됩니다."this.arrRecipe[i].name);
                            foundrecipe = this.arrRecipe[i];
                            this.arrCookRecipe[arrCoookRecipeindex++= foundrecipe;
                            this.arrRecipe[i] = null;
                            arrCoookRecipeindex++;
                            break;
                        }
                        else
                        {
                            Console.WriteLine("검색: {0} / 검색어 : {1} / 불일치"this.arrRecipe[i].name, name);
                        }
                    }
                }
            }
     
            public void PrintCookRecipe()
            {
                Console.WriteLine("***요리가능레시피***");
                for (int i = 0; i < this.arrCookRecipe.Length; i++)
                {
                    if (this.arrCookRecipe[i] != null)
                    {
                        Console.WriteLine(this.arrCookRecipe[i].name);
                    }
                    else
                    {
                        Console.WriteLine("[    ]");
                    }
                }
            }
     
            public void PrintRecipeInfo(string name)
            {
                // 배운 배열 요소 이름name 같은거 찾아내기 
                Recipe foundRecipe = null;
     
                foreach (var recipe in this.arrCookRecipe)
                {
                    if (this.arrCookRecipe != null)
                    {
                        if (recipe.name == name)
                        {
                            foundRecipe = recipe;
                            break;
                        }
                    }
                }
     
                Console.WriteLine("*** 선택한 레시피 재료정보***");
                Console.WriteLine(foundRecipe.GetName());
                foreach (string ingredientname in foundRecipe.arrFoodIngredinets)
                    Console.WriteLine(ingredientname);
            }
     
     
            public void Cook(string name)
            {
                Recipe foundRecipe = null;
     
                foreach (Recipe recipe in this.arrCookRecipe)
                {
                    if (recipe != null)
                    {
                        foundRecipe = recipe;
                    }
                }
     
                foreach (FoodIngredient material in this.arrmaterial)
                {
                    if(material != null)
                     {
                        foreach (FoodIngredient mat in this.myarrmaterial)
                        { 
                           if (mat != null)
                            {
                                material.name = mat.name;
     
                                Console.WriteLine("필요: {0}x{1}, 소지: {2}x{3}"material.name, material.amount, mat.name, mat.amount);
                                break;
     
     
                            }
                        }
     
                    }
                } 
     
            }
     
     
        }
    }
     
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter

     

     

     

     

     

     

    한 내용들은 쓰겠지만 머리굴려가며 응용이 안된다..

    'C# > 과제' 카테고리의 다른 글

    2020-04-23 [JSON 활용 및 초반 과정 및 생각 정리]  (0) 2020.04.23
    객체지향 3요소 / 5 원칙 둘러보고 간단 서술  (0) 2020.04.23
    2020-04-15 [인벤토리 구축]  (0) 2020.04.15
    2020-04-14  (1) 2020.04.14
    연습 [2020-04-12]  (2) 2020.04.12
Designed by Tistory.