#pragma once


namespace hanoi2 {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::MenuStrip^  menuStrip1;
	protected: 
	private: System::Windows::Forms::ToolStripMenuItem^  plikToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  startToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  wyjscieToolStripMenuItem;

	private: System::Windows::Forms::ToolStripMenuItem^  opcjeToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  krazki3ToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  krazki5ToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  krazki7ToolStripMenuItem;




	private: System::Windows::Forms::Panel^  panel1;
	private: System::Windows::Forms::Panel^  panel2;
	private: System::Windows::Forms::Panel^  panel3;




	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
			this->plikToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->startToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->wyjscieToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->opcjeToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->krazki3ToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->krazki5ToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->krazki7ToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->panel1 = (gcnew System::Windows::Forms::Panel());
			this->panel2 = (gcnew System::Windows::Forms::Panel());
			this->panel3 = (gcnew System::Windows::Forms::Panel());
			this->menuStrip1->SuspendLayout();
			this->SuspendLayout();
			// 
			// menuStrip1
			// 
			this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {this->plikToolStripMenuItem, 
				this->opcjeToolStripMenuItem});
			this->menuStrip1->Location = System::Drawing::Point(0, 0);
			this->menuStrip1->Name = L"menuStrip1";
			this->menuStrip1->Size = System::Drawing::Size(462, 24);
			this->menuStrip1->TabIndex = 0;
			this->menuStrip1->Text = L"menuStrip1";
			// 
			// plikToolStripMenuItem
			// 
			this->plikToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {this->startToolStripMenuItem, 
				this->wyjscieToolStripMenuItem});
			this->plikToolStripMenuItem->Name = L"plikToolStripMenuItem";
			this->plikToolStripMenuItem->Size = System::Drawing::Size(34, 20);
			this->plikToolStripMenuItem->Text = L"Plik";
			// 
			// startToolStripMenuItem
			// 
			this->startToolStripMenuItem->Enabled = false;
			this->startToolStripMenuItem->Name = L"startToolStripMenuItem";
			this->startToolStripMenuItem->Size = System::Drawing::Size(152, 22);
			this->startToolStripMenuItem->Text = L"Start";
			this->startToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::startToolStripMenuItem_Click);
			// 
			// wyjscieToolStripMenuItem
			// 
			this->wyjscieToolStripMenuItem->Name = L"wyjscieToolStripMenuItem";
			this->wyjscieToolStripMenuItem->Size = System::Drawing::Size(152, 22);
			this->wyjscieToolStripMenuItem->Text = L"Wyjście";
			this->wyjscieToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::wyjscieToolStripMenuItem_Click);
			// 
			// opcjeToolStripMenuItem
			// 
			this->opcjeToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(3) {this->krazki3ToolStripMenuItem, 
				this->krazki5ToolStripMenuItem, this->krazki7ToolStripMenuItem});
			this->opcjeToolStripMenuItem->Name = L"opcjeToolStripMenuItem";
			this->opcjeToolStripMenuItem->Size = System::Drawing::Size(47, 20);
			this->opcjeToolStripMenuItem->Text = L"Opcje";
			// 
			// krazki3ToolStripMenuItem
			// 
			this->krazki3ToolStripMenuItem->CheckOnClick = true;
			this->krazki3ToolStripMenuItem->Name = L"krazki3ToolStripMenuItem";
			this->krazki3ToolStripMenuItem->Size = System::Drawing::Size(133, 22);
			this->krazki3ToolStripMenuItem->Text = L"3 krążki";
			this->krazki3ToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::krazki3ToolStripMenuItem_Click);
			// 
			// krazki5ToolStripMenuItem
			// 
			this->krazki5ToolStripMenuItem->Name = L"krazki5ToolStripMenuItem";
			this->krazki5ToolStripMenuItem->Size = System::Drawing::Size(133, 22);
			this->krazki5ToolStripMenuItem->Text = L"5 krążków";
			this->krazki5ToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::krazki5ToolStripMenuItem_Click);
			// 
			// krazki7ToolStripMenuItem
			// 
			this->krazki7ToolStripMenuItem->Name = L"krazki7ToolStripMenuItem";
			this->krazki7ToolStripMenuItem->Size = System::Drawing::Size(133, 22);
			this->krazki7ToolStripMenuItem->Text = L"7 krążków";
			this->krazki7ToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::krazki7ToolStripMenuItem_Click);
			// 
			// panel1
			// 
			this->panel1->Location = System::Drawing::Point(65, 86);
			this->panel1->Name = L"panel1";
			this->panel1->Size = System::Drawing::Size(101, 290);
			this->panel1->TabIndex = 1;
			this->panel1->Click += gcnew System::EventHandler(this, &Form1::panel1Click);
			// 
			// panel2
			// 
			this->panel2->Location = System::Drawing::Point(184, 86);
			this->panel2->Name = L"panel2";
			this->panel2->Size = System::Drawing::Size(101, 290);
			this->panel2->TabIndex = 2;
			this->panel2->Click += gcnew System::EventHandler(this, &Form1::panel2Click);
			// 
			// panel3
			// 
			this->panel3->Location = System::Drawing::Point(301, 86);
			this->panel3->Name = L"panel3";
			this->panel3->Size = System::Drawing::Size(101, 290);
			this->panel3->TabIndex = 3;
			this->panel3->Click += gcnew System::EventHandler(this, &Form1::panel3Click);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(462, 405);
			this->Controls->Add(this->panel3);
			this->Controls->Add(this->panel2);
			this->Controls->Add(this->panel1);
			this->Controls->Add(this->menuStrip1);
			this->MainMenuStrip = this->menuStrip1;
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::Odswiez);
			this->menuStrip1->ResumeLayout(false);
			this->menuStrip1->PerformLayout();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: array<int,2>^ patyk; // tablica reprezentujaca patyki patyki numerowane od 0
	
	private: array <int>^ max_k; //ilosc krazków na poszczegolnych patykach
	private: int zrodlo;//numer patyka z ktorego pobieramy
	private: int cel;//numer patyka na ktory przenosimy
	private: int kod;//zmienna do wyboru patyka zrodła i celu
	private: int ile_krazkow; //ilosc krazkow w grze
    private: SolidBrush^ pedzel;

    private: System::Void przesun_krazki() { // funkcja przeklada krazki 
				 if (max_k[zrodlo]>0) { //jezeli zrodlo nie puste to przekladaj
				 if ((patyk[zrodlo,max_k[zrodlo]]<patyk[cel,max_k[cel]])||(max_k[cel]==0)) { //nie klasc wiekszego na mniejszym no chyba ze to pierwszy krazek
                      max_k[cel]++;
					  patyk[cel,max_k[cel]]=patyk[zrodlo,max_k[zrodlo]];
					  max_k[zrodlo]--;
				 }
				 
				 else MessageBox::Show("Nie wolno kłaść większego krążka na mniejszym","Błąd",MessageBoxButtons::OK,MessageBoxIcon::Error);
				 }
				 else MessageBox::Show("Brak krążków do przeniesienia","Błąd",MessageBoxButtons::OK,MessageBoxIcon::Error);
			 }

	 private: System::Void wyswietl_krazki() {
				 Image^ bmp = Image::FromFile("krazek.jpg");
				  Image^ bmp_wyb = Image::FromFile("krazek_wyb.jpg");
			
					 
			  //kontrolki graficzne na panelu
			Graphics^ g=panel1->CreateGraphics();
            Graphics^ g1=panel2->CreateGraphics();
			Graphics^ g3=panel3->CreateGraphics();
			panel1->Refresh();// wytrzyj stare krązki
			panel2->Refresh();
			panel3->Refresh();
			pedzel->Color=System::Drawing::Color::IndianRed;// przerysuj patyki 
			g->FillRectangle(pedzel,48,0,5,280);
			g1->FillRectangle(pedzel,48,0,5,280);
			g3->FillRectangle(pedzel,48,0,5,280);
			
			
             for (int i=1;i<max_k[0]+1;i++) {
			if (patyk[0,i]>0) g->DrawImage(bmp,(panel1->Width/2)-(panel1->Width/((ile_krazkow-patyk[0,i])+1))/2,panel1->Height-i*20,panel1->Width/((ile_krazkow-patyk[0,i])+1),20);
			}

			if ((kod==1)&&(zrodlo==0)) {g->DrawImage(bmp_wyb,(panel1->Width/2)-(panel1->Width/((ile_krazkow-patyk[0,max_k[0]])+1))/2,panel1->Height-max_k[0]*20,panel1->Width/((ile_krazkow-patyk[0,max_k[0]])+1),20);}

			for (int i=1;i<max_k[1]+1;i++) {
				if (patyk[1,i]>0) g1->DrawImage(bmp,(panel2->Width/2)-(panel2->Width/((ile_krazkow-patyk[1,i])+1))/2,panel2->Height-i*20,panel2->Width/((ile_krazkow-patyk[1,i])+1),20);
			}
			
			
			if ((kod==1)&&(zrodlo==1)) {g1->DrawImage(bmp_wyb,(panel2->Width/2)-(panel2->Width/((ile_krazkow-patyk[1,max_k[1]])+1))/2,panel2->Height-max_k[1]*20,panel2->Width/((ile_krazkow-patyk[1,max_k[1]])+1),20);}
			
			for (int i=1;i<max_k[2]+1;i++) {
				if (patyk[2,i]>0) g3->DrawImage(bmp,(panel3->Width/2)-(panel3->Width/((ile_krazkow-patyk[2,i])+1))/2,panel3->Height-i*20,panel3->Width/((ile_krazkow-patyk[2,i])+1),20);
			}

			if ((kod==1)&&(zrodlo==2)) {g3->DrawImage(bmp_wyb,(panel2->Width/2)-(panel1->Width/((ile_krazkow-patyk[2,max_k[2]])+1))/2,panel1->Height-max_k[2]*20,panel1->Width/((ile_krazkow-patyk[2,max_k[2]])+1),20);}
			
			
			 }

	private: System::Void startToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
				 max_k[0]=ile_krazkow; //poczatkowe polozenie krazkow
				 max_k[1]=0;
				 max_k[2]=0;
				 kod=0;
				 for (int k=1;k<max_k[0]+1;k++) // wypelnienie planszy na pierwszym patyku max ilosc krazkow
					 patyk[0,k]=max_k[0]-(k-1);
				
				wyswietl_krazki();
			 }
private: System::Void krazki3ToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			
			 startToolStripMenuItem->Enabled=true;
			 krazki3ToolStripMenuItem->Checked=true;
			 krazki5ToolStripMenuItem->Checked=false;
			 krazki7ToolStripMenuItem->Checked=false;
			 ile_krazkow=3;
		 }
private: System::Void krazki5ToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
		
			 startToolStripMenuItem->Enabled=true;
			 krazki3ToolStripMenuItem->Checked=false;
			 krazki5ToolStripMenuItem->Checked=true;
			 krazki7ToolStripMenuItem->Checked=false;
			 ile_krazkow=5;
		 }
private: System::Void krazki7ToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			 startToolStripMenuItem->Enabled=true;
			 krazki3ToolStripMenuItem->Checked=false;
			 krazki5ToolStripMenuItem->Checked=false;
			 krazki7ToolStripMenuItem->Checked=true;
			 ile_krazkow=7;
		 }
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
			patyk = gcnew array<int,2>(3,20); //tablica ze stanem patykow 
				max_k = gcnew array<int>(3); // liczba krązków na patyku
				pedzel = gcnew SolidBrush(System::Drawing::Color::IndianRed);
		 }
private: System::Void panel1Click(System::Object^  sender, System::EventArgs^  e) {
				if (kod==0) {zrodlo=0; kod=1; 
			    wyswietl_krazki();
				return;}
				 if (kod==1) {cel=0;kod=0;przesun_krazki();wyswietl_krazki();} 
				 }
private: System::Void panel2Click(System::Object^  sender, System::EventArgs^  e) {
			
				 if (kod==0) {zrodlo=1; kod=1; 
				 wyswietl_krazki();
				 return;
				 }
				 if (kod==1) {cel=1;kod=0;przesun_krazki();wyswietl_krazki();}
			
		 }
private: System::Void panel3Click(System::Object^  sender, System::EventArgs^  e) {
			
				 if (kod==0) {zrodlo=2; kod=1; 
			     wyswietl_krazki();
				 return;}
				 if (kod==1) {cel=2;kod=0;przesun_krazki();wyswietl_krazki();}
			
		 }
private: System::Void wyjscieToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			 Close();
		 }
private: System::Void Odswiez(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
wyswietl_krazki();
		 }
};
}

