Skip to content

Commit

Permalink
Update tower stuff so you are charged for creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Coderlane committed Apr 16, 2012
1 parent 237e245 commit 9e04b32
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
39 changes: 31 additions & 8 deletions Eight Minions/game_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,25 +167,48 @@ void game_host::spawnCreep( creep *newCreep )
creepList.insertInOrder(newCreep);
}

int game_host::placeTower( int playerNumber, int towerType, int x, int y)
int game_host::placeTower(int playerNumber, int towerType, int x, int y)
{
if(Tmap[x][y] == NULL)
{
if(towerType == STRUCTURE)
{
// Not defined
if(Tmap[x][y] == NULL)
{
if(2 <= this->getPlayer(playerNumber)->getMoney())
{
structure *newStructure = new structure(0, playerNumber, towerType, x, y);
this->getPlayer(playerNumber)->spendMoney(2);
this->towerList.insertInOrder(newStructure);
Tmap[x][y] = newStructure;
}
}
}
else if(towerType >= NORMTOWER && towerType <= MINETOWER)
{
Standard_Tower *newTower = new Standard_Tower(STANDARDTOWERSTARTLEVEL, playerNumber, towerType, x, y, this);
this->towerList.insertInOrder(newTower);
Tmap[x][y] = newTower;
if(Tmap[x][y] == NULL)
{
Standard_Tower *newTower = new Standard_Tower(STANDARDTOWERSTARTLEVEL, playerNumber, towerType, x, y, this);
if(newTower->getCost() <= this->getPlayer(playerNumber)->getMoney())
{
this->getPlayer(playerNumber)->spendMoney(newTower->getCost());
this->towerList.insertInOrder(newTower);
Tmap[x][y] = newTower;
}
}
}
else if(towerType >= NORMCREEPTOWER && towerType <= FATTYCREEPTOWER)
{
Creep_Tower *newTower = new Creep_Tower(CREEPTOWERSTARTLEVEL, playerNumber, towerType, x, y, this);
this->towerList.insertInOrder(newTower);
Tmap[x][y] = newTower;
if(Tmap[x][y] == NULL)
{
Creep_Tower *newTower = new Creep_Tower(CREEPTOWERSTARTLEVEL, playerNumber, towerType, x, y, this);
if(newTower->getCost() <= this->getPlayer(playerNumber)->getMoney())
{
this->getPlayer(playerNumber)->spendMoney(newTower->getCost());
this->towerList.insertInOrder(newTower);
Tmap[x][y] = newTower;
}
}
}
else
return 0;
Expand Down
4 changes: 4 additions & 0 deletions Eight Minions/standard_tower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,8 @@ void Standard_Tower::iterate()
}
else
choose();
}
int Standard_Tower::getCost()
{
return cost;
}
2 changes: 2 additions & 0 deletions Eight Minions/standard_tower.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Standard_Tower : public structure
void sell();

int getID();

int getCost();
private:
game_host *manager;
queue<int> chosenCreeps;
Expand Down
4 changes: 4 additions & 0 deletions Eight Minions/tower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ int structure::setLevel(int newLevel){
void structure::iterate()
{
cout << "Nothing to do for base tower type" << endl;
}
int structure::getCost()
{
return cost;
}
2 changes: 2 additions & 0 deletions Eight Minions/tower.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class structure : public location
int player;
int level;
int type;
int cost;
SDL_Rect *r;
bool passable;
public:
Expand All @@ -19,6 +20,7 @@ class structure : public location
int getType();
int setType(int newType);
int getPlayer();
int getCost();

bool getPassable();
void setPassable(bool nPass);
Expand Down

0 comments on commit 9e04b32

Please sign in to comment.