add feature blocking foreign bombs
authorRiMa <s1810567015@students.fh-hagenberg.at>
Tue, 18 Dec 2018 16:29:23 +0000 (17:29 +0100)
committerRiMa <s1810567015@students.fh-hagenberg.at>
Tue, 18 Dec 2018 16:29:23 +0000 (17:29 +0100)
src/game.cpp
src/game.h

index 95cb3b1..f267631 100644 (file)
@@ -284,8 +284,7 @@ bool Game::NextFrame(float elapsed, const std::vector<std::unique_ptr<Client>>&
 
                        // check if player stands on a block, if yes reset to old position
                        MapField f = mMap(static_cast<size_t>(plr->getPosX()), static_cast<size_t>(plr->getPosY()));
-
-                       if (f == MapField::Breakable || f == MapField::Fixed) {
+                       if (f == MapField::Breakable || f == MapField::Fixed || playerStandOnForeignBomb(plr)) {
                                plr->setPosX(old_x);
                                plr->setPosY(old_y);
                        }
@@ -523,3 +522,16 @@ bool Game::GameEnd() {
 
        return true;
 }
+
+
+bool Game::playerStandOnForeignBomb(std::shared_ptr<Player> const &player){
+       for (size_t i = 0; i < mBombs.size(); i++){
+               if (mBombs.at(i).id != player->getID()){
+                       if (static_cast<size_t>(mBombs.at(i).x) == static_cast<size_t>(player->getPosX())
+                               && static_cast<size_t>(mBombs.at(i).y) == static_cast<size_t>(player->getPosY())){
+                               return true;
+                       }
+               }
+       }
+       return false;
+}
\ No newline at end of file
index 07fdb40..76e0ba2 100644 (file)
@@ -92,6 +92,13 @@ private:
        bool canPlaceBomb(size_t const& playerId, size_t const x, size_t const y);
 
        /**
+       * @brief Check if the player stand on a Bomb
+       * @param player actual Player
+       * @return @c true if the player can place a bomb, otherwise @c false
+       */
+       bool playerStandOnForeignBomb(std::shared_ptr<Player> const &player);
+
+       /**
        * @brief Let a bome at position [x][y] explode and draw the flames and remove the destroyable blocks
        * @param playerID The player ID
        * @param x Position x on the map