2020-04-17 과제
-----------------------------------------------------------------------------------------------------------------------------------Class
-----------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Homework_003
{
class App
{
//데이터
public App()
{
Character beak = new Character("백종원"); //"백종원" 캐릭터 생성
FoodIngredient[] arrFoodIngredient = new FoodIngredient[5];
arrFoodIngredient[0] = new FoodIngredient("따뜻한 밥", 1);
arrFoodIngredient[1] = new FoodIngredient("김", 1);
arrFoodIngredient[2] = new FoodIngredient("참치", 1);
arrFoodIngredient[3] = new FoodIngredient("마요", 1);
arrFoodIngredient[4] = new FoodIngredient("깻잎", 1);
Recipe recipe = new Recipe("특제참치김밥", arrFoodIngredient);
beak.GetRecipe(recipe); //캐릭터가 레시피를 줍는 메서드
//Console.WriteLine("[{0}]", recipe.ShowRecipeName());
//foreach (FoodIngredient ingredient in arrFoodIngredient)
//{
// Console.WriteLine(ingredient.name);
//}
arrFoodIngredient = new FoodIngredient[5];
arrFoodIngredient[0] = new FoodIngredient("뜨거운 물", 1);
arrFoodIngredient[1] = new FoodIngredient("탱탱우동면", 1);
arrFoodIngredient[2] = new FoodIngredient("새우", 1);
arrFoodIngredient[3] = new FoodIngredient("마리나라용 해물", 1);
arrFoodIngredient[4] = new FoodIngredient("가쓰오육수", 1);
recipe = new Recipe("특제해물우동", arrFoodIngredient);
beak.GetRecipe(recipe); // 캐릭터가 레시피를 줍는 메서드
//beak.ShowMyRecipeList();
//beak.ShowLearnedRecipeList();
beak.UseRecipe("특제참치김밥"); //조리법 : 특제참치김밥을 배웁니다.
beak.ShowMyRecipeList();
beak.ShowLearnedRecipeList();
// 아이템 수량을 고려해 획득하고 획득한 아이템으로 요리를 만든다.
//아이템 획득
beak.GetItem("따뜻한 밥", 1);
beak.GetItem("김", 1);
beak.GetItem("참치", 1);
beak.GetItem("마요", 1);
beak.GetItem("깻잎", 1);
beak.ShowMyIngredientBag(); //재료 아이템 가방 목록 확인
beak.ShowMyFoodsBag(); // 나의 음식 아이템 가방 목록 확인
beak.ReadyCook("특제참치김밥");
beak.ShowMyIngredientBag(); //재료 아이템 가방 목록 확인
beak.ShowMyFoodsBag(); // 나의 음식 아이템 가방 목록 확인
}
}
}
|
-----------------------------------------------------------------------------------------------------------------------------------Recipe 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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Homework_003
{
class Recipe
{
public FoodIngredient[] arrFoodIngredient;
public string name;
//데이터
public Recipe(string name, FoodIngredient[] arrFoodIngredient)
{
this.name = name;
this.arrFoodIngredient = arrFoodIngredient;
Console.WriteLine("[{0}] 레시피가 생성되었습니다.", this.name);
}
//메서드
public string ShowRecipeName() // [조리법: (레시피이름)] 으로 출력해주는 메서드
{
string name = "조리법: " + this.name;
return name;
}
}
}
|
-----------------------------------------------------------------------------------------------------------------------------------Food Class
-----------------------------------------------------------------------------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Homework_003
{
class Food
{
public string name;
public int amount;
//데이터
public Food(string name, int amount)
{
this.name = name;
this.amount = amount;
}
}
}
|
-----------------------------------------------------------------------------------------------------------------------------------FoodIngredient Class
-----------------------------------------------------------------------------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Homework_003
{
class FoodIngredient
{
public string name;
public int amount;
//데이터
public FoodIngredient(string name, int amount)
{
this.name = name;
this.amount = amount;
}
}
}
|
-----------------------------------------------------------------------------------------------------------------------------------Character 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
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
|
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace Homework_003
{
class Character
{
public string name;
public Recipe[] arrPickUpRecipe = new Recipe[6];
public Recipe[] arrLeanedRecipe = new Recipe[6];
int pickUpRecipeInx = 0; //획득하는 레시피 아이템의 인덱스
int useRecipeInx = 0; //사용하는 레시피 아이템의 인덱스
public FoodIngredient[] arrUserFoodIngredientsBag = new FoodIngredient[5];
public Food[] arrUserFoodBag = new Food[5];
int userFoodIngredientsBaginx = 0;
int userFoodBaginx = 0;
//데이터
public Character(string name) //생성자
{
this.name = name;
Console.WriteLine("[{0}]님이 생성되었습니다.", this.name);
}
// 획득 메서드
public void GetRecipe(Recipe recipe) //레시피 아이템 획득 메서드
{
this.arrPickUpRecipe[pickUpRecipeInx++] = recipe;
Console.WriteLine("★★★★★레시피 아이템 [{0}]를 획득하셨습니다.★★★★★\n", recipe.ShowRecipeName());
Console.ResetColor();
}
public void GetItem(string itemName,int amount)
{
FoodIngredient foodIngredient = new FoodIngredient(itemName, amount);
this.arrUserFoodIngredientsBag[userFoodIngredientsBaginx++] = foodIngredient;
Console.WriteLine("★★★★★요리 재료 아이템 [{0}]을 [{1}개] 획득하셨습니다.★★★★★\n",itemName,amount);
Console.ResetColor();
} //재료 아이템 획득 메서드
// 기능 메서드
public void UseRecipe(string name) // 가지고 있는 레시피 사용 메서드
{
int inx = 0;
foreach (Recipe recipe in this.arrPickUpRecipe)
{
if (recipe != null)
{
{
this.arrLeanedRecipe[useRecipeInx++] = recipe;
inx = Array.IndexOf(this.arrPickUpRecipe, recipe);
this.arrPickUpRecipe[inx] = null;
}
}
}
Console.WriteLine("\n○○○○○[{0}]를 배우셨습니다.○○○○○\n", name);
Console.ResetColor();
}
public void ReadyCook(string name) // 요리전에 매개변수로 받아온 문자열이 사용할 수 있는 레시피에 있는지 확인
{
foreach(Recipe recipe in this.arrLeanedRecipe) // 사용할 수 있는 레시피 목록 검색
{
if (recipe != null)
{
{
this.Cook(recipe); // Cook 메서드 실행(매개변수)
}
}
}
}
public void Cook(Recipe cookRecipe) //ReadyCook 메서드에서 받아온 매개변수 cookRecipe를 사용
{
bool isMade = false;
{
foreach (FoodIngredient foodIngredient in this.arrUserFoodIngredientsBag)
{
if (foodIngredient != null)
{
{
isMade = true;
}
}
}
}
{
if (this.arrUserFoodIngredientsBag[i].amount == 0)
{
this.arrUserFoodIngredientsBag[i] = null;
}
}
foreach (Food food in this.arrUserFoodBag) // 만들어졌으면 음식 아이템 가방에 넣음.
{
if (food == null)
{
if (isMade == true)
{
userFoodBaginx++;
break;
}
}
}
}
// 목록 출력 메서드
public void ShowMyIngredientBag()
{
Console.WriteLine("------------현재 소지하고 있는 재료 아이템 목록------------");
Console.ResetColor();
int inx = 0;
foreach (FoodIngredient foodIngredient in this.arrUserFoodIngredientsBag)
{
if (foodIngredient != null)
{
Console.ResetColor();
}
else if (foodIngredient == null)
{
Console.Write("[{0}번]", inx + 1);
Console.ResetColor();
Console.WriteLine("칸에 재료 아이템이 존재하지 않습니다.");
}
inx++;
}
Console.WriteLine("");
} // 현재 가지고 있는 재료 아이템 목록 메서드
public void ShowMyRecipeList()
{
Console.WriteLine("------------현재 소지하고 있는 레시피 목록------------");
Console.ResetColor();
int inx = 0;
foreach (Recipe recipe in this.arrPickUpRecipe)
{
if (recipe != null)
{
Console.ResetColor();
}
else if (recipe == null)
{
Console.Write("[{0}번]", inx + 1);
Console.ResetColor();
Console.WriteLine("칸에 레시피가 존재하지 않습니다.");
}
inx++;
}
Console.WriteLine();
} // 현재 가지고 있는 레시피 목록 메서드
public void ShowLearnedRecipeList()
{
Console.WriteLine("------------현재 사용할 수 있는 레시피 목록------------");
Console.ResetColor();
int inx = 0;
foreach (Recipe recipe in this.arrLeanedRecipe)
{
if (recipe != null)
{
Console.ResetColor();
}
else if (recipe == null)
{
Console.ForegroundColor = ConsoleColor.DarkBlue;
Console.Write("[{0}번]", inx + 1);
Console.ResetColor();
Console.WriteLine("칸에 레시피가 존재하지 않습니다.");
}
inx++;
}
Console.WriteLine("");
} // 현재 사용할 수 있는 레시피 목록 메서드
public void ShowMyFoodsBag()
{
Console.WriteLine("------------현재 소지하고 있는 음식 아이템 목록------------");
Console.ResetColor();
int inx = 0;
foreach (Food food in this.arrUserFoodBag)
{
if (food != null)
{
Console.ResetColor();
}
else if (food == null)
{
Console.Write("[{0}번]", inx + 1);
Console.ResetColor();
Console.WriteLine("칸에 음식 아이템이 존재하지 않습니다.");
}
inx++;
}
Console.WriteLine("");
}
}
}
|
-----------------------------------------------------------------------------------------------------------------------------------
출력값
-----------------------------------------------------------------------------------------------------------------------------------