Skip to content

Commit

Permalink
Add parentheses to make the operator precedence explicit.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Sep 13, 2024
1 parent eca45de commit 6c38ed9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/Bullet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

Bullet::Bullet(Point startingPoint, unsigned int speed, bool playerOrigin,
unsigned int power, Direction direction)
: Drawable({startingPoint.x_ - Config::getInstance().getBulletSize() / 2,
startingPoint.y_ - Config::getInstance().getBulletSize() / 2}),
: Drawable(
{startingPoint.x_ - (Config::getInstance().getBulletSize() / 2),
startingPoint.y_ - (Config::getInstance().getBulletSize() / 2)}),
size_(Config::getInstance().getBulletSize()),
playerOrigin_(playerOrigin),
direction_(direction),
Expand Down
4 changes: 2 additions & 2 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void Config::setFPS(FPS fps)
Config::Config()
{
const unsigned int initialBoardSize{tileCount_ * tileSize_};
screenSizeChanged(initialBoardSize + initialBoardSize / 3,
screenSizeChanged(initialBoardSize + (initialBoardSize / 3),
initialBoardSize);
}

Expand All @@ -61,5 +61,5 @@ float Config::calculateSpeedFactor() const
defaultTileSize_};
const float fpsFactor{static_cast<float>(getFps()) /
static_cast<float>(defaultFps_)};
return 1.F * tileSizeFactor / fpsFactor;
return tileSizeFactor / fpsFactor;
}
6 changes: 3 additions & 3 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ void Game::control(Map& map, std::list<Tank>& tanks, std::list<Bullet>& bullets)
if (tank.canFire(now))
bullets.emplace_back(tank.fire(now));
const int randomDirection{distribution_(randomGenerator_)};
if ((tank.getX() % Config::getInstance().getTileSize() == 0) &&
(tank.getY() % Config::getInstance().getTileSize() == 0) &&
randomDirection < 4)
if (((tank.getX() % Config::getInstance().getTileSize()) == 0) &&
((tank.getY() % Config::getInstance().getTileSize()) == 0) &&
(randomDirection < 4))
direction = static_cast<Direction>(randomDirection);
else
direction = tank.getDirection();
Expand Down
10 changes: 5 additions & 5 deletions src/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ void Map::shift(Point& pointToShift, Direction direction) const
{
const unsigned int tileSize{Config::getInstance().getTileSize()};
const Point leftUpper{pointToShift};
const Point leftLower{leftUpper.x_, leftUpper.y_ + tileSize - 1};
const Point rightUpper{leftUpper.x_ + tileSize - 1, leftUpper.y_};
const Point rightLower{leftUpper.x_ + tileSize - 1,
leftUpper.y_ + tileSize - 1};
const Point leftLower{leftUpper.x_, (leftUpper.y_ + tileSize) - 1};
const Point rightUpper{(leftUpper.x_ + tileSize) - 1, leftUpper.y_};
const Point rightLower{(leftUpper.x_ + tileSize) - 1,
(leftUpper.y_ + tileSize) - 1};
switch (direction)
{
case Direction::UP:
Expand Down Expand Up @@ -217,7 +217,7 @@ Point Map::tileToScreenPoint(Point point)

void Map::shiftRight(Point& point, unsigned int tileSize)
{
point.x_ = (point.x_ / tileSize + 1) * tileSize;
point.x_ = ((point.x_ / tileSize) + 1) * tileSize;
}

void Map::shiftLeft(Point& point, unsigned int tileSize)
Expand Down

0 comments on commit 6c38ed9

Please sign in to comment.