build_towers

This commit is contained in:
unknown
2010-08-31 21:29:47 +04:00
parent bbb6f9b366
commit 0e0f1cbfbb
8 changed files with 82 additions and 21 deletions

55
map.cpp
View File

@@ -78,6 +78,19 @@ void Map::removeAliensPath()
}
}
void Map::delTowerOnMap(int playerId, QPoint pos)
{
bool * pathOK;
pathOK = new bool();
emit recreateAlienPath(pathOK);
Cells[pos.x()][pos.y()]=Player+playerId;
Cells[pos.x()+1][pos.y()]=Player+playerId;
Cells[pos.x()][pos.y()+1]=Player+playerId;
Cells[pos.x()+1][pos.y()+1]=Player+playerId;
}
bool Map::addTowerOnMap(int playerId, QPoint pos)
{
//qDebug() << pos;
@@ -109,15 +122,26 @@ bool Map::addTowerOnMap(int playerId, QPoint pos)
}
return true;
}
if (Cells[pos.x()][pos.y()]==AlienPath+playerId &&
Cells[pos.x()+1][pos.y()]==AlienPath+playerId &&
Cells[pos.x()][pos.y()+1]==AlienPath+playerId &&
Cells[pos.x()+1][pos.y()+1]==AlienPath+playerId)
if ((Cells[pos.x()][pos.y()]==AlienPath+Player+playerId || Cells[pos.x()][pos.y()]==Player+playerId) &&
(Cells[pos.x()+1][pos.y()]==AlienPath+Player+playerId || Cells[pos.x()+1][pos.y()]==Player+playerId) &&
(Cells[pos.x()][pos.y()+1]==AlienPath+Player+playerId || Cells[pos.x()][pos.y()+1]==Player+playerId) &&
(Cells[pos.x()+1][pos.y()+1]==AlienPath+Player+playerId || Cells[pos.x()+1][pos.y()+1]==Player+playerId))
{
Cells[pos.x()][pos.y()]=PlayerTower-playerId;
Cells[pos.x()+1][pos.y()]=PlayerTower-playerId;
Cells[pos.x()][pos.y()+1]=PlayerTower-playerId;
Cells[pos.x()+1][pos.y()+1]=PlayerTower-playerId;
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) {
Cells[pos.x()][pos.y()]=Player+playerId;
Cells[pos.x()+1][pos.y()]=Player+playerId;
Cells[pos.x()][pos.y()+1]=Player+playerId;
Cells[pos.x()+1][pos.y()+1]=Player+playerId;
return false;
}
}
}
// bool ok=true;
// for (int i=0; i<Starts.size(); i++)
// for (int j=0; j<Finishs.size(); j++)
@@ -137,14 +161,17 @@ bool Map::addTowerOnMap(int playerId, QPoint pos)
qDebug() << *pathOK;
if (!pathOK)
{
Cells[pos.x()][pos.y()]=AlienPath+playerId;
Cells[pos.x()+1][pos.y()]=AlienPath+playerId;
Cells[pos.x()][pos.y()+1]=AlienPath+playerId;
Cells[pos.x()+1][pos.y()+1]=AlienPath+playerId;
Cells[pos.x()][pos.y()]=Player+playerId;
Cells[pos.x()+1][pos.y()]=Player+playerId;
Cells[pos.x()][pos.y()+1]=Player+playerId;
Cells[pos.x()+1][pos.y()+1]=Player+playerId;
emit recreateAlienPath(pathOK);
return false;
}
return true;
} else {
qDebug() << Cells[pos.x()][pos.y()] << Cells[pos.x()+1][pos.y()] << Cells[pos.x()][pos.y()+1] << Cells[pos.x()+1][pos.y()+1];
qDebug() << playerId;
}
qDebug()<<"Dont buid here" << pos;
return false;
@@ -204,8 +231,16 @@ QVector<QPointF> Map::createPath(QPoint start, QPoint finish)
QVector<QPointF> tmpPath;
QVector<QPointF> path;
//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);
if (Cells[start.x()][start.y()] < 0)
{
qDebug("ERROR invalid start");
return path;
}
if (Cells[finish.x()][finish.y()] < 0)
{
qDebug("ERROR invalid finish");
return path;
}
srcPath = invWaveTrace(finish,waveTrace(start,finish));
for (int i=0; i<srcPath.size();i++)
{