-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quartal.cs
283 lines (267 loc) · 8.48 KB
/
Quartal.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
using System;
using System.Collections.Generic;
using System.Windows.Media;
namespace Monopoly
{
public class Quartal
{
private readonly string name;
private readonly ConsoleColor color;
private Player owner;
private int visitors;
/// <summary>
/// Специальное обозначение улицы.
/// -1 – обычная улица
/// 0 – старт;
/// 1 – казна;
/// 2 – шанс;
/// 3 – тюрьма;
/// 4 – парковка;
/// 5 – арест;
/// 6 – порт;
/// 7 – коммунальное предприятие;
/// 8 – налог;
/// 9 – дорогая покупка.
/// </summary>
private readonly int special;
private readonly int cost;
private readonly int noMonopolyRent;
private readonly int monopolyRent;
private readonly int house1Rent;
private readonly int house2Rent;
private readonly int house3Rent;
private readonly int house4Rent;
private readonly int hotelRent;
private readonly int houseCost;
/// <summary>
/// 0 – без домов;
/// 1 – 1 дом;
/// 2 – 2 дома;
/// 3 – 3 дома;
/// 4 – 4 дома;
/// 5 отель.
/// </summary>
private int level;
private readonly int pledge;
private readonly List<Quartal> colorGroup;
private bool isMantaged;
private bool? isMonopoly;
public string Name { get { return name; } }
public ConsoleColor Color { get { return color; } }
public Player Owner { get { return owner; } }
public int Visitors { get { return visitors; } }
public int Special { get { return special; } }
public int Cost { get { return cost; } }
public int NoMonopolyRent { get { return noMonopolyRent; } }
public int MonopolyRent { get { return monopolyRent; } }
public int House1Rent { get { return house1Rent; } }
public int House2Rent { get { return house2Rent; } }
public int House3Rent { get { return house3Rent; } }
public int House4Rent { get { return house4Rent; } }
public int HotelRent { get { return hotelRent; } }
public int HouseCost { get { return houseCost; } }
public int Level { get { return level; } }
public int Pledge { get { return pledge; } }
public List<Quartal> ColorGroup { get { return colorGroup; } }
public bool IsMantaged { get { return isMantaged; } }
public bool? IsMonopoly { get { return isMonopoly; } }
public Quartal (string _name, ConsoleColor _color, int _cost, int _noMonopolyRent, int _monopolyRent, int _house1Rent, int _house2Rent,
int _house3Rent, int _house4Rent, int _hotelRent, int _houseCost, int _pledge)
{
name = _name;
special = -1;
color = _color;
owner = null;
visitors = 0;
level = 0;
cost = _cost;
noMonopolyRent = _noMonopolyRent;
monopolyRent = _monopolyRent;
house1Rent = _house1Rent;
house2Rent = _house2Rent;
house3Rent = _house3Rent;
house4Rent = _house4Rent;
hotelRent = _hotelRent;
houseCost = _houseCost;
pledge = _pledge;
colorGroup = new List<Quartal>();
isMantaged = false;
isMonopoly = false;
}
public Quartal(string _name, bool isBlack)
{
if (isBlack)
{
special = 6;
color = ConsoleColor.Black;
cost = 200;
pledge = 100;
}
else
{
special = 7;
color = ConsoleColor.Gray;
cost = 150;
pledge = 75;
}
name = _name;
owner = null;
visitors = 0;
isMantaged = false;
isMonopoly = null;
}
public Quartal (int _special)
{
special = _special;
visitors = 0;
}
public void Reset()
{
visitors = 0;
if (Special == 6 || Special == 7)
{
isMantaged = false;
owner = null;
}
if (Special == -1)
{
owner = null;
isMantaged = false;
isMonopoly = null;
}
}
public void InitStart(int playersCount)
{
if (special == 0) visitors = playersCount;
}
public void AddToGroup(Quartal quartal)
{
colorGroup.Add(quartal);
}
public void SetOwner(Player player)
{
if (player == null)
{
owner.DecreaseColor(this);
owner.RemoveProperty(this);
owner = null;
isMonopoly = false;
if (colorGroup != null)
{
foreach (Quartal quartal in colorGroup)
{
quartal.isMonopoly = false;
}
}
}
else
{
if (owner == null)
{
player.Pay(cost);
}
else
{
owner.DecreaseColor(this);
owner.RemoveProperty(this);
}
owner = player;
owner.IncreaseColor(this);
owner.AddProperty(this);
if (colorGroup != null)
{
isMonopoly = true;
foreach (Quartal quartal in colorGroup)
{
if (quartal.owner != owner)
{
isMonopoly = false;
break;
}
}
foreach (Quartal quartal in colorGroup)
{
quartal.isMonopoly = isMonopoly;
}
}
}
}
public void SetOwner(Player player, int bid)
{
if (owner == null)
{
player.Pay(bid);
}
else
{
owner.DecreaseColor(this);
owner.RemoveProperty(this);
}
owner = player;
owner.IncreaseColor(this);
owner.AddProperty(this);
if (colorGroup != null)
{
isMonopoly = true;
foreach (Quartal quartal in colorGroup)
{
if (quartal.owner != owner)
{
isMonopoly = false;
break;
}
}
foreach (Quartal quartal in colorGroup)
{
quartal.isMonopoly = isMonopoly;
}
}
}
public void Mantage()
{
isMantaged = true;
owner.Receive(Pledge);
}
public void Redeem()
{
isMantaged = false;
owner.Pay(pledge + pledge / 10);
}
public void Downgrade()
{
if (level == 5)
{
owner.AddHouses(4);
owner.DecreaseHotels();
}
else
{
owner.ReduceHouses(1);
}
level--;
owner.Receive(houseCost / 2);
}
public void IncreaseVisitors()
{
visitors++;
}
public void DecreaseVisitors()
{
visitors--;
}
public void Upgrade()
{
level++;
if (level == 5)
{
owner.ReduceHouses(4);
owner.IncreaseHotels();
}
else
{
owner.AddHouses(1);
}
owner.Pay(houseCost);
}
}
}