text: #include "cMain.h"
  
  wxBEGIN_EVENT_TABLE(cMain, wxFrame)
  	
  wxEND_EVENT_TABLE()
  
  cMain::cMain() : wxFrame(nullptr, wxID_ANY, "github.com/defini7 - Windows Application Example", wxPoint(30,30), wxSize(800, 600))
  {
  	btn = new wxButton*[nFieldWidth * nFieldHeight];
  	wxGridSizer* grid = new wxGridSizer(nFieldWidth, nFieldHeight, 0, 0);
  
  	wxFont font(24, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false);
  
  	nField = new int[nFieldWidth * nFieldHeight];
  
  	for (int x = 0; x < nFieldWidth; x++)
  	{
  		for (int y = 0; y < nFieldHeight; y++)
  		{
  			btn[y * nFieldWidth + x] = new wxButton(this, 10000 + (y * nFieldWidth + x));
  			btn[y * nFieldWidth + x]->SetFont(font);
  			grid->Add(btn[y * nFieldWidth + x], 1, wxEXPAND | wxALL);
  
  
  			btn[y * nFieldWidth + x]->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &cMain::OnButtonClicked, this);
  			nField[y * nFieldWidth + x] = 0;
  		}
  	}
  
  	this->SetSizer(grid);
  	grid->Layout();
  }
  
  cMain::~cMain()
  {
  	delete[] btn;
  }
  
  void cMain::OnButtonClicked(wxCommandEvent& evt)
  {
  	// Get coordinate of button in field array
  	int x = (evt.GetId() - 10000) % nFieldWidth;
  	int y = (evt.GetId() - 10000) / nFieldWidth;
  	mines = 30;
  
  	if (bFirstClick)
  	{
  		while (mines)
  		{
  			int rx = rand() % nFieldWidth;
  			int ry = rand() % nFieldHeight;
  
  			if (nField[ry * nFieldWidth + rx] == 0 && rx != x && ry != y)
  			{
  				nField[ry * nFieldWidth + rx] = -1;
  				mines--;
  			}
  		}
  		
  		bFirstClick = false;
  	}
  
  	// Disable Button, preventing it being pressed again
  	btn[y * nFieldWidth + x]->Enable(false);
  
  	// Check if player hit a mine
  	if (nField[y * nFieldWidth + x] == -1)
  	{
  		wxMessageBox("BOOM!");
  
  		bFirstClick = true;
  		for (int x = 0; x < nFieldWidth; x++)
  			for (int y = 0; y < nFieldHeight; y++)
  			{
  				nField[y * nFieldWidth + x] = 0;
  				btn[y * nFieldWidth + x]->SetLabel("");
  				btn[y * nFieldWidth + x]->Enable();
  			}
  	}
  	else
  	{
  		int mineCount = 0;
  		for (int i = -1; i < 2; i++)
  			for (int j = -1; j < 2; j++)
  			{
  				if (x + i >= 0 && x + i < nFieldWidth && y + j >= 0 && y + j < nFieldHeight)
  				{
  					if (nField[(y + j) * nFieldWidth + (x + i)] == -1)
  						mineCount++;
  				}
  			}
  
  		if (mineCount > 0)
  		{
  			btn[y * nFieldWidth + x]->SetLabel(std::to_string(mineCount));
  		}
  	}
  
  	evt.Skip();
  }
  