/
Cat.cs
321 lines (276 loc) · 11.3 KB
/
Cat.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tamagochi
{
public class Cat : Appearance
{
public void Menu()
{
Console.ForegroundColor = ConsoleColor.Green;
Console.BackgroundColor = ConsoleColor.Black;
Console.WriteLine(" \t \t \t ------МЕНЮ------- \t \t \t \n");
Console.WriteLine("\t Выберите действие: \n \n 1 - Кормить \n 2 - Играть \n 3 - Спать \n 4 - Гулять \n 5 - Выбрать внешность \n 6 - Выбрать породу \n 7 - Выход");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Введите номер выбора");
int input = Convert.ToInt32(Console.ReadLine());
link: try
{
switch (input)
{
case 1:
Cat c1 = new Cat();
c1.Feed();
break;
case 2:
Cat c2 = new Cat();
c2.Play();
break;
case 3:
Cat c3 = new Cat();
c3.Sleep();
break;
case 4:
Cat c4 = new Cat();
c4.Walk();
break;
case 5:
Cat c5 = new Cat();
c5.Appearance();
break;
case 6:
Cat c6 = new Cat();
c6.Breed();
break;
case 7:
return;
}
}
catch (FormatException)
{
Console.WriteLine("Читай внимательно! Надо вводить Ч-И-С-Л-О!");
goto link;
}
if (input < 1 || input > 7)
{ try
{
Console.WriteLine("Проверьте введенное число!");
goto link;
}
catch (FormatException)
{
Console.WriteLine("Число должно быть от 1 до 7");
goto link;
}
}
}
public void Feed()
{
Console.WriteLine("Выберите, чем покормить кота. \n Если нужного блюда в списке нет, введите любое другое число, чтобы добавить свое \n");
List<string> food = new List<string>();
food.Add("1 - рыба");
food.Add("2 -вискас");
food.Add("3 - молоко");
foreach (string f in food)
{
Console.WriteLine(f);
}
int i;
i = Convert.ToInt32(Console.ReadLine());
if (i == 1)
{
Console.WriteLine("Сегодня на обед у кота" + " " + (food[0]) + "\n");
}
else if (i == 2)
{
Console.WriteLine("Сегодня на обед у кота" + " " + (food[1]) + "\n");
}
else if (i == 3)
{
Console.WriteLine("Сегодня на обед у кота" + " " + (food[2]) + "\n");
}
else
{
Console.WriteLine("Введите свой вариант еды: \n");
string newfood = Console.ReadLine();
food.Add(newfood);
foreach (string f in food)
{
Console.WriteLine(f);
}
Console.WriteLine("Сегодня на обед у кота" + " " + (food[3]) + "\n");
}
Console.WriteLine("Для возврата в основное меню нажмите Enter");
Console.ReadLine();
Menu();
}
public void Play()
{
Console.WriteLine("Сыграем? Правила простые: ваш питомец загадал число. Попробуйте угадать его! \n");
start:
Console.WriteLine("Введите число от 1 до 10: \n");
int number;
number = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Вы ввели число {0}", number.ToString());
Random ran = new Random();
int min = 1;
int max = 10;
for (int i = 1; i <= 1; i++)
{
Console.WriteLine("Посмотрим, совпали ли ваши числа. \n Ваш питомец загадал число " + ran.Next(min, max));
}
Console.WriteLine("Хотите сыграть еще раз? 1 - Да \n 2 - Нет \n");
int enter;
enter = Convert.ToInt32(Console.ReadLine());
if (enter == 1)
{
goto start;
}
else
{
Console.WriteLine("Для возврата в основное меню нажмите Enter \n");
Console.ReadLine();
Menu();
}
}
public void Sleep()
{
int input;
Console.WriteLine("Время спать? \t 1 - Да \t 0 - Нет");
input = Convert.ToInt32(Console.ReadLine());
if (input == 1)
{
Console.WriteLine("Кот спит. Чтобы разбудить его и вернуться в основное меню, нажмите Enter \n");
Console.WriteLine("Для возврата в основное меню нажмите Enter \n");
Console.ReadLine();
Menu();
}
else
{
Menu();
}
}
public void Walk()
{
int input;
Console.WriteLine("Хотите отправить питомца на прогулку? \t 1 - Да \t 0 - Нет");
input = Convert.ToInt32(Console.ReadLine());
if (input == 1)
{
Console.WriteLine("Кот на прогулке. Чтобы вернуться в основное меню, нажмите Enter \n");
Console.WriteLine("Для возврата в основное меню нажмите Enter \n");
Console.ReadLine();
Menu();
}
else
{
Menu();
}
}
public override string HairColor // переопределение абстрактного свойства
{
get
{
return haircolor;
}
set
{
haircolor = value;
}
}
public override string HairLength // переопределение абстрактного свойства
{
get
{
return hairlength;
}
set
{
hairlength = value;
}
}
public override string Breed() // переопределение абстрактного метода
{
Console.WriteLine("Выберите породу. \n Если нужной породы в списке нет, введите любое другое число, чтобы добавить свою \n");
List<string> breeds = new List<string>();
breeds.Add("1 - Перс");
breeds.Add("2 - Британская");
breeds.Add("3 - Мейн-кун \n");
foreach (string breed in breeds)
{
Console.WriteLine(breed);
}
int result = Convert.ToInt32(Console.ReadLine());
if (result == 1)
{
Console.WriteLine("Выбрана порода: " + " " + (breeds[0]) + "\n");
Console.WriteLine("Для возврата в основное меню нажмите Enter \n");
Console.ReadLine();
Menu();
return result.ToString();
}
else if (result == 2)
{
Console.WriteLine("Выбрана порода: " + " " + (breeds[1]) + "\n");
Console.WriteLine("Для возврата в основное меню нажмите Enter \n");
Console.ReadLine();
Menu();
return result.ToString();
}
else if (result == 3)
{
Console.WriteLine("Выбрана порода: " + " " + (breeds[2]) + "\n");
Console.WriteLine("Для возврата в основное меню нажмите Enter \n");
Console.ReadLine();
Menu();
return result.ToString();
}
else
{
Console.WriteLine("Введите свою породу: \n");
string newbreed = Console.ReadLine();
breeds.Add(newbreed);
foreach (string breed in breeds)
{
Console.WriteLine(breed);
}
Console.WriteLine("Выбрана своя порода: " + " " + (breeds[3]) + "\n");
return result.ToString();
}
}
public void Appearance()
{
Cat c1 = new Cat();
Console.WriteLine("Выберите цвет шерсти: \n");
string[] hair = new string[3];
hair[0] = "Рыжий";
hair[1] = "Черный";
hair[2] = "Белый \n";
foreach (string i in hair)
{
Console.WriteLine(i);
}
string s = Console.ReadLine();
c1.HairColor = s;
Console.WriteLine("Выбран цвет шерсти: " + " " + c1.HairColor + "\n");
Cat c2 = new Cat();
Console.WriteLine("Выберите длину шерсти: \n");
string[] length = new string[3];
length[0] = "Короткая";
length[1] = "Средняя";
length[2] = "Длинная \n";
foreach (string h in length)
{
Console.WriteLine(h);
}
string u = Console.ReadLine();
c2.HairLength = u;
Console.WriteLine("Выбрана длина шерсти:" + " " + c2.HairLength + "\n");
Console.WriteLine("Для возврата в основное меню нажмите Enter \n");
Console.ReadLine();
Menu();
}
}
}