-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
535 lines (455 loc) · 18.7 KB
/
MainWindow.xaml.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace THCardDealer
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private int currentStage = 0; //0=pre flop, 1=flop, 2=turn, 3=river
private List<string> fullDeck = new List<string>() { "1H", "1C", "1S", "1D", "2H", "2C", "2S", "2D", "3H", "3C", "3S", "3D", "4H", "4C", "4S", "4D", "5H", "5C", "5S", "5D", "6H", "6C", "6S", "6D", "7H", "7C", "7S", "7D", "8H", "8C", "8S", "8D", "9H", "9C", "9S", "9D", "10H", "10C", "10S", "10D", "11H", "11C", "11S", "11D", "12H", "12C", "12S", "12D", "13H", "13C", "13S", "13D", };
private List<string> currentDeck = null;
private List<string> CommunityCards = null;
Random rand = new Random();
public MainWindow()
{
InitializeComponent();
}
private void Window_ContentRendered(object sender, EventArgs e)
{
ReadFromFile();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
SaveToFile();
}
private void ReadFromFile()
{
System.Net.WebClient wc = new System.Net.WebClient();
//string webData = wc.DownloadString("http://www.yoursite.com/resource/file.htm");
if (File.Exists("params.txt"))
{
string txtParams = File.ReadAllText("params.txt");
List<string> str = txtParams.Split('~').ToList<string>();
currentDeck = new List<string>();
foreach (var item in str[0].Split(','))
if (item != "")
currentDeck.Add(item);
CommunityCards = new List<string>();
foreach (var item in str[1].Split(','))
{
if (item != "")
CommunityCards.Add(item);
}
currentStage = Convert.ToInt32(str[2]);
handNumber.Text = str[3];
lblCardsLeft.Content = "Cards In Deck : " + (currentDeck == null || currentDeck.Count == 0 ? "52" : currentDeck.Count.ToString());
try
{
SmallBlind.Text = str[4];
BigBlind.Text = str[5];
Email.Text = str[6];
Password.Password = str[7];
Email1.Text = str[8];
Email2.Text = str[9];
Email3.Text = str[10];
Email4.Text = str[11];
Email5.Text = str[12];
Email6.Text = str[13];
Email7.Text = str[14];
Email8.Text = str[15];
Email9.Text = str[16];
}
catch (Exception)
{
}
btnDeal.Content = SetButtonText();
}
}
private void SaveToFile()
{
StringBuilder sb = new StringBuilder();
if (currentDeck != null && currentDeck.Count > 0)
{
foreach (var item in currentDeck)
sb.Append(item + ",");
sb.Remove(sb.Length - 1, 1);
}
sb.Append('~');
if (CommunityCards != null)
{
foreach (var item in CommunityCards)
sb.Append(item + ",");
if (CommunityCards.Count > 0)
sb.Remove(sb.Length - 1, 1);
}
sb.Append('~');
sb.Append(currentStage);
sb.Append('~');
sb.Append(handNumber.Text);
sb.Append('~');
sb.Append(SmallBlind.Text);
sb.Append('~');
sb.Append(BigBlind.Text);
sb.Append('~');
sb.Append(Email.Text);
sb.Append('~');
sb.Append(Password.Password);
sb.Append('~');
sb.Append(Email1.Text);
sb.Append('~');
sb.Append(Email2.Text);
sb.Append('~');
sb.Append(Email3.Text);
sb.Append('~');
sb.Append(Email4.Text);
sb.Append('~');
sb.Append(Email5.Text);
sb.Append('~');
sb.Append(Email6.Text);
sb.Append('~');
sb.Append(Email7.Text);
sb.Append('~');
sb.Append(Email8.Text);
sb.Append('~');
sb.Append(Email9.Text);
sb.Append('~');
File.WriteAllText("params.txt", sb.ToString());
}
private void btnDeal_Click(object sender, RoutedEventArgs e)
{
if (handNumber.Text == "")
{
MessageBox.Show("Please enter hand number");
return;
}
if (Email.Text == "" || Email.Text == "Email address")
{
MessageBox.Show("Please enter Email");
return;
}
if (Password.Password == "")
{
MessageBox.Show("Please enter Password");
return;
}
if (SmallBlind.Text == "")
{
MessageBox.Show("Please enter Small blind");
return;
}
if (BigBlind.Text == "")
{
MessageBox.Show("Please enter Big blind");
return;
}
lblSending.Visibility = System.Windows.Visibility.Visible;
System.Windows.Forms.Application.DoEvents();
switch (currentStage)
{
case 0:
//Testing :
//for (int i = 0; i < 26; i++)
//{
if (DealCards())
currentStage++;
//}
break;
case 1:
if (Flop())
currentStage++;
break;
case 2:
if (Turn())
currentStage++;
break;
case 3:
if (River())
{
Reset();
handNumber.Text = ((Convert.ToInt32(handNumber.Text)) + 1).ToString();
}
break;
}
btnDeal.Content = SetButtonText();
lblSending.Visibility = System.Windows.Visibility.Hidden;
lblCardsLeft.Content = "Cards In Deck : " + (currentDeck == null || currentDeck.Count == 0 ? "52" : currentDeck.Count.ToString());
SaveToFile();
}
private string SetButtonText()
{
switch (currentStage)
{
case 1:
return "Flop!";
case 2:
return "Turn!";
case 3:
return "River!";
case 0:
return "Deal!";
}
return "";
}
private bool DealCards()
{
currentDeck = new List<string>();
foreach (string card in fullDeck)
currentDeck.Add(card);
CommunityCards = new List<string>();
string err = "";
try { DealPlayer(Email1.Text); }
catch { err += Email1.Text + ", "; }
try { DealPlayer(Email2.Text); }
catch { err += Email2.Text + ", "; }
try { DealPlayer(Email3.Text); }
catch { err += Email3.Text + ", "; }
try { DealPlayer(Email4.Text); }
catch { err += Email4.Text + ", "; }
try { DealPlayer(Email5.Text); }
catch { err += Email5.Text + ", "; }
try { DealPlayer(Email6.Text); }
catch { err += Email6.Text + ", "; }
try { DealPlayer(Email7.Text); }
catch { err += Email7.Text + ", "; }
try { DealPlayer(Email8.Text); }
catch { err += Email8.Text + ", "; }
try { DealPlayer(Email9.Text); }
catch { err += Email9.Text + ", "; }
if (err != "")
{
err = "Emails weren't sent to - " + err;
MessageBox.Show(err);
}
return true;
}
private void DealPlayer(string to)
{
if (to == "") return;
string subject = "Invitational Tournament Hand #" + handNumber.Text;
int rnd = rand.Next(currentDeck.Count);
string card1 = currentDeck[rnd];
currentDeck.RemoveAt(rnd);
rnd = rand.Next(currentDeck.Count);
string card2 = currentDeck[rnd];
currentDeck.RemoveAt(rnd);
SendEmail(to, subject, card1, card2);
}
private bool Flop()
{
int rnd1 = rand.Next(currentDeck.Count);
CommunityCards.Add(currentDeck[rnd1]);
currentDeck.RemoveAt(rnd1);
int rnd2 = rand.Next(currentDeck.Count);
CommunityCards.Add(currentDeck[rnd2]);
currentDeck.RemoveAt(rnd2);
int rnd3 = rand.Next(currentDeck.Count);
CommunityCards.Add(currentDeck[rnd3]);
currentDeck.RemoveAt(rnd3);
string subject = "Flop for hand #" + handNumber.Text;
string err = "";
try { SendCommunityCard(Email1.Text, subject); }
catch { err += Email1.Text + ", "; }
try { SendCommunityCard(Email2.Text, subject); }
catch { err += Email2.Text + ", "; }
try { SendCommunityCard(Email3.Text, subject); }
catch { err += Email3.Text + ", "; }
try { SendCommunityCard(Email4.Text, subject); }
catch { err += Email4.Text + ", "; }
try { SendCommunityCard(Email5.Text, subject); }
catch { err += Email5.Text + ", "; }
try { SendCommunityCard(Email6.Text, subject); }
catch { err += Email6.Text + ", "; }
try { SendCommunityCard(Email7.Text, subject); }
catch { err += Email7.Text + ", "; }
try { SendCommunityCard(Email8.Text, subject); }
catch { err += Email8.Text + ", "; }
try { SendCommunityCard(Email9.Text, subject); }
catch { err += Email9.Text + ", "; }
if (err != "")
{
err = "Emails weren't sent to - " + err;
MessageBox.Show(err);
}
return true;
}
private bool Turn()
{
int rnd = rand.Next(currentDeck.Count);
CommunityCards.Add(currentDeck[rnd]);
currentDeck.RemoveAt(rnd);
string subject = "Turn for hand #" + handNumber.Text;
string err = "";
try { SendCommunityCard(Email1.Text, subject); }
catch { err += Email1.Text + ", "; }
try { SendCommunityCard(Email2.Text, subject); }
catch { err += Email2.Text + ", "; }
try { SendCommunityCard(Email3.Text, subject); }
catch { err += Email3.Text + ", "; }
try { SendCommunityCard(Email4.Text, subject); }
catch { err += Email4.Text + ", "; }
try { SendCommunityCard(Email5.Text, subject); }
catch { err += Email5.Text + ", "; }
try { SendCommunityCard(Email6.Text, subject); }
catch { err += Email6.Text + ", "; }
try { SendCommunityCard(Email7.Text, subject); }
catch { err += Email7.Text + ", "; }
try { SendCommunityCard(Email8.Text, subject); }
catch { err += Email8.Text + ", "; }
try { SendCommunityCard(Email9.Text, subject); }
catch { err += Email9.Text + ", "; }
if (err != "")
{
err = "Emails weren't sent to - " + err;
MessageBox.Show(err);
}
return true;
}
private bool River()
{
int rnd = rand.Next(currentDeck.Count);
CommunityCards.Add(currentDeck[rnd]);
currentDeck.RemoveAt(rnd);
string subject = "River for hand #" + handNumber.Text;
string err = "";
try { SendCommunityCard(Email1.Text, subject); }
catch { err += Email1.Text + ", "; }
try { SendCommunityCard(Email2.Text, subject); }
catch { err += Email2.Text + ", "; }
try { SendCommunityCard(Email3.Text, subject); }
catch { err += Email3.Text + ", "; }
try { SendCommunityCard(Email4.Text, subject); }
catch { err += Email4.Text + ", "; }
try { SendCommunityCard(Email5.Text, subject); }
catch { err += Email5.Text + ", "; }
try { SendCommunityCard(Email6.Text, subject); }
catch { err += Email6.Text + ", "; }
try { SendCommunityCard(Email7.Text, subject); }
catch { err += Email7.Text + ", "; }
try { SendCommunityCard(Email8.Text, subject); }
catch { err += Email8.Text + ", "; }
try { SendCommunityCard(Email9.Text, subject); }
catch { err += Email9.Text + ", "; }
if (err != "")
{
err = "Emails weren't sent to - " + err;
MessageBox.Show(err);
}
return true;
}
private void SendCommunityCard(string to, string subject)
{
if (to == "") return;
using (var client = new SmtpClient("smtp.gmail.com", 587))
{
client.Credentials = new System.Net.NetworkCredential(Email.Text, Password.Password);
client.EnableSsl = true;
MailMessage newMail = new MailMessage();
newMail.To.Add(new MailAddress(to));
newMail.Subject = subject;
newMail.IsBodyHtml = true;
newMail.From = new MailAddress(Email.Text);
var inlineImg1 = new LinkedResource("Cards\\" + CommunityCards[0] + ".jpg");
inlineImg1.ContentId = Guid.NewGuid().ToString();
var inlineImg2 = new LinkedResource("Cards\\" + CommunityCards[1] + ".jpg");
inlineImg2.ContentId = Guid.NewGuid().ToString();
var inlineImg3 = new LinkedResource("Cards\\" + CommunityCards[2] + ".jpg");
inlineImg3.ContentId = Guid.NewGuid().ToString();
string body = string.Format(@"
<img height=""100"" src=""cid:{0}"" />
<img height=""100"" src=""cid:{1}"" />
<img height=""100"" src=""cid:{2}"" />
", inlineImg1.ContentId, inlineImg2.ContentId, inlineImg3.ContentId);
LinkedResource inlineImg4 = null;
if (currentStage == 2 || currentStage == 3)
{
inlineImg4 = new LinkedResource("Cards\\" + CommunityCards[3] + ".jpg");
inlineImg4.ContentId = Guid.NewGuid().ToString();
body += string.Format(@"
<img height=""100"" src=""cid:{0}"" />
", inlineImg4.ContentId);
}
LinkedResource inlineImg5 = null;
if (currentStage == 3)
{
inlineImg5 = new LinkedResource("Cards\\" + CommunityCards[4] + ".jpg");
inlineImg5.ContentId = Guid.NewGuid().ToString();
body += string.Format(@"
<img height=""100"" src=""cid:{0}"" />
", inlineImg5.ContentId);
}
AlternateView view = AlternateView.CreateAlternateViewFromString(body, null, "text/html");
view.LinkedResources.Add(inlineImg1);
view.LinkedResources.Add(inlineImg2);
view.LinkedResources.Add(inlineImg3);
if (currentStage == 2 || currentStage == 3)
view.LinkedResources.Add(inlineImg4);
if (currentStage == 3)
view.LinkedResources.Add(inlineImg5);
newMail.AlternateViews.Add(view);
client.Send(newMail);
}
}
private void SendEmail(string to, string subject, string card1, string card2)
{
using (var client = new SmtpClient("smtp.gmail.com", 587))
{
client.Credentials = new System.Net.NetworkCredential(Email.Text, Password.Password);
client.EnableSsl = true;
MailMessage newMail = new MailMessage();
newMail.To.Add(new MailAddress(to));
newMail.Subject = subject;
newMail.IsBodyHtml = true;
newMail.From = new MailAddress(Email.Text);
var inlineImg1 = new LinkedResource("Cards\\" + card1 + ".jpg");
inlineImg1.ContentId = Guid.NewGuid().ToString();
var inlineImg2 = new LinkedResource("Cards\\" + card2 + ".jpg");
inlineImg2.ContentId = Guid.NewGuid().ToString();
string body = string.Format(@"
<p>Blinds: " + SmallBlind.Text + " / " + BigBlind.Text + @"</p>
<p>Your cards for hand #" + handNumber.Text + @":</p>
<img height=""100"" src=""cid:{0}"" />
<img height=""100"" src=""cid:{1}"" />
", inlineImg1.ContentId, inlineImg2.ContentId);
var view = AlternateView.CreateAlternateViewFromString(body, null, "text/html");
view.LinkedResources.Add(inlineImg1);
view.LinkedResources.Add(inlineImg2);
newMail.AlternateViews.Add(view);
client.Send(newMail);
}
}
private void btnReset_Click(object sender, RoutedEventArgs e)
{
Reset();
}
private void Reset()
{
currentDeck = null;
currentStage = 0;
CommunityCards = null;
lblCardsLeft.Content = "Cards In Deck : " + (currentDeck == null || currentDeck.Count == 0 ? "52" : currentDeck.Count.ToString());
btnDeal.Content = SetButtonText();
SaveToFile();
}
private void Email_GotFocus(object sender, RoutedEventArgs e)
{
if (Email.Text == "Email address")
Email.Text = "";
}
}
}