-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cs
188 lines (181 loc) · 6.76 KB
/
Player.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace Win538Electors
{
internal class Player : Politician
{
private string party;
private int turns;
private double rallyCostIncrease;
private double donation;
private double donationCostIncrease;
private double adsCostIncrease;
private double campaignerCostIncrease;
// Getters
public string GetParty()
{
return party;
}
public int GetTurns()
{
return turns;
}
public double GetRallyCostIncrease() { return rallyCostIncrease; }
public double GetDonationCostIncrease() { return donationCostIncrease; }
public double GetAdsCostIncrease() { return adsCostIncrease; }
public double GetCampaignerCostIncrease() { return campaignerCostIncrease; }
// Setters
public void SetParty(string chosenParty)
{
party = chosenParty;
}
public void SetTurns()
{
// Player taken turn
turns = turns - 1;
}
// Constructor
public Player()
{
party = "Independent";
turns = 52;
rallyCostIncrease = 1.2;
adsCostIncrease = 1.3;
donationCostIncrease = 1.05;
campaignerCostIncrease = 1.05;
}
// Methods
public override void TurnTaken(Dictionary<string, int> statePolling, string[] states, Dictionary<string, int> campaignCosts)
{
SetTurnTicker(); // Count a turn
// Count donations
int donationsCount = 0;
Enumerable.Range(0, GetDonators()).ToList().ForEach(i =>
{
Random rand = new Random();
int donated = rand.Next(350, 501);
donationsCount += donated;
});
// Increase polling by +1 per campaigner for a random state (per campaigner)
Enumerable.Range(0, GetCampaigners()).ToList().ForEach(i =>
{
Random rand = new Random();
int stateChosen = rand.Next(0, 50);
statePolling[states[stateChosen]] += 1;
SetLatestAction($"A campaigner increased your polling by +1 in {states[stateChosen]} ({GetTurnTicker()})");
});
if (donationsCount > 0)
{
SetFundsIncrease(donationsCount);
SetLatestAction($"secured ${donationsCount} of funding this turn from your {GetDonators()} donators. ({GetTurnTicker()})");
}
}
public void Rally(string selectedState, Dictionary<string, int> statePolling, int rallyCost, double rallyCostIncrease)
{
if (funds >= rallyCost)
{
SetFundsPurchase(rallyCost);
statePolling[selectedState] += 4;
UpdateCampaignCost("Rally", Convert.ToInt32(rallyCost * rallyCostIncrease));
SetLatestAction($"Held a campaign rally in {selectedState}, increasing your polling by: +4 ({GetTurnTicker()})");
}
else
{
throw new InvalidOperationException("Not enough funds to rally.");
}
}
public void Ads(string selectedState, Dictionary<string, int> statePolling, int adsCost, double adsCostIncrease)
{
if (funds >= adsCost)
{
SetFundsPurchase(adsCost);
statePolling[selectedState] += 2;
UpdateCampaignCost("Ads", Convert.ToInt32(adsCost * adsCostIncrease));
SetLatestAction($"Placed TV Advertisements in {selectedState}, increasing your polling by: +2 ({GetTurnTicker()})");
}
else
{
throw new InvalidOperationException("Not enough funds to run ads.");
}
}
public void AddCampaigner(int campaignerCost, double campaignerCostIncrease)
{
if (funds >= campaignerCost)
{
SetFundsPurchase(campaignerCost);
SetCampaigners();
UpdateCampaignCost("Campaigner", Convert.ToInt32(campaignerCost * campaignerCostIncrease));
SetLatestAction($"Purchased a campaigner. ({GetTurnTicker()})");
}
else
{
throw new InvalidOperationException("Not enough funds to hire a campaigner.");
}
}
public void AddDonator(int donatorCost, double donatorCostIncrease)
{
if (funds >= donatorCost)
{
SetFundsPurchase(donatorCost);
SetDonators();
UpdateCampaignCost("Donators", Convert.ToInt32(donatorCost * donatorCostIncrease));
SetLatestAction($"Purchased a donator. ({GetTurnTicker()})");
}
else
{
throw new InvalidOperationException("Not enough funds to add a donator.");
}
}
// Save and load player data.
public override void SaveGame()
{
try
{
FileStream fs = new FileStream("player.dat", FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(GetFunds());
bw.Write(GetCampaigners());
bw.Write(GetDonators());
bw.Write(GetCampaignCost("Rally"));
bw.Write(GetCampaignCost("Ads"));
bw.Write(GetCampaignCost("Campaigner"));
bw.Write(GetCampaignCost("Donators"));
bw.Write(GetParty());
bw.Write(GetTurns());
bw.Close();
fs.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public override void LoadGame()
{
try
{
FileStream fs = new FileStream("player.dat", FileMode.Open);
BinaryReader br = new BinaryReader(fs);
this.funds = br.ReadInt32();
this.campaigners = br.ReadInt32();
this.donators = br.ReadInt32();
UpdateCampaignCost("Rally", br.ReadInt32());
UpdateCampaignCost("Ads", br.ReadInt32());
UpdateCampaignCost("Campaigner", br.ReadInt32());
UpdateCampaignCost("Donators", br.ReadInt32());
this.party = br.ReadString();
this.turns = br.ReadInt32();
br.Close();
fs.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}