void Field::openCell(HWND & hWnd) { for (int i = 0; i < sizeX; i++) { for (int j = 0; j < sizeY; j++) { if (area[i][j].getButton() == hWnd) { if (area[i][j].IsOpened()) { return; } if (area[i][j].isBomb()) { area[i][j].open(); SendMessage(hWnd, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)images[10]); UpdateWindow(hWnd); explode = true; return; } int outPut = checkSiblings(i, j); if (!outPut) { SendMessage(hWnd, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)images[0]); EnableWindow(hWnd, 0); area[i][j].open(); if ((i - 1) >= 0 && (j - 1) >= 0 && !area[i - 1][j - 1].isBomb()) openCell(area[i - 1][j - 1].getButton()); if ((i - 1) >= 0 && !area[i - 1][j].isBomb()) openCell(area[i - 1][j].getButton()); if ((i - 1) >= 0 && (j + 1) >= 0 && !area[i - 1][j + 1].isBomb()) openCell(area[i - 1][j + 1].getButton()); if ((j - 1) >= 0 && !area[i][j - 1].isBomb()) openCell(area[i][j - 1].getButton()); if ((j + 1) >= 0 && !area[i][j + 1].isBomb()) openCell(area[i][j + 1].getButton()); if ((i + 1) < sizeX && (j - 1) >= 0 && !area[i + 1][j - 1].isBomb()) openCell(area[i + 1][j - 1].getButton()); if ((i + 1) < sizeX && !area[i + 1][j].isBomb()) openCell(area[i + 1][j].getButton()); if ((i + 1) < sizeX && (j + 1) < sizeY && !area[i + 1][j + 1].isBomb()) openCell(area[i + 1][j + 1].getButton()); } else { SendMessage(hWnd, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)images[outPut]); EnableWindow(area[i][j].getButton(), 0); area[i][j].open(); } UpdateWindow(hWnd); break; } } } }
std::pair<int,bool> mine_sweeper::openCell() { return openCell(posY,posX); }