forked from plutoscarab/Rails
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStrike.cs
82 lines (71 loc) · 1.94 KB
/
Strike.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
// Strike.cs
/*
* This class represents a coastal or inland labor strike random event.
*
*/
using System;
using System.Drawing;
using System.IO;
namespace Rails
{
public class Strike : Disaster
{
private bool coastal; // or inland
private bool[] affectedCities; // which cites are in affected area
public Strike(int player, Map map, bool coastal) : base(player, map)
{
this.coastal = coastal;
// store them in an array for later
affectedCities = new bool[map.CityCount];
for (int i=0; i<map.CityCount; i++)
{
City city = map.Cities[i];
if ((map[city.X, city.Y].DistanceInland < 4) == coastal)
affectedCities[i] = true;
}
}
public override void Save(BinaryWriter writer)
{
base.Save(writer);
writer.Write((int) 0); // version
writer.Write(coastal);
writer.Write(affectedCities.Length);
for (int i=0; i<affectedCities.Length; i++)
writer.Write(affectedCities[i]);
}
public Strike(BinaryReader reader, Map map) : base(reader, map)
{
int version = reader.ReadInt32();
coastal = reader.ReadBoolean();
int n = reader.ReadInt32();
affectedCities = new bool[n];
for (int i=0; i<n; i++)
affectedCities[i] = reader.ReadBoolean();
}
public override bool IsLaborStrike(int city)
{
return affectedCities[city];
}
public override void Draw(Graphics g)
{
Brush brush = new SolidBrush(Color.FromArgb(128, Color.Yellow));
int r = 40;
int x, y;
for (int i=0; i<map.CityCount; i++)
if (affectedCities[i])
{
City city = map.Cities[i];
if (map.GetCoord(city.X, city.Y, out x, out y))
g.FillEllipse(brush, x - r, y - r, 2 * r, 2 * r);
}
brush.Dispose();
}
public override string ToString()
{
if (coastal)
return "Dock Workers Strike\rUnrest paralyzes coastal cities";
else
return "General Strike\rUnrest paralyzes inland cities";
}
}
}