t (QColor lColor, int i, int j);// обробляє промахpaintDeck (QColor lColor, QColor deckColor, int i, int j);// малює палуьби
getLocation (int size, int i, int j, int locI);// записує координати палоб для кожного корабля checkDeath (int i, int j);// перевірка на знищення корабля
void supCheck (int sizeShip, int ** a);// вспомогательнаяpaintPoints (int sizeShip, int ** a, QColor lColor);
};
# endif//FIELD_H
Файл field.cpp
# include field.h
:: Field ()
{= - 1;=0;=0;=0;=0;=0;
=0;=0;=0;=0;=0;=0;
path=QApplication :: applicationDirPath () + /settings.confraquo ;;
* settings=new QSettings (path, QSettings :: IniFormat);=settings- gt; value ( settings/sizeField ). toInt (); () lt; lt; sizeField;= settings- gt; value ( settings/sizeDeck ). toInt ();
();
}
Field :: paintField (QColor Bcolor, QColor Lcolor)
{i, j; ch; str; * numbers, * letters; .setBackgroundBrush (QBrush (Bcolor));
//------ промальовування поля ------------------------------------- (i=30; i lt; 330; i=i + 30) (j=30; j lt; 330; j=j + 30) .addRect (j, i, sizeDeck, sizeDeck, QPen (Lcolor) , QBrush (Bcolor));
//----------------------------------------------------------
//--------- промальовування букв і цифр ---------------------------(i=1; i lt;=sizeField; i ++)
{= scene.addText (QString :: number (i)); gt; setDefaultTextColor (Lcolor); gt; setPos (5, i * sizeDeck);
}
=1; (ch= A raquo ;; ch lt;= J raquo ;; ch ++)
{= ch;=scene.addText (str); gt; setDefaultTextColor (Lcolor); gt; setPos ((i + 0.3) * sizeDeck, 0); ++;
}
//----------------------------------------------------------
}
Field :: matrix ()
{i, j; (i=0; i lt; sizeField; i ++) (j=0; j lt; sizeField; j ++) [i] [j]=- 1;
}
Field :: calcPos (int x, int y)
{
}
Field :: loadField (QColor lColor, QColor bColor, QColor deckColor, QColor hitColor)
{i, j; (bColor, lColor); (i=0; i lt; sizeField; i ++) (j=0; j lt; sizeField; j ++)
{(player [i] [j] == 0) paintDeck (lColor, deckColor, i, j); if (player [i] [j] == 2) past (lColor, i +1, j + 1); if (player [i] [j] == 1) wound (i + 1, j + 1, lColor, hitColor);
}
}
Field :: checkPosition ()
{i, j, f, iStart, jStart, jFinish, iFinish;=0;=iShip - 1;=jShip - 1; (i == 0) iStart=0; iStart=i -1;
(j == 0) jStart=0; jStart=j - 1;
(i == 9) iFinish=9; iFinish=i + 1;
(j == 9) jFinish=9; jFinish=j + 1;
(player [iShip - 1] [jShip - 1] == size) f=1; (i=iStart; i lt;=iFinish; i ++) (j=jStart; j lt;=jFinish; j ++) (player [i] [j] == 0) f=1;
(f!=0) return false; return true;
}
Field :: selectShip (int amp; flag, int amp; t, int amp; size)
{i, j, f, iStart, jStart, jFinish, iFinish;=0;
(flag lt; size)
{= iShip - 1;=jShip - 1; (i == 0) iStart=0; iStart=i - 1;
(j == 0) jStart=0; jStart=j - 1;
(i == 9) iFinish=9; iFinish=i + 1;
(j == 9) jFinish=9; jFinish=j + 1;
(checkPosition ())
{(t!=1)
{. addRect (jShip * sizeDeck, iShip * sizeDeck, sizeDeck, sizeDeck, QPen (Qt :: red, 1)); [iShip - 1] [jShip - 1]=size;=1 ;=1;
} (i=iStart; i lt;=iFinish; i ++) (j=jStart; j lt;=jFinish; j ++)
{(player [i] [j] == size)
{((i == iShip - 1 amp; amp; j!=jShip - 1) || (i!=iShip - 1 amp; amp; j == jShip - 1))
{. addRect (jShip * sizeDeck, iShip * sizeDeck, sizeDeck, sizeDeck, QPen (Qt :: red, 1)); [iShip - 1] [jShip - 1]=size;=1 ;
}
}
} (f!=0) flag ++; (flag == size)
{(size, lColor, deckColor);=0;=0;
(size == 3) thI ++; if (size == 2) twI ++; if (siz...