-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMonopoly.cs
225 lines (192 loc) · 7.28 KB
/
Monopoly.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using Monopoly.Properties;
using System.IO;
using System.Timers;
namespace Monopoly
{
public partial class Monopoly : Form
{
private GameLogic mGameLogic;
private MoneyLogic mMoneyLogic;
private CardLogic mCardLogic;
private Monopoly refMonopoly;
public Monopoly()
{
InitializeComponent();
this.ReadyToStart = false;
this.TestMode = false;
this.TestState = 1;
}//Monopoly()
//PROPERTIES
public GameState ActiveGame { get; set; }
public GameLogic GameLogic { get { return mGameLogic; } set { mGameLogic = value; } }
public MoneyLogic MoneyLogic { get { return mMoneyLogic; } set { mMoneyLogic = value; } }
public CardLogic CardLogic { get { return mCardLogic; } set { mCardLogic = value; } }
public UI UI { get; set; }
public bool ReadyToStart { get; private set; }
private TestFunctions Test { get; set; }
public bool TestMode { get; private set; }
public int TestState { get; set; }
//METHODS
public void PrepareGame()
{
refMonopoly = this;
ActiveGame = new GameState(); //called first, since UI needs it
this.UI = new UI(this);
UI.WriteToLog("#");
UI.UIDebug("A new game is being prepared");
IntializeLogic();
ReadyToStart = true;
UI.UIDebug("Game has been prepared.");
}
public void IntializeLogic()
{
GameLogic = new GameLogic(this);
CardLogic = new CardLogic(this);
MoneyLogic = new MoneyLogic(this);
GameLogic.Initialize();
CardLogic.Initialize();
MoneyLogic.Initialize();
}//InitializeLogic
public void SetTestMode()
{
PrepareGame();
refMonopoly = this;
Test = new TestFunctions(ref refMonopoly);
TestMode = true;
}//SetTestMode()
private void Monopoly_Paint(object sender, PaintEventArgs e)
{
/*
* //This draws two rectangles that were once going to display the space each player was on, but it's no longer necessary
* TODO: Clean up
System.Drawing.Graphics graphicsObj;
graphicsObj = this.CreateGraphics();
Pen myPen = new Pen(System.Drawing.Color.Black, 2);
Rectangle rect = new Rectangle(125, 75, 200, 250);
graphicsObj.DrawRectangle(myPen, rect); //player 1's rectangle
graphicsObj.DrawLine(myPen, 375, 20, 375, 400); //the division between the players
rect = new Rectangle(425, 75, 200, 250);
graphicsObj.DrawRectangle(myPen, rect); //player 2's rectangle
* */
}//Paint
private void Form1_Load(object sender, EventArgs e)
{
PrepareGame();
P1GoojOut.Text = String.Empty;
P1MoneyOut.Text = String.Empty;
P1PosOut.Text = String.Empty;
P2GoojOut.Text = String.Empty;
P2MoneyOut.Text = String.Empty;
P2PosOut.Text = String.Empty;
}
private void btnStart_Click(object sender, EventArgs e)
{
if (ReadyToStart)
{
DisableStartButton();
GameLogic.StartGame();
}//if
else
{
PrepareGame();
UI.Error("Game was not ready. Game was prepared. Try again.");
}//else
}//btnStart_Click
private void OpenDialog(Form form)
{
form.ShowDialog(this);
}//OpenDialog
public void HandleOutput(String output)
{
lbxOutput.Items.Add(output);
lbxOutput.SelectedIndex = lbxOutput.Items.Count - 1;
}//HandleOutput
public void SyncPlayerStats()
{
Player p1 = ActiveGame.Players[0];
Player p2 = ActiveGame.Players[1];
P1MoneyOut.Text = p1.Money.ToString();
P1PosOut.Text = String.Format("{0}: {1}", p1.Position, ActiveGame.Board.BoardSpaces[p1.Position].Name);
P1GoojOut.Text = p1.JailFreeCards.ToString();
P2MoneyOut.Text = p2.Money.ToString();
P2PosOut.Text = String.Format("{0}: {1}", p2.Position, ActiveGame.Board.BoardSpaces[p2.Position].Name);
P2GoojOut.Text = p2.JailFreeCards.ToString();
P1OwnedPropsOut.Items.Clear();
P2OwnedPropsOut.Items.Clear();
foreach(Tiles.BuyableSpace p in p1.OwnedProperties) { P1OwnedPropsOut.Items.Add(p.Name); }
foreach (Tiles.BuyableSpace p in p2.OwnedProperties) { P2OwnedPropsOut.Items.Add(p.Name); }
if (p1.Railroads > 0) { P1OwnedPropsOut.Items.Add("Railroads: " + p1.Railroads); }
if (p1.Utilities > 0) { P1OwnedPropsOut.Items.Add("Utilities: " + p1.Utilities); }
if (p2.Railroads > 0) { P2OwnedPropsOut.Items.Add("Railroads: " + p2.Railroads); }
if (p2.Utilities > 0) { P2OwnedPropsOut.Items.Add("Utilities: " + p2.Utilities); }
}//SyncPlayerStats()
private void btnRoll_Click(object sender, EventArgs e)
{
GameLogic.Roll();
}
public void EnableStartButton()
{
btnStart.Enabled = true;
}//EnableStartButton()
public void DisableStartButton()
{
btnStart.Enabled = false;
}//DisableStartButton()
public void EnableRollButton()
{
btnRoll.Enabled = true;
}//EnableRollButton()
public void DisableRollButton()
{
btnRoll.Enabled = false;
}
private void btnDebug_Click(object sender, EventArgs e)
{
Monopoly thisRef = this;
DebuggingForm debug = new DebuggingForm(ref thisRef);
debug.Show();
}//DisableRollButton()
public void IndicateActivePlayer()
{
//Set the label of the active player to green
//TODO: use system colors rather than hard-coded values
if (ActiveGame.ActivePlayerID == 0)
{
lblPlayer1.ForeColor = Color.Green;
lblPlayer2.ForeColor = Color.Black;
}
else
{
lblPlayer1.ForeColor = Color.Black;
lblPlayer2.ForeColor = Color.Green;
}
this.Refresh();
}
private void Monopoly_FormClosing(object sender, FormClosingEventArgs e)
{
UI.UIDebug("Game form is closing");
}
private void btnImprove_Click(object sender, EventArgs e)
{
ImproveMenu improveForm = new ImproveMenu(this);
improveForm.ShowDialog();
}//Improve_Click()
public void GameOver()
{
btnRoll.Enabled = false;
btnImprove.Enabled = false;
btnStart.Enabled = true;
PrepareGame();
}//GameOver()
}//Monopoly
}