-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainForm.cs
229 lines (173 loc) · 6.51 KB
/
MainForm.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
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.Threading;
using System.Diagnostics;
namespace MillMoneyMiner2
{
public partial class MainForm : Form
{
public int millmoney = 0;
public string logging = "";
public int intGuessValue = 999999999;
public string[] threadNums = new string[6];
public bool startMine = true;
public int Mining(int number)
{
logging = "";
int threadnumber = Thread.CurrentThread.ManagedThreadId;
Debug.WriteLine("Thread number:" + threadnumber);
threadNums.Append(threadnumber.ToString());
Debug.WriteLine(number);
var computerGenRandom = new Random();
var userGuessRandom = new Random();
var userGuess = userGuessRandom.Next(intGuessValue);
var compGuess = computerGenRandom.Next(intGuessValue);
bool shouldOutput = false;
int skipCount = 0;
//Debug.WriteLine("About to start guessing");
while (startMine)
{
if (skipCount > 1000000)
{
shouldOutput = true;
skipCount = 0;
}
else
{
shouldOutput = false;
skipCount++;
}
//Debug.WriteLine("In the while");
if (shouldOutput)
{
this.Invoke((MethodInvoker)delegate ()
{
switch (number)
{
case 1:
lblCompNum.Text = compGuess.ToString();
break;
case 2:
lblCompNum2.Text = compGuess.ToString();
break;
case 3:
lblCompNum3.Text = compGuess.ToString();
break;
default:
Debug.WriteLine(compGuess.ToString());
break;
}
});
}
//Debug.WriteLine("Set Userguess");
userGuess = userGuessRandom.Next(intGuessValue);
if (shouldOutput)
{
this.Invoke((MethodInvoker)delegate ()
{
switch (number)
{
case 1:
txtLogger.Text = userGuess.ToString();
break;
case 2:
txtLogger2.Text = userGuess.ToString();
break;
case 3:
txtLogger3.Text = userGuess.ToString();
break;
default:
Debug.WriteLine(txtLogger.Text = userGuess.ToString());
break;
}
});
}
//Debug.WriteLine("Comp Guess:" + compGuess.ToString());
//Debug.WriteLine("User Guess:" + userGuess.ToString());
if (userGuess == compGuess)
{
millmoney++;
this.Invoke((MethodInvoker)delegate ()
{
lblMillCount.Text = millmoney.ToString();
txtLogger.Text = "You earned another $MILL!";
switch (number)
{
case 1:
lblMillCount.Text = millmoney.ToString();
txtLogger.Text = "You earned another $MILL!";
break;
case 2:
lblMillCount.Text = millmoney.ToString();
txtLogger2.Text = "You earned another $MILL!";
break;
case 3:
lblMillCount.Text = millmoney.ToString();
txtLogger3.Text = "You earned another $MILL!";
break;
default:
Debug.WriteLine(millmoney.ToString());
Debug.WriteLine("You earned another $MILL!");
break;
}
});
compGuess = userGuessRandom.Next(intGuessValue);
}
}
return 0;
}
public MainForm()
{
InitializeComponent();
lblMillCount.Text = "None";
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
public void btnMine_Click(object sender, EventArgs e)
{
startMine = true;
Task taskA = new Task(() => Mining(1));
taskA.Start();
Task taskB = new Task(() => Mining(2));
taskB.Start();
Task task3 = new Task(() => Mining(3));
task3.Start();
}
public void Form2_Activated(object sender, EventArgs e) {
System.Diagnostics.Debug.WriteLine("Activated");
}
public void Form2_HandleCreated(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("HandleCreated");
}
public void Form2_VisibleChanged(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("VisibleChanged");
}
public void Form2_Shown(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("Shown");
}
private void button1_Click(object sender, EventArgs e)
{
startMine = false;
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if(startMine == true)
{
startMine = false;
e.Cancel = true;
Close();
}
}
}
}