-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDebuggingForm.cs
153 lines (129 loc) · 4.83 KB
/
DebuggingForm.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
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 System.IO;
namespace Monopoly
{
public partial class DebuggingForm : Form
{
public DebuggingForm(ref Monopoly monopoly)
{
InitializeComponent();
this.MonopolyRef = monopoly;
this.Game = monopoly.ActiveGame;
this.SelectedID = 0;
foreach (Tiles.BoardSpace b in Game.Board.BoardSpaces)
{
lbxBoardSpaces.Items.Add(b.Position + ": " + b.Name);
}//foreach
toolTip1.SetToolTip(btnCopyLog, "Copies the log of the current session to a new file");
}//DebuggingForm
private Monopoly MonopolyRef { get; set; }
private GameState Game { get; set; }
private int SelectedID { get; set; }
private void btnSendToPos_Click_1(object sender, EventArgs e)
{
if (Game.IsStarted == true)
{
String msg = String.Format("Attempting to send player {0} to position {1} via the debug menu", SelectedID, lbxBoardSpaces.SelectedIndex);
MonopolyRef.UI.UIDebug(msg);
MonopolyRef.GameLogic.AdvancePlayerToPosition(SelectedID, lbxBoardSpaces.SelectedIndex);
}
else
{
MessageBox.Show("You can't send a player to a position until the game has been started.", "Error");
}
}
private void btnGoToJail_Click(object sender, EventArgs e)
{
lbxBoardSpaces.SelectedIndex = 31;
}
private void btnGoToProp_Click(object sender, EventArgs e)
{
lbxBoardSpaces.SelectedIndex = 4;
}
private void btnGoToRailroad_Click(object sender, EventArgs e)
{
lbxBoardSpaces.SelectedIndex = 16;
}
private void btnGoToChance_Click_1(object sender, EventArgs e)
{
lbxBoardSpaces.SelectedIndex = 8;
}
private void btnGoToUtil_Click(object sender, EventArgs e)
{
lbxBoardSpaces.SelectedIndex = 29;
}
private void btnGoToGo_Click(object sender, EventArgs e)
{
lbxBoardSpaces.SelectedIndex = 1;
}
private void btnPrintStats_Click(object sender, EventArgs e)
{
MessageBox.Show(Game.Players[SelectedID].ToString(), String.Format("Player {0} Stats", SelectedID + 1));
}
private void btnTruncateLog_Click(object sender, EventArgs e)
{
File.Delete("Log.txt");
MonopolyRef.UI.DisplayPopup("Log has been truncated on the debug menu", "Log truncated");
}
private void btnCopyLog_Click(object sender, EventArgs e)
{
try
{
StreamReader reader = new StreamReader("Log.txt");
String fullLog = reader.ReadToEnd();
reader.Close();
fullLog = fullLog.Substring(fullLog.LastIndexOf("#"));
File.WriteAllText("GameLog.txt", fullLog);
MonopolyRef.UI.DisplayPopup("Log copied to GameLog.txt", "Log Copied");
}
catch (FileNotFoundException ex)
{
MonopolyRef.UI.DisplayPopup("Error in Log Copy: " + ex.Message, "Error");
}
catch (ArgumentOutOfRangeException ex)
//almost always as a result of truncating the log before copying it
{
StreamReader reader = new StreamReader("Log.txt");
String fullLog = reader.ReadToEnd();
reader.Close();
File.WriteAllText("GameLog.txt", fullLog);
MonopolyRef.UI.DisplayPopup("Log copied to GameLog.txt", "Log Copied");
}
}
private void rbtPlayer1_CheckedChanged(object sender, EventArgs e)
{
if (rbtPlayer1.Checked == true)
{
SelectedID = 0;
}
else
{
SelectedID = 1;
}//if-else
}
private void btnSetMoney_Click(object sender, EventArgs e)
{
if (tbxSetMoney.Text != String.Empty)
{
try
{
Game.Players[SelectedID].Money = int.Parse(tbxSetMoney.Text);
MonopolyRef.UI.DisplayPopup("Player " + (SelectedID + 1) + "s money set to " + tbxSetMoney.Text + " with debug form", "Set Money");
}
catch (InvalidCastException ex)
{
MonopolyRef.UI.Error("Data must be numerical", ex);
}//catch
}//if
}//SetMoney_Click
}
}