now is enable build and delete towers in game and improve graphic perfomance
find and correct many-many bugs
This commit is contained in:
92
map.cpp
92
map.cpp
@@ -81,13 +81,32 @@ 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;
|
||||
emit recreateAlienPath(new bool());
|
||||
}
|
||||
|
||||
|
||||
bool Map::isReachable(int playerId, QPoint pos)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -104,74 +123,21 @@ bool Map::addTowerOnMap(int playerId, QPoint pos)
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return isReachable(playerId,pos);
|
||||
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++)
|
||||
// if (waveTrace(Starts.at(i),Finishs.at(j))<0) ok = false;
|
||||
// qDebug()<<"ok="<<ok;
|
||||
// if (!ok)
|
||||
// {
|
||||
// Cells[pos.x()][pos.y()]=AlienPath+playerId;
|
||||
// return false;
|
||||
// }
|
||||
//Cells[pos.x()][pos.y()]=PlayerTower-playerId;
|
||||
if (!isReachable(playerId,pos)) return false;
|
||||
bool * pathOK;
|
||||
pathOK = new bool();
|
||||
*pathOK = true;
|
||||
//qDebug("emit");
|
||||
pathOK = new bool(true);
|
||||
emit recreateAlienPath(pathOK);
|
||||
qDebug() << *pathOK;
|
||||
if (!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;
|
||||
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;
|
||||
if (*pathOK)
|
||||
return true;
|
||||
else
|
||||
delTowerOnMap(playerId,pos);
|
||||
}
|
||||
qDebug()<<"Dont buid here" << pos;
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user