-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
248 lines (217 loc) · 8.76 KB
/
Program.cs
File metadata and controls
248 lines (217 loc) · 8.76 KB
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
using System;
using System.Collections.Generic;
namespace Polymorphism
{
internal class Program
{
static void Main(string[] args)
{
QuestJournal questJournal = new QuestJournal();
KillQuest goblinHunting = new KillQuest("Охота на гоблинов", 100, "Гоблин", 3);
KillQuest trollHunting = new KillQuest("Охота на троллей", 350, "Тролль", 2);
CollectQuest theHerbalist = new CollectQuest("Травник", 10, "Трава", 2);
CollectQuest mushroomPicker = new CollectQuest("Грибник", 23, "Гриб", 4);
ExplorationQuest theDarkForest = new ExplorationQuest("Темный лес", 75, "Темный лес");
ExplorationQuest everest = new ExplorationQuest("Эверест", 125, "Заснеженые горы");
questJournal.AddQuest(goblinHunting);
questJournal.AddQuest(trollHunting);
questJournal.AddQuest(theHerbalist);
questJournal.AddQuest(mushroomPicker);
questJournal.AddQuest(theDarkForest);
questJournal.AddQuest(everest);
GameManager.Game(questJournal);
}
}
public static class GameManager
{
public static void Game(QuestJournal questJournal)
{
bool isPlaying = true;
while (isPlaying)
{
DrawMenu();
if (int.TryParse(Console.ReadLine(), out int choice))
{
switch (choice)
{
case 1:
Console.Write("Какой враг убит: ");
string enemyType = Console.ReadLine();
foreach (Quest quest in questJournal.Quests)
{
if (quest is KillQuest killQuest)
killQuest.EnemyKilled(enemyType);
}
break;
case 2:
Console.Write("Какой предмет найден: ");
string itemName = Console.ReadLine();
foreach (Quest quest in questJournal.Quests)
{
if (quest is CollectQuest collectQuest)
collectQuest.ItemCollected(itemName);
}
break;
case 3:
Console.Write("Какую локацию вы посетили: ");
string locationName = Console.ReadLine();
foreach (Quest quest in questJournal.Quests)
{
if (quest is ExplorationQuest explorationQuest)
explorationQuest.LocationReached(locationName);
}
break;
case 4:
foreach (Quest quest in questJournal.Quests)
quest.ShowInfo();
break;
case 5: isPlaying = false; break;
default:
Console.WriteLine("Не корректный ввод!");
break;
}
questJournal.UpdateAllQuests();
}
}
}
public static void DrawMenu()
{
Console.WriteLine("\n===Main Menu===");
Console.WriteLine("1. Убить врага");
Console.WriteLine("2. Найти предмет");
Console.WriteLine("3. Посетить локацию");
Console.WriteLine("4. Показать список квестов");
Console.WriteLine("5. Выйти из игры");
Console.Write("Ваш выбор: ");
}
}
public class QuestJournal
{
public readonly List<Quest> Quests = new List<Quest>();
public void AddQuest(Quest quest)
{
Quests.Add(quest);
}
public void UpdateAllQuests()
{
foreach (Quest quest in Quests)
{
quest.CheckProgress();
}
}
}
public abstract class Quest
{
public string QuestName { get; private set; }
public bool IsCompleted { get; private set; }
public int RewardGold { get; private set; }
public Quest(string questName, int rewardGold)
{
QuestName = questName;
RewardGold = rewardGold;
}
public abstract void CheckProgress();
protected void CompleteQuest()
{
if (!IsCompleted)
{
IsCompleted = true;
Console.WriteLine($"Квест '{QuestName}' выполнен! Получено {RewardGold} золота!");
}
}
public virtual void ShowInfo()
{
if (IsCompleted)
Console.WriteLine(" (Квест завершен)");
else Console.WriteLine();
}
}
public class KillQuest : Quest
{
public string targetEnemyType { get; private set; }
public int requiredKills { get; private set; }
public int currentKills { get; private set; }
public KillQuest(string questName, int rewardGold, string targetEnemyType, int requiredKills) : base(questName, rewardGold)
{
this.targetEnemyType = targetEnemyType;
this.requiredKills = requiredKills;
currentKills = 0;
}
public override void CheckProgress()
{
if (currentKills >= requiredKills)
CompleteQuest();
}
public void EnemyKilled(string enemyType)
{
if (enemyType == targetEnemyType && !IsCompleted)
{
currentKills++;
Console.WriteLine($"Убито {targetEnemyType}: {currentKills}/{requiredKills}");
}
}
public override void ShowInfo()
{
Console.Write($"{QuestName}: Убить {targetEnemyType}. Прогресс: {currentKills}/{requiredKills}");
base.ShowInfo();
}
}
public class CollectQuest : Quest
{
public string targetItemName { get; private set; }
public int requiredItems { get; private set; }
public int currentItems { get; private set; }
public CollectQuest(string questName, int rewardGold, string itemName, int requiredItems) : base(questName, rewardGold)
{
targetItemName = itemName;
this.requiredItems = requiredItems;
currentItems = 0;
}
public void ItemCollected(string itemName)
{
if (itemName == targetItemName && !IsCompleted)
{
currentItems++;
Console.WriteLine($"Собрано {targetItemName}: {currentItems}/{requiredItems}");
}
}
public override void CheckProgress()
{
if (currentItems >= requiredItems)
CompleteQuest();
}
public override void ShowInfo()
{
Console.Write($"{QuestName}: Собрать {targetItemName}. Прогресс: {currentItems}/{requiredItems}");
base.ShowInfo();
}
}
public class ExplorationQuest : Quest
{
public string targetLocation { get; private set; }
bool locationVisited = false;
public ExplorationQuest(string questName, int rewardGold, string targetLocation) : base(questName, rewardGold)
{
this.targetLocation = targetLocation;
}
public void LocationReached(string locationName)
{
if (locationName == targetLocation && !IsCompleted)
{
locationVisited = true;
Console.WriteLine($"Посещена локация: {targetLocation}");
}
}
public override void CheckProgress()
{
if (locationVisited)
CompleteQuest();
}
public override void ShowInfo()
{
string status = locationVisited ? "[Посещено]" : "[Не посещено]";
Console.Write($"{QuestName}: Посетить локацию {targetLocation} {status}");
base.ShowInfo();
}
}
}