Skip to content

Commit

Permalink
Divide Game::moveEnemyTanks method.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Oct 11, 2024
1 parent f8c94e1 commit a3165d0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,8 @@ void Game::moveEnemyTanks()
if (const auto now{std::chrono::system_clock::now()};
tank.canFire(now))
bullets_.emplace_back(tank.fire(now));
const int randomDirection{distribution_(randomGenerator_)};

Direction direction{Direction::UP};
if (((tank.getX() % Config::getInstance().getTileSize()) == 0) &&
((tank.getY() % Config::getInstance().getTileSize()) == 0) &&
(randomDirection < 4))
direction = static_cast<Direction>(randomDirection);
else
direction = tank.getDirection();

Direction direction{getEnemyTankDirection(tank)};
movement(tank, direction);
}
}
Expand Down Expand Up @@ -239,3 +232,17 @@ bool Game::canDrive(Point point, Direction direction) const
[&map = map_](Point corner)
{ return map.canDrive(corner); });
}

Direction Game::getEnemyTankDirection(Tank& tank)
{
const int randomDirection{distribution_(randomGenerator_)};
Direction direction{Direction::UP};
if (((tank.getX() % Config::getInstance().getTileSize()) == 0) &&
((tank.getY() % Config::getInstance().getTileSize()) == 0) &&
(randomDirection < 4))
direction = static_cast<Direction>(randomDirection);
else
direction = tank.getDirection();

return direction;
}
2 changes: 2 additions & 0 deletions src/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class Game

bool canDrive(Point point, Direction direction) const;

Direction getEnemyTankDirection(Tank& tank);

Status status_;
std::mt19937 randomGenerator_;
bool playerDestroyed_{false};
Expand Down

0 comments on commit a3165d0

Please sign in to comment.