added some graphics but only for debug

This commit is contained in:
peri4
2010-08-27 14:04:05 +04:00
parent b3854e867d
commit 95f3fb74fa
37 changed files with 876 additions and 707 deletions

65
map.cpp
View File

@@ -27,11 +27,12 @@ Map::Map(QByteArray data, QSize size, QString name, int maxPlayers, int image, Q
}
for (int j=0; j<Cells[i].size(); j++)
{
if (Cells[i][j]==Start) starts.push_back(QPoint(i,j));
if (Cells[i][j]==Finish) finishs.push_back(QPoint(i,j));
if (Cells[i][j]==Start) Starts.push_back(QPoint(i,j));
if (Cells[i][j]==Finish) Finishs.push_back(QPoint(i,j));
}
}
if (starts.isEmpty() || finishs.isEmpty()) qFatal("invalid map, not found start/finish");
mapSize.setHeight(chei);
if (Starts.isEmpty() || Finishs.isEmpty()) qFatal("invalid map, not found start/finish");
// TODO: check for maxPlayers
players = maxPlayers;
imageType = image;
@@ -91,9 +92,9 @@ bool Map::addTowerOnMap(int playerId, QPoint pos)
{
Cells[pos.x()][pos.y()]=PlayerTower-playerId;
bool ok=true;
for (int i=0; i<starts.size(); i++)
for (int j=0; j<finishs.size(); j++)
if (WaveTrace(starts.at(i),finishs.at(j))<0) ok = false;
for (int i=0; i<Starts.size(); i++)
for (int j=0; j<Finishs.size(); j++)
if (waveTrace(Starts.at(i),Finishs.at(j))<0) ok = false;
qDebug()<<"ok="<<ok;
if (!ok)
{
@@ -105,12 +106,12 @@ bool Map::addTowerOnMap(int playerId, QPoint pos)
pathOK = new bool();
*pathOK = true;
qDebug("emit");
emit RecreateAlienPath(pathOK);
emit recreateAlienPath(pathOK);
qDebug() << *pathOK;
if (!pathOK)
{
Cells[pos.x()][pos.y()]=PlayerAlien+playerId;
emit RecreateAlienPath(pathOK);
emit recreateAlienPath(pathOK);
return false;
}
return true;
@@ -166,7 +167,7 @@ bool Map::addTowerOnMap(int playerId, QPoint pos)
//}
QVector<QPointF> Map::CreatePath(QPoint start, QPoint finish)
QVector<QPointF> Map::createPath(QPoint start, QPoint finish)
{
QPointF tp;
QVector<QPoint> srcPath;
@@ -175,7 +176,7 @@ QVector<QPointF> Map::CreatePath(QPoint start, QPoint finish)
//PathIndex = 1;
if (Cells[start.x()][start.y()] < 0) qDebug("ERROR invalid start"),exit(-1);
if (Cells[finish.x()][finish.y()] < 0) qDebug("ERROR invalid finish"),exit(-1);
srcPath = InvWaveTrace(finish,WaveTrace(start,finish));
srcPath = invWaveTrace(finish,waveTrace(start,finish));
for (int i=0; i<srcPath.size();i++)
{
int x = Cells.at(srcPath.at(i).x()).at(srcPath.at(i).y());
@@ -218,7 +219,7 @@ QVector<QPointF> Map::CreatePath(QPoint start, QPoint finish)
}
int Map::WaveTrace(QPoint start, QPoint finish)
int Map::waveTrace(QPoint start, QPoint finish)
{
bool stop = false;
int step = 2;
@@ -251,29 +252,37 @@ int Map::WaveTrace(QPoint start, QPoint finish)
}
tp.setX(cp.x() - 1);
tp.setY(cp.y());
if (fr.contains(tp) && TmpCells[tp.x()][tp.y()] == 0) {
TmpCells[tp.x()][tp.y()] = step;
curp.push_back(tp);
stop = false;
if (fr.contains(tp)) {
if (TmpCells[tp.x()][tp.y()] == 0) {
TmpCells[tp.x()][tp.y()] = step;
curp.push_back(tp);
stop = false;
}
}
tp.setX(cp.x() + 1);
if (fr.contains(tp) && TmpCells[tp.x()][tp.y()] == 0) {
TmpCells[tp.x()][tp.y()] = step;
curp.push_back(tp);
stop = false;
if (fr.contains(tp)) {
if (TmpCells[tp.x()][tp.y()] == 0) {
TmpCells[tp.x()][tp.y()] = step;
curp.push_back(tp);
stop = false;
}
}
tp.setX(cp.x());
tp.setY(cp.y() - 1);
if (fr.contains(tp) && TmpCells[tp.x()][tp.y()] == 0) {
TmpCells[tp.x()][tp.y()] = step;
curp.push_back(tp);
stop = false;
if (fr.contains(tp)) {
if (TmpCells[tp.x()][tp.y()] == 0) {
TmpCells[tp.x()][tp.y()] = step;
curp.push_back(tp);
stop = false;
}
}
tp.setY(cp.y() + 1);
if (fr.contains(tp) && TmpCells[tp.x()][tp.y()] == 0) {
TmpCells[tp.x()][tp.y()] = step;
curp.push_back(tp);
stop = false;
if (fr.contains(tp)) {
if (TmpCells[tp.x()][tp.y()] == 0) {
TmpCells[tp.x()][tp.y()] = step;
curp.push_back(tp);
stop = false;
}
}
}
step++;
@@ -284,7 +293,7 @@ int Map::WaveTrace(QPoint start, QPoint finish)
}
QVector<QPoint> Map::InvWaveTrace(QPoint finish, int cnt)
QVector<QPoint> Map::invWaveTrace(QPoint finish, int cnt)
{
QPoint wp, Ppnt;
QVector<QPoint> alpath;