niedziela, 28 maja 2017

The Game of LIFE (Visual C++)



#pragma endregion
private:
System::Void init_Random()
{
srand(time(NULL));
}
private:
array<System::Int64,2>^ game_table;
private:
System::Void init_Table()
{
game_table=gcnew array<System::Int64,2>(30,30);
System::Int64 i;
System::Int64 j;
for(i=0;i<30;i++)
for(j=0;j<30;j++)
game_table[i,j]=0;

}
private:
System::Void change_Table()
{
System::Int64 i;
System::Int64 j;
System::Int64 k;
for(i=0;i<30;i++)
{
for(j=0;j<30;j++)
{
k=rand()%10;
if(k>6)
game_table[i,j]=1;
}
}
}
 private:
System::Boolean in_Area(System::Int64 x, System::Int64 y)
{
if((x>=0) && (x<30) && (y>=0) && (y<30))
return true;
else
return false;
}
private:
System::Void step_GridView()
{
            System::Int64 i;
System::Int64 j;
for(i=0;i<30;i++)
{
for(j=0;j<30;j++)
{
if(game_table[i,j]==0)
dataGridView1->Rows[i]->Cells[j]->Style->BackColor=System::Drawing::Color::Yellow;
else
dataGridView1->Rows[i]->Cells[j]->Style->BackColor=System::Drawing::Color::Black;

}
}
}
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
init_Random();
init_Table();
change_Table();
System::Int64 i;
    System::Int64 j;
 
dataGridView1->ColumnCount=30;
dataGridView1->RowCount=30;
dataGridView1->AutoSizeColumnsMode=DataGridViewAutoSizeColumnsMode::Fill;
dataGridView1->ColumnHeadersVisible=false;
dataGridView1->RowHeadersVisible=false;
dataGridView1->AllowUserToResizeRows=false;
dataGridView1->AllowUserToResizeColumns=false;
for(i=0;i<30;i++)
{
for(j=0;j<30;j++)
{
if(game_table[i,j]==0)
dataGridView1->Rows[i]->Cells[j]->Style->BackColor=System::Drawing::Color::Yellow;
else
dataGridView1->Rows[i]->Cells[j]->Style->BackColor=System::Drawing::Color::Black;

}
}

}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
System::Int64 i;
    System::Int64 j;
System::Int64 k;
System::Int64 l;
System::Int64 value;
value=0;
for(i=0;i<30;i++)
{
for(j=0;j<30;j++)
{
for(k=i-1;k<i+2;k++)
{
                           for(l=j-1;l<j+2;l++)
  {
  if(in_Area(k,l))
  {
  if(game_table[k,l]==0)
  if(!((l==j)&&(k==i)))
  value++;
  }
  }
}
game_table[i,j]=1;
if(value==3)
game_table[i,j]=0;
if((value==2) && (dataGridView1->Rows[i]->Cells[j]->Style->BackColor==System::Drawing::Color::Yellow))
game_table[i,j]=0;
value=0;

}
}
              step_GridView();

}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
};
}


środa, 3 maja 2017

Sending files via FTP to the server (Visual C++)

I want to check my Windows files and information to send to the company server.




I need includes:

using namespace System::IO;
using namespace System::Net;

And code:



#pragma endregion
array<String^>^ files_Windows;
String^ address_ftp;
Uri^ send_address;
array<Byte>^ table;
String^ path;
int size;
Stream^ f_stream;
FtpWebRequest ^send_FTP;
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
int i;
address_ftp="ftp.company.com";
table=gcnew array<Byte>(2048);
path="info.txt";

files_Windows=Directory::GetFiles("c:\\Windows","*.*",System::IO::SearchOption::TopDirectoryOnly);
size=files_Windows->Length;
for(i=0;i<size;i++)
listBox1->Items->Add("( "+files_Windows[i]+" )");
 

;
}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
 
StreamWriter^ my_Stream=gcnew StreamWriter(path);
int i,length_bytes;
for(i=0;i<size;i++)
my_Stream->WriteLine(files_Windows[i]);
send_address=gcnew Uri("ftp://"+address_ftp);
send_FTP=dynamic_cast<FtpWebRequest^>(WebRequest::Create(send_address));
send_FTP->Credentials=gcnew NetworkCredential("employee_name","employee@company.com");
send_FTP->Method+WebRequestMethods::Ftp::UploadFile;
FileStream^ use_file=gcnew FileStream(path,FileMode::Open);
f_stream=send_FTP->GetRequestStream();
do
{
length_bytes=use_file->Read(table,0,2048);
f_stream->Write(table,0,length_bytes);
}while(length_bytes!=0);
f_stream->Close();

}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
};
}



poniedziałek, 1 maja 2017

Cuboid (Visual C++)




#pragma endregion
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
Graphics^ g=panel1->CreateGraphics();
Pen^ pen1=gcnew Pen(System::Drawing::Color::Brown);
Pen^ pen2=gcnew Pen(System::Drawing::Color::Green);
Pen^ pen3=gcnew Pen(System::Drawing::Color::Blue);
Pen^ pen4=gcnew Pen(System::Drawing::Color::Black);
pen1->Width=3;
pen2->Width=3;
pen3->Width=3;
pen4->Width=4;
pen4->DashStyle=System::Drawing::Drawing2D::DashStyle::Dot;
int width,height,centr_x,centr_y,down_margin,down_margin2,line1=400,A,B,C,D,A1,B1,C1,D1;
width=panel1->Width;
height=panel1->Height;
down_margin=height-5;
centr_x=width/2;
centr_y=height/2;
A=centr_x-(line1/2);
B=centr_x+(line1/2);
g->DrawLine(pen1,A,down_margin,B,down_margin);
C=A+150;
D=B+150;
down_margin2=down_margin-150;
g->DrawLine(pen1,C,down_margin2,D,down_margin2);
g->DrawLine(pen1,A,down_margin,C,down_margin2);
g->DrawLine(pen1,B,down_margin,D,down_margin2);
g->DrawLine(pen4,A,down_margin,D,down_margin2);
A1=down_margin-400;
B1=down_margin-400;
C1=down_margin2-400;
D1=down_margin2-400;
g->DrawLine(pen2,A,down_margin,A,A1);
g->DrawLine(pen2,B,down_margin,B,B1);
g->DrawLine(pen2,C,down_margin2,C,C1);
g->DrawLine(pen2,D,down_margin2,D,D1);
g->DrawLine(pen4,D,down_margin2,C,C1);
g->DrawLine(pen4,C,C1,A,down_margin);
g->DrawLine(pen3,A,A1,B,B1);
g->DrawLine(pen3,C,C1,D,D1);
g->DrawLine(pen3,A,A1,C,C1);
g->DrawLine(pen3,B,B1,D,D1);
 
 


}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
};
}