Морской бой с++ winforms. Не получается сделать чтобы клетки вокруг корабля закрашивались когда корабль полностью сбит
private: System::Void ris() {
SolidBrush^ mySolidBrush = gcnew SolidBrush(Color::Red);
Graphics^ formGraph4 = this->panel1->CreateGraphics();
Graphics^ formGraph5 = this->panel2->CreateGraphics();
Brush^ Заливка = gcnew SolidBrush(Color::Orange);
//formGraph4->FillRectangle(gcnew SolidBrush(Color::Blue),0,0,200,200);
for (int ix = 1; ix <= 10; ix++) {
for (int iy = 1; iy <= 10; iy++) {
bool isShipSunk = true;
switch (mas[ix][iy]) {
case 1:
formGraph4->FillRectangle(gcnew SolidBrush(Color::Black), (ix - 1) * 20, (iy - 1) * 20, 20, 20);
break;
case 2:
formGraph4->FillRectangle(gcnew SolidBrush(Color::Red), (ix - 1) * 20, (iy - 1) * 20, 20, 20);
formGraph4->DrawLine(Pens::Black, (ix - 1) * 20, (iy - 1) * 20, (ix - 1) * 20 + 20, (iy - 1) * 20 + 20);
formGraph4->DrawLine(Pens::Black, (ix - 1) * 20, (iy - 1) * 20 + 20, (ix - 1) * 20 + 20, (iy - 1) * 20);
// Проверяем, потоплен ли корабль
// Проверяем, потоплен ли корабль // Проверяем, потоплен ли корабль
for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= 10; j++) {
if (mas[i][j] == 2 && mas2[i][j] != 2) {
isShipSunk = false;
break;
}
}
if (!isShipSunk) {
break;
}
}
// Если корабль полностью потоплен, закрашиваем клетки вокруг него точками
if (isShipSunk) {
for (int i = ix - 1; i <= ix + 1; i++) {
for (int j = iy - 1; j <= iy + 1; j++) {
if (i >= 1 && i <= 10 && j >= 1 && j <= 10 && mas[i][j] != 2 && mas2[i][j] != 2) {
mas2[i][j] = 2;
formGraph4->FillEllipse(gcnew SolidBrush(Color::Black), (i - 1) * 20 + 8, (j - 1) * 20 + 8, 4, 4);
}
}
}
}
break;
case 3:
formGraph4->FillRectangle(gcnew SolidBrush(Color::Black), (ix - 1) * 20 + 8, (iy - 1) * 20 + 8, 4, 4);
break;
}
switch (mas2[ix][iy]) {
/*case 1:
formGraph5->FillRectangle(gcnew SolidBrush(Color::Black),(ix-1)*20,(iy-1)*20,20,20);
break;*/
case 2:
formGraph5->FillRectangle(gcnew SolidBrush(Color::Red), (ix - 1) * 20, (iy - 1) * 20, 20, 20);
formGraph5->DrawLine(Pens::Black, (ix - 1) * 20, (iy - 1) * 20, (ix - 1) * 20 + 20, (iy - 1) * 20 + 20);
formGraph5->DrawLine(Pens::Black, (ix - 1) * 20, (iy - 1) * 20 + 20, (ix - 1) * 20 + 20, (iy - 1) * 20);
break;
case 3:
formGraph5->FillRectangle(gcnew SolidBrush(Color::Black), (ix - 1) * 20 + 8, (iy - 1) * 20 + 8, 4, 4);
break;
}
}
}
}