-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
178 lines (156 loc) · 6.25 KB
/
Program.cs
File metadata and controls
178 lines (156 loc) · 6.25 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
using System;
using System.Collections.Generic;
using System.Linq;
namespace Dictionary
{
internal class Program
{
static Random rand = new Random();
static void Main(string[] args)
{
Player player = new Player("Victor", 20);
GameData.AddCard(new Card(1, "Меч новичка", Rarity.Usual));
GameData.AddCard(new Card(2, "Палка", Rarity.Usual));
GameData.AddCard(new Card(3, "Медное кольцо", Rarity.Usual));
GameData.AddCard(new Card(4, "Огненный шар", Rarity.Rare));
GameData.AddCard(new Card(5, "Морозная буря", Rarity.Rare));
GameData.AddCard(new Card(6, "Пламенный меч", Rarity.Rare));
GameData.AddCard(new Card(7, "Кинжал вора", Rarity.Epic));
GameData.AddCard(new Card(8, "Шапка ушанка", Rarity.Epic));
GameData.AddCard(new Card(9, "Лук власти", Rarity.Legendary));
GameData.AddCard(new Card(10, "Корона правления", Rarity.Legendary));
bool isPlaying = true;
while (isPlaying)
{
Console.WriteLine("1 - Показать каталог карт");
Console.WriteLine("2 - Открыть сундук");
Console.WriteLine("3 - Продать карту");
Console.WriteLine("4 - Показать инвентарь");
Console.WriteLine("5 - Выйти");
if(int.TryParse(Console.ReadLine(), out int choice))
{
switch (choice)
{
case 1:
Console.WriteLine("===Каталог===");
GameData.ShowCatalog();
break;
case 2:
Console.WriteLine("===Сундук===");
OpenLootbox(player, GameData.CardsContainer);
break;
case 3:
Console.WriteLine("===Продажа===");
Console.Write("Введите id карты для продажи: ");
if (int.TryParse(Console.ReadLine(), out int cardId))
SellCard(player, cardId, GameData.CardsContainer);
break;
case 4:
Console.WriteLine("===Инвентарь===");
player.ShowInventory();
break;
case 5: isPlaying = false; break;
default:
break;
}
}
}
}
static void OpenLootbox(Player player, Dictionary<int, Card> allCards)
{
var keys = allCards.Keys.ToArray();
int randomIndex = rand.Next(0, allCards.Count);
int randomCardId = keys[randomIndex];
Card card = allCards[randomCardId];
Console.WriteLine($"Вы открыли сундук и нашли карту: {card.Name} ({card.CardRarity})!");
player.AddToInventory(card);
Console.WriteLine();
}
static void SellCard(Player player, int cardId, Dictionary<int, Card> allCards)
{
if (!allCards.ContainsKey(cardId))
{
Console.WriteLine("Такой карты не существует в игре!");
return;
}
Card cardToSell = player.Inventory.FirstOrDefault(c => c.Id == cardId);
if (cardToSell != null)
{
player.Inventory.Remove(cardToSell);
int price = allCards[cardId].BasePrice;
player.Gold += price;
Console.WriteLine($"Вы продали {cardToSell.Name} за {price} монет. Теперь у вас {player.Gold} монет.");
}
else
Console.WriteLine("Карта не найдена.");
Console.WriteLine();
}
}
public class Card
{
public int Id { get; }
public string Name { get; }
public Rarity CardRarity { get; }
public int BasePrice { get; }
public Card(int id, string name, Rarity cardRarity)
{
Id = id;
Name = name;
CardRarity = cardRarity;
switch (cardRarity)
{
case Rarity.Usual: BasePrice = 10; break;
case Rarity.Rare: BasePrice = 50; break;
case Rarity.Epic: BasePrice = 200; break;
case Rarity.Legendary: BasePrice = 1000; break;
}
}
}
public class Player
{
public string Name { get; }
public int Gold { get; set; }
public List<Card> Inventory { get; }
public Player (string name, int gold)
{
Name = name;
Gold = gold;
Inventory = new List<Card>();
}
public void AddToInventory (Card card)
{
Inventory.Add(card);
}
public void ShowInventory()
{
foreach(Card card in Inventory)
{
Console.WriteLine($"Id: {card.Id} - {card.Name}, Цена - {card.BasePrice}");
}
Console.WriteLine();
}
}
static class GameData
{
static public Dictionary<int, Card> CardsContainer = new Dictionary<int, Card>();
public static void AddCard(Card card)
{
CardsContainer.Add(card.Id, card);
}
public static void ShowCatalog()
{
foreach (Card card in CardsContainer.Values)
{
Console.WriteLine($"Id: {card.Id} - {card.Name}, Цена - {card.BasePrice}");
}
Console.WriteLine();
}
}
public enum Rarity
{
Usual,
Rare,
Epic,
Legendary
}
}