Finished project 4 COM380
Signed-off-by: Amrit Panesar <apanesar-77260@student.coleman.edu>
This commit is contained in:
1 parent
39ee821f54
commit
a73a4190cb
7 files changed
+418
-140
No files matched your search
@@ -0,0 +1,213 @@
|
||||
#pragma once
|
||||
#include "stdafx.h"
|
||||
|
||||
using namespace System;
|
||||
using namespace System::Collections;
|
||||
using namespace System::Collections::Generic;
|
||||
using namespace System::Threading;
|
||||
using namespace System::Threading::Tasks;
|
||||
using namespace System::Data;
|
||||
|
||||
namespace Project4
|
||||
{
|
||||
|
||||
System::Void Form1::SetNum(int index, int number)
|
||||
{
|
||||
this->numbers[index] = number;
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
if (this->textBox6->InvokeRequired)
|
||||
{
|
||||
this->Invoke(sndelegate, gcnew array <Object^> { index, number } );
|
||||
}
|
||||
else
|
||||
{
|
||||
textBox6->Text = number.ToString("D2");
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (this->textBox5->InvokeRequired)
|
||||
{
|
||||
this->Invoke(sndelegate, gcnew array <Object^> { index, number });
|
||||
}
|
||||
else
|
||||
{
|
||||
textBox5->Text = number.ToString("D2");
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (this->textBox4->InvokeRequired)
|
||||
{
|
||||
this->Invoke(sndelegate, gcnew array <Object^> { index, number });
|
||||
}
|
||||
else
|
||||
{
|
||||
textBox4->Text = number.ToString("D2");
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (this->textBox3->InvokeRequired)
|
||||
{
|
||||
this->Invoke(sndelegate, gcnew array <Object^> { index, number });
|
||||
}
|
||||
else
|
||||
{
|
||||
textBox3->Text = number.ToString("D2");
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (this->textBox2->InvokeRequired)
|
||||
{
|
||||
this->Invoke(sndelegate, gcnew array <Object^> { index, number });
|
||||
}
|
||||
else
|
||||
{
|
||||
textBox2->Text = number.ToString("D2");
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if (this->textBox1->InvokeRequired)
|
||||
{
|
||||
this->Invoke(sndelegate, gcnew array <Object^> { index, number });
|
||||
}
|
||||
else
|
||||
{
|
||||
textBox1->Text = number.ToString("D2");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
System::Void Form1::Form1_Load(System::Object^ sender, System::EventArgs^ e)
|
||||
{
|
||||
sndelegate = gcnew SetNumDelegate(this, &Form1::SetNum);
|
||||
numbers = gcnew array < int > {0, 0, 0, 0, 0, 0};
|
||||
balls = gcnew List < LottoBall^ > ;
|
||||
radioButtons = gcnew List < RadioButton^ >;
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
balls->Add(gcnew LottoBall(1, 75, this, i));
|
||||
balls[i]->initThread();
|
||||
}
|
||||
|
||||
balls->Add(gcnew LottoBall(1, 15, this, 5));
|
||||
balls[balls->Count-1]->initThread();
|
||||
|
||||
radioButtons->Add(radioButton1);
|
||||
radioButtons->Add(radioButton2);
|
||||
radioButtons->Add(radioButton3);
|
||||
radioButtons->Add(radioButton4);
|
||||
radioButtons->Add(radioButton5);
|
||||
radioButtons->Add(radioButton6);
|
||||
|
||||
for (int i = 0; i < radioButtons->Count; i++)
|
||||
{
|
||||
radioButtons[i]->Checked = true;
|
||||
balls[i]->start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
System::Void Form1::exitToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
|
||||
{
|
||||
for (int i = 0; i < balls->Count; i++)
|
||||
{
|
||||
balls[i]->stop();
|
||||
}
|
||||
|
||||
Application::Exit();
|
||||
}
|
||||
|
||||
System::Void Form1::button1_Click(System::Object^ sender, System::EventArgs^ e)
|
||||
{
|
||||
bool isRunning = false;
|
||||
bool poolRun = false;
|
||||
for (int i = 0; i < balls->Count; i++)
|
||||
{
|
||||
if (balls[i]->isDisplaying())
|
||||
{
|
||||
isRunning = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isRunning)
|
||||
{
|
||||
for (int i = 0; i < balls->Count; i++)
|
||||
{
|
||||
balls[i]->stop();
|
||||
radioButtons[i]->Checked = false;
|
||||
}
|
||||
button1->Text = "Start";
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < balls->Count; i++)
|
||||
{
|
||||
balls[i]->start();
|
||||
radioButtons[i]->Checked = true;
|
||||
}
|
||||
button1->Text = "Stop";
|
||||
}
|
||||
}
|
||||
|
||||
System::Void Form1::Form1_FormClosing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e)
|
||||
{
|
||||
for (int i = 0; i < balls->Count; i++)
|
||||
{
|
||||
if (balls[i]->isRunning())
|
||||
{
|
||||
balls[i]->abort();
|
||||
e->Cancel = true;
|
||||
}
|
||||
}
|
||||
if (e->Cancel)
|
||||
{
|
||||
MessageBox::Show("Cleaning up threads, please wait", "Hang on a momement", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
|
||||
}
|
||||
}
|
||||
|
||||
System::Void Form1::radioButton1_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
|
||||
{
|
||||
RadioButton^ rb = safe_cast<RadioButton^>(sender);
|
||||
|
||||
String^ lastchar = rb->Name->Substring(rb->Name->Length - 1, 1);
|
||||
int out = -1;
|
||||
Int32::TryParse(lastchar, out);
|
||||
out = out - 1;
|
||||
if (out != -1)
|
||||
{
|
||||
if (!rb->Checked)
|
||||
{
|
||||
balls[out]->start();
|
||||
}
|
||||
else
|
||||
{
|
||||
balls[out]->stop();
|
||||
}
|
||||
}
|
||||
|
||||
bool isRunning = false;
|
||||
for (int i = 0; i < balls->Count; i++)
|
||||
{
|
||||
if (balls[i]->isDisplaying())
|
||||
{
|
||||
isRunning = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isRunning)
|
||||
{
|
||||
button1->Text = "Stop";
|
||||
}
|
||||
else
|
||||
{
|
||||
button1->Text = "Start";
|
||||
}
|
||||
|
||||
rb->Checked = !rb->Checked;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
#include "stdafx.h"
|
||||
#include "LottoBall.h"
|
||||
|
||||
namespace Project4
|
||||
{
|
||||
@@ -17,6 +16,8 @@ namespace Project4
|
||||
/// </summary>
|
||||
public ref class Form1 : public System::Windows::Forms::Form
|
||||
{
|
||||
delegate void SetNumDelegate(int index, int number);
|
||||
|
||||
public:
|
||||
Form1(void)
|
||||
{
|
||||
@@ -115,8 +116,10 @@ namespace Project4
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->fileToolStripMenuItem,
|
||||
this->helpToolStripMenuItem});
|
||||
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {
|
||||
this->fileToolStripMenuItem,
|
||||
this->helpToolStripMenuItem
|
||||
});
|
||||
this->menuStrip1->Location = System::Drawing::Point(0, 0);
|
||||
this->menuStrip1->Name = L"menuStrip1";
|
||||
this->menuStrip1->Size = System::Drawing::Size(669, 24);
|
||||
@@ -125,7 +128,7 @@ namespace Project4
|
||||
//
|
||||
// fileToolStripMenuItem
|
||||
//
|
||||
this->fileToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->exitToolStripMenuItem});
|
||||
this->fileToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) { this->exitToolStripMenuItem });
|
||||
this->fileToolStripMenuItem->Name = L"fileToolStripMenuItem";
|
||||
this->fileToolStripMenuItem->ShortcutKeys = static_cast<System::Windows::Forms::Keys>((System::Windows::Forms::Keys::Alt | System::Windows::Forms::Keys::F));
|
||||
this->fileToolStripMenuItem->Size = System::Drawing::Size(37, 20);
|
||||
@@ -141,7 +144,7 @@ namespace Project4
|
||||
//
|
||||
// helpToolStripMenuItem
|
||||
//
|
||||
this->helpToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->aboutToolStripMenuItem});
|
||||
this->helpToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) { this->aboutToolStripMenuItem });
|
||||
this->helpToolStripMenuItem->Name = L"helpToolStripMenuItem";
|
||||
this->helpToolStripMenuItem->ShortcutKeys = static_cast<System::Windows::Forms::Keys>((System::Windows::Forms::Keys::Alt | System::Windows::Forms::Keys::H));
|
||||
this->helpToolStripMenuItem->Size = System::Drawing::Size(44, 20);
|
||||
@@ -183,6 +186,7 @@ namespace Project4
|
||||
//
|
||||
// radioButton6
|
||||
//
|
||||
this->radioButton6->AutoCheck = false;
|
||||
this->radioButton6->AutoSize = true;
|
||||
this->radioButton6->Location = System::Drawing::Point(581, 86);
|
||||
this->radioButton6->Name = L"radioButton6";
|
||||
@@ -190,9 +194,11 @@ namespace Project4
|
||||
this->radioButton6->TabIndex = 13;
|
||||
this->radioButton6->TabStop = true;
|
||||
this->radioButton6->UseVisualStyleBackColor = true;
|
||||
this->radioButton6->Click += gcnew System::EventHandler(this, &Form1::radioButton1_CheckedChanged);
|
||||
//
|
||||
// radioButton5
|
||||
//
|
||||
this->radioButton5->AutoCheck = false;
|
||||
this->radioButton5->AutoSize = true;
|
||||
this->radioButton5->Location = System::Drawing::Point(475, 86);
|
||||
this->radioButton5->Name = L"radioButton5";
|
||||
@@ -200,9 +206,11 @@ namespace Project4
|
||||
this->radioButton5->TabIndex = 12;
|
||||
this->radioButton5->TabStop = true;
|
||||
this->radioButton5->UseVisualStyleBackColor = true;
|
||||
this->radioButton5->Click += gcnew System::EventHandler(this, &Form1::radioButton1_CheckedChanged);
|
||||
//
|
||||
// radioButton4
|
||||
//
|
||||
this->radioButton4->AutoCheck = false;
|
||||
this->radioButton4->AutoSize = true;
|
||||
this->radioButton4->Location = System::Drawing::Point(369, 86);
|
||||
this->radioButton4->Name = L"radioButton4";
|
||||
@@ -210,9 +218,11 @@ namespace Project4
|
||||
this->radioButton4->TabIndex = 11;
|
||||
this->radioButton4->TabStop = true;
|
||||
this->radioButton4->UseVisualStyleBackColor = true;
|
||||
this->radioButton4->Click += gcnew System::EventHandler(this, &Form1::radioButton1_CheckedChanged);
|
||||
//
|
||||
// radioButton3
|
||||
//
|
||||
this->radioButton3->AutoCheck = false;
|
||||
this->radioButton3->AutoSize = true;
|
||||
this->radioButton3->Location = System::Drawing::Point(263, 86);
|
||||
this->radioButton3->Name = L"radioButton3";
|
||||
@@ -220,9 +230,11 @@ namespace Project4
|
||||
this->radioButton3->TabIndex = 10;
|
||||
this->radioButton3->TabStop = true;
|
||||
this->radioButton3->UseVisualStyleBackColor = true;
|
||||
this->radioButton3->Click += gcnew System::EventHandler(this, &Form1::radioButton1_CheckedChanged);
|
||||
//
|
||||
// radioButton2
|
||||
//
|
||||
this->radioButton2->AutoCheck = false;
|
||||
this->radioButton2->AutoSize = true;
|
||||
this->radioButton2->Location = System::Drawing::Point(157, 86);
|
||||
this->radioButton2->Name = L"radioButton2";
|
||||
@@ -230,6 +242,7 @@ namespace Project4
|
||||
this->radioButton2->TabIndex = 9;
|
||||
this->radioButton2->TabStop = true;
|
||||
this->radioButton2->UseVisualStyleBackColor = true;
|
||||
this->radioButton2->Click += gcnew System::EventHandler(this, &Form1::radioButton1_CheckedChanged);
|
||||
//
|
||||
// radioButton1
|
||||
//
|
||||
@@ -241,6 +254,7 @@ namespace Project4
|
||||
this->radioButton1->TabIndex = 8;
|
||||
this->radioButton1->TabStop = true;
|
||||
this->radioButton1->UseVisualStyleBackColor = true;
|
||||
this->radioButton1->Click += gcnew System::EventHandler(this, &Form1::radioButton1_CheckedChanged);
|
||||
//
|
||||
// label6
|
||||
//
|
||||
@@ -298,7 +312,7 @@ namespace Project4
|
||||
//
|
||||
// textBox6
|
||||
//
|
||||
this->textBox6->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
|
||||
this->textBox6->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
|
||||
static_cast<System::Byte>(0)));
|
||||
this->textBox6->Location = System::Drawing::Point(40, 44);
|
||||
this->textBox6->Name = L"textBox6";
|
||||
@@ -310,73 +324,78 @@ namespace Project4
|
||||
//
|
||||
// textBox5
|
||||
//
|
||||
this->textBox5->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
|
||||
this->textBox5->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
|
||||
static_cast<System::Byte>(0)));
|
||||
this->textBox5->Location = System::Drawing::Point(146, 44);
|
||||
this->textBox5->Name = L"textBox5";
|
||||
this->textBox5->ReadOnly = true;
|
||||
this->textBox5->Size = System::Drawing::Size(34, 29);
|
||||
this->textBox5->TabIndex = 4;
|
||||
this->textBox5->TabStop = false;
|
||||
this->textBox5->Text = L"00";
|
||||
this->textBox5->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
|
||||
//
|
||||
// textBox4
|
||||
//
|
||||
this->textBox4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
|
||||
this->textBox4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
|
||||
static_cast<System::Byte>(0)));
|
||||
this->textBox4->Location = System::Drawing::Point(252, 44);
|
||||
this->textBox4->Name = L"textBox4";
|
||||
this->textBox4->ReadOnly = true;
|
||||
this->textBox4->Size = System::Drawing::Size(34, 29);
|
||||
this->textBox4->TabIndex = 3;
|
||||
this->textBox4->TabStop = false;
|
||||
this->textBox4->Text = L"00";
|
||||
this->textBox4->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
|
||||
//
|
||||
// textBox3
|
||||
//
|
||||
this->textBox3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
|
||||
this->textBox3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
|
||||
static_cast<System::Byte>(0)));
|
||||
this->textBox3->Location = System::Drawing::Point(358, 44);
|
||||
this->textBox3->Name = L"textBox3";
|
||||
this->textBox3->ReadOnly = true;
|
||||
this->textBox3->Size = System::Drawing::Size(34, 29);
|
||||
this->textBox3->TabIndex = 2;
|
||||
this->textBox3->TabStop = false;
|
||||
this->textBox3->Text = L"00";
|
||||
this->textBox3->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
|
||||
//
|
||||
// textBox2
|
||||
//
|
||||
this->textBox2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
|
||||
this->textBox2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
|
||||
static_cast<System::Byte>(0)));
|
||||
this->textBox2->Location = System::Drawing::Point(464, 44);
|
||||
this->textBox2->Name = L"textBox2";
|
||||
this->textBox2->ReadOnly = true;
|
||||
this->textBox2->Size = System::Drawing::Size(34, 29);
|
||||
this->textBox2->TabIndex = 1;
|
||||
this->textBox2->TabStop = false;
|
||||
this->textBox2->Text = L"00";
|
||||
this->textBox2->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
|
||||
//
|
||||
// textBox1
|
||||
//
|
||||
this->textBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
|
||||
this->textBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
|
||||
static_cast<System::Byte>(0)));
|
||||
this->textBox1->Location = System::Drawing::Point(570, 44);
|
||||
this->textBox1->Name = L"textBox1";
|
||||
this->textBox1->ReadOnly = true;
|
||||
this->textBox1->Size = System::Drawing::Size(34, 29);
|
||||
this->textBox1->TabIndex = 0;
|
||||
this->textBox1->TabStop = false;
|
||||
this->textBox1->Text = L"00";
|
||||
this->textBox1->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
|
||||
this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
|
||||
static_cast<System::Byte>(0)));
|
||||
this->button1->Location = System::Drawing::Point(297, 187);
|
||||
this->button1->Name = L"button1";
|
||||
this->button1->Size = System::Drawing::Size(74, 50);
|
||||
this->button1->TabIndex = 2;
|
||||
this->button1->Text = L"Start";
|
||||
this->button1->Text = L"Stop";
|
||||
this->button1->UseVisualStyleBackColor = true;
|
||||
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
|
||||
//
|
||||
@@ -391,6 +410,7 @@ namespace Project4
|
||||
this->MainMenuStrip = this->menuStrip1;
|
||||
this->Name = L"Form1";
|
||||
this->Text = L"Lotto Ball Picker";
|
||||
this->FormClosing += gcnew System::Windows::Forms::FormClosingEventHandler(this, &Form1::Form1_FormClosing);
|
||||
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
|
||||
this->menuStrip1->ResumeLayout(false);
|
||||
this->menuStrip1->PerformLayout();
|
||||
@@ -404,65 +424,21 @@ namespace Project4
|
||||
|
||||
public: List<LottoBall^>^ balls;
|
||||
public: static array<int>^ numbers;
|
||||
public: System::Void affixNumber(int index, int number)
|
||||
{
|
||||
this->numbers[index] = number;
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
textBox5->Text = number.ToString("D2");
|
||||
break;
|
||||
case 1:
|
||||
textBox4->Text = number.ToString("D2");
|
||||
break;
|
||||
case 2:
|
||||
textBox4->Text = number.ToString("D2");
|
||||
break;
|
||||
case 3:
|
||||
textBox3->Text = number.ToString("D2");
|
||||
break;
|
||||
case 4:
|
||||
textBox2->Text = number.ToString("D2");
|
||||
break;
|
||||
case 5:
|
||||
textBox1->Text = number.ToString("D2");
|
||||
break;
|
||||
case 6:
|
||||
textBox6->Text = number.ToString("D2");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
|
||||
{
|
||||
this->numbers = gcnew array<int> {0, 0, 0, 0, 0, 0};
|
||||
balls = gcnew List<LottoBall^>;
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
balls->Add(gcnew LottoBall(1, 75, this));
|
||||
}
|
||||
private: bool isClosing = false;
|
||||
private: List<RadioButton^>^ radioButtons;
|
||||
|
||||
balls->Add(gcnew LottoBall(1, 15, this));
|
||||
}
|
||||
public: System::Void SetNum(int index, int number);
|
||||
|
||||
private: System::Void exitToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
|
||||
{
|
||||
for (int i = 0; i < balls->Count; i++)
|
||||
{
|
||||
balls[i]->stop();
|
||||
}
|
||||
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e);
|
||||
private: System::Void exitToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e);
|
||||
|
||||
Application::Exit();
|
||||
}
|
||||
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e);
|
||||
private: SetNumDelegate^ sndelegate;
|
||||
|
||||
private: System::Void Form1_FormClosing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e);
|
||||
private: System::Void radioButton1_CheckedChanged(System::Object^ sender, System::EventArgs^ e);
|
||||
|
||||
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
|
||||
{
|
||||
for (int i = 0; i < balls->Count; i++)
|
||||
{
|
||||
balls[i]->start();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "stdafx.h"
|
||||
#include "Form1.h"
|
||||
|
||||
using namespace System;
|
||||
using namespace System::Collections;
|
||||
@@ -7,34 +7,44 @@ using namespace System::Collections::Generic;
|
||||
using namespace System::Threading;
|
||||
using namespace System::Threading::Tasks;
|
||||
using namespace System::Data;
|
||||
using namespace Project4;
|
||||
|
||||
|
||||
public ref class LottoBall
|
||||
namespace Project4
|
||||
{
|
||||
ref class Form1;
|
||||
|
||||
public:
|
||||
LottoBall(int minval, int maxval, Form1^ form1);
|
||||
~LottoBall();
|
||||
public ref class LottoBall
|
||||
{
|
||||
|
||||
int getCurrentValue();
|
||||
int num;
|
||||
public:
|
||||
LottoBall(int minval, int maxval, Form1^ form1, int num1);
|
||||
~LottoBall();
|
||||
|
||||
System::Void start();
|
||||
System::Void stop();
|
||||
System::Void initThread();
|
||||
int getCurrentValue();
|
||||
int num;
|
||||
|
||||
private:
|
||||
int minVal;
|
||||
int maxVal;
|
||||
int seedValue;
|
||||
System::Void start();
|
||||
System::Void stop();
|
||||
System::Void abort();
|
||||
|
||||
Form1^ formptr;
|
||||
System::Void initThread();
|
||||
System::Boolean isRunning();
|
||||
System::Boolean isDisplaying();
|
||||
System::Boolean getPoolRun();
|
||||
|
||||
Random^ r;
|
||||
private:
|
||||
int minVal;
|
||||
int maxVal;
|
||||
int seedValue;
|
||||
bool poolRun;
|
||||
bool threadAbort;
|
||||
bool threadStop;
|
||||
Form1^ formptr;
|
||||
|
||||
bool threadStop;
|
||||
Thread^ thread;
|
||||
System::Void run();
|
||||
Random^ r;
|
||||
|
||||
};
|
||||
Thread^ thread;
|
||||
System::Void run();
|
||||
System::Boolean isUnique(int num);
|
||||
|
||||
};
|
||||
}
|
||||
@@ -1,59 +1,127 @@
|
||||
#pragma once
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "LottoBall.h"
|
||||
|
||||
LottoBall::LottoBall(int minval, int maxval, Form1^ form1)
|
||||
namespace Project4
|
||||
{
|
||||
minVal = minval;
|
||||
maxVal = maxval;
|
||||
|
||||
threadStop = false;
|
||||
num = 0;
|
||||
|
||||
formptr = form1;
|
||||
}
|
||||
|
||||
LottoBall::~LottoBall()
|
||||
{
|
||||
thread->Abort();
|
||||
}
|
||||
|
||||
System::Void LottoBall::initThread()
|
||||
{
|
||||
r = gcnew Random();
|
||||
long long seed = 0;
|
||||
for(int i = 0; i < 100; ++i)
|
||||
LottoBall::LottoBall(int minval, int maxval, Form1^ form1, int num1)
|
||||
{
|
||||
seed += r->Next(i, 9999 + i);
|
||||
minVal = minval;
|
||||
maxVal = maxval;
|
||||
|
||||
threadStop = false;
|
||||
poolRun = false;
|
||||
threadAbort = false;
|
||||
|
||||
num = num1;
|
||||
|
||||
formptr = form1;
|
||||
}
|
||||
r = gcnew Random(seed);
|
||||
thread = gcnew Thread(gcnew ThreadStart(&this->run));
|
||||
}
|
||||
|
||||
System::Void LottoBall::run()
|
||||
{
|
||||
String^ threadname = Thread::CurrentThread->Name;
|
||||
int id = 0;
|
||||
Int32::TryParse(threadname, id);
|
||||
|
||||
while (!this->threadStop)
|
||||
LottoBall::~LottoBall()
|
||||
{
|
||||
this->num = r->Next(minVal, maxVal);
|
||||
formptr->affixNumber(id, this->num);
|
||||
thread->Abort();
|
||||
}
|
||||
}
|
||||
|
||||
int LottoBall::getCurrentValue()
|
||||
{
|
||||
return this->num;
|
||||
}
|
||||
System::Void LottoBall::initThread()
|
||||
{
|
||||
r = gcnew Random();
|
||||
long long seed = 0;
|
||||
int min = r->Next(0, 1000);
|
||||
int max = r->Next(0, 1000);
|
||||
|
||||
System::Void LottoBall::start()
|
||||
{
|
||||
this->threadStop = false;
|
||||
thread->Start();
|
||||
}
|
||||
if (min > max)
|
||||
{
|
||||
int hold = max;
|
||||
max = min;
|
||||
min = hold;
|
||||
}
|
||||
|
||||
for (int i = min; i < max; i++)
|
||||
{
|
||||
seed += r->Next(min, max);
|
||||
if (seed % 500 > 250)
|
||||
{
|
||||
seed += r->Next(min, max) + num;
|
||||
}
|
||||
}
|
||||
|
||||
r = gcnew Random(seed);
|
||||
thread = gcnew Thread(gcnew ThreadStart(this, &LottoBall::run));
|
||||
thread->Name = num.ToString();
|
||||
}
|
||||
|
||||
System::Boolean LottoBall::isUnique(int num)
|
||||
{
|
||||
for (int i = 0; i < Form1::numbers->Length; i++)
|
||||
{
|
||||
if (num == Form1::numbers[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
System::Void LottoBall::run()
|
||||
{
|
||||
String^ threadname = Thread::CurrentThread->Name;
|
||||
int id = 0;
|
||||
Int32::TryParse(threadname, id);
|
||||
|
||||
while (!threadAbort)
|
||||
{
|
||||
this->num = r->Next(1, 199999) % maxVal + 1;
|
||||
if (!threadStop)
|
||||
{
|
||||
if (this->isUnique(this->num))
|
||||
{
|
||||
Form1::numbers[id] = num;
|
||||
formptr->SetNum(id, this->num);
|
||||
}
|
||||
}
|
||||
Thread::Sleep(r->Next(0, 10));
|
||||
}
|
||||
}
|
||||
|
||||
int LottoBall::getCurrentValue()
|
||||
{
|
||||
return this->num;
|
||||
}
|
||||
|
||||
System::Void LottoBall::start()
|
||||
{
|
||||
this->threadStop = false;
|
||||
if (!poolRun)
|
||||
{
|
||||
thread->Start();
|
||||
poolRun = true;
|
||||
}
|
||||
}
|
||||
|
||||
System::Void LottoBall::stop()
|
||||
{
|
||||
this->threadStop = true;
|
||||
}
|
||||
|
||||
System::Boolean LottoBall::isDisplaying()
|
||||
{
|
||||
return !this->threadStop;
|
||||
}
|
||||
|
||||
System::Boolean LottoBall::isRunning()
|
||||
{
|
||||
return !this->threadAbort;
|
||||
}
|
||||
|
||||
System::Boolean LottoBall::getPoolRun()
|
||||
{
|
||||
return this->poolRun;
|
||||
}
|
||||
|
||||
System::Void LottoBall::abort()
|
||||
{
|
||||
this->threadAbort = true;
|
||||
}
|
||||
|
||||
System::Void LottoBall::stop()
|
||||
{
|
||||
this->threadStop = true;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
@@ -12,7 +12,7 @@
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{95420C8C-DDE8-4C10-AB3C-E6593D36DE8A}</ProjectGuid>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<Keyword>ManagedCProj</Keyword>
|
||||
<RootNamespace>Project4</RootNamespace>
|
||||
</PropertyGroup>
|
||||
@@ -20,14 +20,14 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CLRSupport>Pure</CLRSupport>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CLRSupport>Pure</CLRSupport>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
@@ -86,6 +86,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="AssemblyInfo.cpp" />
|
||||
<ClCompile Include="Form1.cpp" />
|
||||
<ClCompile Include="LottoBallcpp.cpp" />
|
||||
<ClCompile Include="Project4.cpp" />
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
|
||||
@@ -30,6 +30,9 @@
|
||||
<ClCompile Include="LottoBallcpp.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Form1.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Form1.h">
|
||||
@@ -55,4 +58,9 @@
|
||||
<Filter>Resource Files</Filter>
|
||||
</Image>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Form1.resX">
|
||||
<Filter>Resource Files</Filter>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -4,3 +4,5 @@
|
||||
#pragma once
|
||||
|
||||
// TODO: reference additional headers your program requires here
|
||||
#include "LottoBall.h"
|
||||
#include "Form1.h"
|
||||
Reference in new issue
Block a user