#pragma once


namespace TicTacToe {

	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>
	/// Zusammenfassung für Form1
	///
	/// Warnung: Wenn Sie den Namen dieser Klasse ändern, müssen Sie auch
	///          die Ressourcendateiname-Eigenschaft für das Tool zur Kompilierung verwalteter Ressourcen ändern,
	///          das allen RESX-Dateien zugewiesen ist, von denen diese Klasse abhängt.
	///          Anderenfalls können die Designer nicht korrekt mit den lokalisierten Ressourcen
	///          arbeiten, die diesem Formular zugewiesen sind.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Konstruktorcode hier hinzufügen.
			//
		}

	protected:
		/// <summary>
		/// Verwendete Ressourcen bereinigen.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
   private: System::Windows::Forms::MenuStrip^  menuStrip1;
   protected: 

   private: System::Windows::Forms::TableLayoutPanel^  tableLayoutPanel1;
   private: TicTacToe::TTTField^  tttField1;
   private: TicTacToe::TTTField^  tttField2;
   private: TicTacToe::TTTField^  tttField5;
   private: TicTacToe::TTTField^  tttField6;
   private: TicTacToe::TTTField^  tttField7;
   private: TicTacToe::TTTField^  tttField8;
   private: TicTacToe::TTTField^  tttField9;
   private: TicTacToe::TTTField^  tttField3;
   private: TicTacToe::TTTField^  tttField4;
   private: System::Windows::Forms::ToolStripMenuItem^  neuesSpielToolStripMenuItem;

	private:
		/// <summary>
		/// Erforderliche Designervariable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Erforderliche Methode für die Designerunterstützung.
		/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
		/// </summary>
		void InitializeComponent(void)
		{
         this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
         this->neuesSpielToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
         this->tableLayoutPanel1 = (gcnew System::Windows::Forms::TableLayoutPanel());
         this->tttField1 = (gcnew TicTacToe::TTTField());
         this->tttField2 = (gcnew TicTacToe::TTTField());
         this->tttField5 = (gcnew TicTacToe::TTTField());
         this->tttField6 = (gcnew TicTacToe::TTTField());
         this->tttField7 = (gcnew TicTacToe::TTTField());
         this->tttField8 = (gcnew TicTacToe::TTTField());
         this->tttField9 = (gcnew TicTacToe::TTTField());
         this->tttField3 = (gcnew TicTacToe::TTTField());
         this->tttField4 = (gcnew TicTacToe::TTTField());
         this->menuStrip1->SuspendLayout();
         this->tableLayoutPanel1->SuspendLayout();
         this->SuspendLayout();
         // 
         // menuStrip1
         // 
         this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) {this->neuesSpielToolStripMenuItem});
         this->menuStrip1->Location = System::Drawing::Point(0, 0);
         this->menuStrip1->Name = L"menuStrip1";
         this->menuStrip1->Size = System::Drawing::Size(347, 24);
         this->menuStrip1->TabIndex = 0;
         this->menuStrip1->Text = L"menuStrip1";
         // 
         // neuesSpielToolStripMenuItem
         // 
         this->neuesSpielToolStripMenuItem->Name = L"neuesSpielToolStripMenuItem";
         this->neuesSpielToolStripMenuItem->Size = System::Drawing::Size(80, 20);
         this->neuesSpielToolStripMenuItem->Text = L"&Neues Spiel";
         this->neuesSpielToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::neuesSpielToolStripMenuItem_Click);
         // 
         // tableLayoutPanel1
         // 
         this->tableLayoutPanel1->ColumnCount = 3;
         this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Percent, 
            33.33333F)));
         this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Percent, 
            33.33333F)));
         this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Percent, 
            33.33333F)));
         this->tableLayoutPanel1->Controls->Add(this->tttField1, 0, 0);
         this->tableLayoutPanel1->Controls->Add(this->tttField2, 1, 0);
         this->tableLayoutPanel1->Controls->Add(this->tttField5, 1, 1);
         this->tableLayoutPanel1->Controls->Add(this->tttField6, 2, 1);
         this->tableLayoutPanel1->Controls->Add(this->tttField7, 0, 2);
         this->tableLayoutPanel1->Controls->Add(this->tttField8, 1, 2);
         this->tableLayoutPanel1->Controls->Add(this->tttField9, 2, 2);
         this->tableLayoutPanel1->Controls->Add(this->tttField3, 2, 0);
         this->tableLayoutPanel1->Controls->Add(this->tttField4, 0, 1);
         this->tableLayoutPanel1->Dock = System::Windows::Forms::DockStyle::Fill;
         this->tableLayoutPanel1->Location = System::Drawing::Point(0, 24);
         this->tableLayoutPanel1->Name = L"tableLayoutPanel1";
         this->tableLayoutPanel1->RowCount = 3;
         this->tableLayoutPanel1->RowStyles->Add((gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Percent, 33.33333F)));
         this->tableLayoutPanel1->RowStyles->Add((gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Percent, 33.33333F)));
         this->tableLayoutPanel1->RowStyles->Add((gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Percent, 33.33333F)));
         this->tableLayoutPanel1->Size = System::Drawing::Size(347, 233);
         this->tableLayoutPanel1->TabIndex = 1;
         // 
         // tttField1
         // 
         this->tttField1->Dock = System::Windows::Forms::DockStyle::Fill;
         this->tttField1->Location = System::Drawing::Point(3, 3);
         this->tttField1->MinimumSize = System::Drawing::Size(50, 50);
         this->tttField1->Name = L"tttField1";
         this->tttField1->Size = System::Drawing::Size(109, 71);
         this->tttField1->Status = TicTacToe::TTTStatus::Empty;
         this->tttField1->TabIndex = 0;
         this->tttField1->Text = L"tttField1";
         this->tttField1->Click += gcnew System::EventHandler(this, &Form1::tttField1_Click);
         // 
         // tttField2
         // 
         this->tttField2->Dock = System::Windows::Forms::DockStyle::Fill;
         this->tttField2->Location = System::Drawing::Point(118, 3);
         this->tttField2->MinimumSize = System::Drawing::Size(50, 50);
         this->tttField2->Name = L"tttField2";
         this->tttField2->Size = System::Drawing::Size(109, 71);
         this->tttField2->Status = TicTacToe::TTTStatus::Empty;
         this->tttField2->TabIndex = 1;
         this->tttField2->Text = L"tttField2";
         this->tttField2->Click += gcnew System::EventHandler(this, &Form1::tttField1_Click);
         // 
         // tttField5
         // 
         this->tttField5->Dock = System::Windows::Forms::DockStyle::Fill;
         this->tttField5->Location = System::Drawing::Point(118, 80);
         this->tttField5->MinimumSize = System::Drawing::Size(50, 50);
         this->tttField5->Name = L"tttField5";
         this->tttField5->Size = System::Drawing::Size(109, 71);
         this->tttField5->Status = TicTacToe::TTTStatus::Empty;
         this->tttField5->TabIndex = 4;
         this->tttField5->Text = L"tttField5";
         this->tttField5->Click += gcnew System::EventHandler(this, &Form1::tttField1_Click);
         // 
         // tttField6
         // 
         this->tttField6->Dock = System::Windows::Forms::DockStyle::Fill;
         this->tttField6->Location = System::Drawing::Point(233, 80);
         this->tttField6->MinimumSize = System::Drawing::Size(50, 50);
         this->tttField6->Name = L"tttField6";
         this->tttField6->Size = System::Drawing::Size(111, 71);
         this->tttField6->Status = TicTacToe::TTTStatus::Empty;
         this->tttField6->TabIndex = 5;
         this->tttField6->Text = L"tttField6";
         this->tttField6->Click += gcnew System::EventHandler(this, &Form1::tttField1_Click);
         // 
         // tttField7
         // 
         this->tttField7->Dock = System::Windows::Forms::DockStyle::Fill;
         this->tttField7->Location = System::Drawing::Point(3, 157);
         this->tttField7->MinimumSize = System::Drawing::Size(50, 50);
         this->tttField7->Name = L"tttField7";
         this->tttField7->Size = System::Drawing::Size(109, 73);
         this->tttField7->Status = TicTacToe::TTTStatus::Empty;
         this->tttField7->TabIndex = 6;
         this->tttField7->Text = L"tttField7";
         this->tttField7->Click += gcnew System::EventHandler(this, &Form1::tttField1_Click);
         // 
         // tttField8
         // 
         this->tttField8->Dock = System::Windows::Forms::DockStyle::Fill;
         this->tttField8->Location = System::Drawing::Point(118, 157);
         this->tttField8->MinimumSize = System::Drawing::Size(50, 50);
         this->tttField8->Name = L"tttField8";
         this->tttField8->Size = System::Drawing::Size(109, 73);
         this->tttField8->Status = TicTacToe::TTTStatus::Empty;
         this->tttField8->TabIndex = 7;
         this->tttField8->Text = L"tttField8";
         this->tttField8->Click += gcnew System::EventHandler(this, &Form1::tttField1_Click);
         // 
         // tttField9
         // 
         this->tttField9->Dock = System::Windows::Forms::DockStyle::Fill;
         this->tttField9->Location = System::Drawing::Point(233, 157);
         this->tttField9->MinimumSize = System::Drawing::Size(50, 50);
         this->tttField9->Name = L"tttField9";
         this->tttField9->Size = System::Drawing::Size(111, 73);
         this->tttField9->Status = TicTacToe::TTTStatus::Empty;
         this->tttField9->TabIndex = 8;
         this->tttField9->Text = L"tttField9";
         this->tttField9->Click += gcnew System::EventHandler(this, &Form1::tttField1_Click);
         // 
         // tttField3
         // 
         this->tttField3->Dock = System::Windows::Forms::DockStyle::Fill;
         this->tttField3->Location = System::Drawing::Point(233, 3);
         this->tttField3->MinimumSize = System::Drawing::Size(50, 50);
         this->tttField3->Name = L"tttField3";
         this->tttField3->Size = System::Drawing::Size(111, 71);
         this->tttField3->Status = TicTacToe::TTTStatus::Empty;
         this->tttField3->TabIndex = 9;
         this->tttField3->Text = L"tttField3";
         this->tttField3->Click += gcnew System::EventHandler(this, &Form1::tttField1_Click);
         // 
         // tttField4
         // 
         this->tttField4->Dock = System::Windows::Forms::DockStyle::Fill;
         this->tttField4->Location = System::Drawing::Point(3, 80);
         this->tttField4->MinimumSize = System::Drawing::Size(50, 50);
         this->tttField4->Name = L"tttField4";
         this->tttField4->Size = System::Drawing::Size(109, 71);
         this->tttField4->Status = TicTacToe::TTTStatus::Empty;
         this->tttField4->TabIndex = 10;
         this->tttField4->Text = L"tttField4";
         this->tttField4->Click += gcnew System::EventHandler(this, &Form1::tttField1_Click);
         // 
         // Form1
         // 
         this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
         this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
         this->ClientSize = System::Drawing::Size(347, 257);
         this->Controls->Add(this->tableLayoutPanel1);
         this->Controls->Add(this->menuStrip1);
         this->MainMenuStrip = this->menuStrip1;
         this->Name = L"Form1";
         this->Text = L"TicTacToe";
         this->menuStrip1->ResumeLayout(false);
         this->menuStrip1->PerformLayout();
         this->tableLayoutPanel1->ResumeLayout(false);
         this->ResumeLayout(false);
         this->PerformLayout();

      }
#pragma endregion
   private: 
      void neuesSpielToolStripMenuItem_Click(Object^  sender, EventArgs^  e) 
      {
         for(int i = 0; i < tableLayoutPanel1->Controls->Count; i++)
            ((TTTField^) tableLayoutPanel1->Controls[i])->Status = TTTStatus::Empty;
             
         this->Refresh();
      }

      void tttField1_Click(Object^  sender, EventArgs^  e)
      {
          this->Evaluate();
      }

      void Evaluate()
      {
          if (tttField1->Status != TTTStatus::Empty &&
              tttField1->Status == tttField2->Status && tttField2->Status == tttField3->Status)
              MessageBox::Show(String::Format(" {0} hat gewonnen", tttField1->Status == TTTStatus::Cross ? "Kreuz" : "Kreis"));
          if (tttField4->Status != TTTStatus::Empty &&
              tttField4->Status == tttField5->Status && tttField5->Status == tttField6->Status)
              MessageBox::Show(String::Format(" {0} hat gewonnen", tttField4->Status == TTTStatus::Cross ? "Kreuz" : "Kreis"));
          if (tttField7->Status != TTTStatus::Empty &&
              tttField7->Status == tttField8->Status && tttField8->Status == tttField9->Status)
              MessageBox::Show(String::Format(" {0} hat gewonnen", tttField7->Status == TTTStatus::Cross ? "Kreuz" : "Kreis"));
          if (tttField1->Status != TTTStatus::Empty &&
              tttField1->Status == tttField4->Status && tttField4->Status == tttField7->Status)
              MessageBox::Show(String::Format(" {0} hat gewonnen", tttField1->Status == TTTStatus::Cross ? "Kreuz" : "Kreis"));
          if (tttField2->Status != TTTStatus::Empty &&
              tttField2->Status == tttField5->Status && tttField5->Status == tttField8->Status)
              MessageBox::Show(String::Format(" {0} hat gewonnen", tttField2->Status == TTTStatus::Cross ? "Kreuz" : "Kreis"));
          if (tttField3->Status != TTTStatus::Empty &&
              tttField3->Status == tttField6->Status && tttField6->Status == tttField9->Status)
              MessageBox::Show(String::Format(" {0} hat gewonnen", tttField3->Status == TTTStatus::Cross ? "Kreuz" : "Kreis"));
          if (tttField1->Status != TTTStatus::Empty &&
              tttField1->Status == tttField5->Status && tttField5->Status == tttField9->Status)
              MessageBox::Show(String::Format(" {0} hat gewonnen", tttField1->Status == TTTStatus::Cross ? "Kreuz" : "Kreis"));
          if (tttField3->Status != TTTStatus::Empty &&
              tttField3->Status == tttField5->Status && tttField5->Status == tttField7->Status)
              MessageBox::Show(String::Format(" {0} hat gewonnen", tttField3->Status == TTTStatus::Cross ? "Kreuz" : "Kreis"));
      }

};
}

