Skip to content

Commit

Permalink
Remove use of ternary operator.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Oct 11, 2024
1 parent 3fcd5b7 commit 45dac21
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Tank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Tank::Tank(TankType tankType, Point point)
: Drawable(point), initialX_(point.x_), initialY_(point.y_)
{
setType(tankType);
direction_ = (isPlayerControlled() ? Direction::UP : Direction::DOWN);
resetDirection();
}

void Tank::draw(const Display& display) const
Expand Down Expand Up @@ -188,7 +188,7 @@ void Tank::respawn()
setY(initialY_);
if (isPlayerControlled())
setType(TankType::PLAYER_TIER_1);
direction_ = (isPlayerControlled() ? Direction::UP : Direction::DOWN);
resetDirection();
}

void Tank::adjustEnemySpeed(float& speed) const
Expand All @@ -205,3 +205,11 @@ int Tank::getCalculatedSpeed(float speedFactor) const
adjustEnemySpeed(speed);
return std::max(1, static_cast<int>(speed));
}

void Tank::resetDirection()
{
if (isPlayerControlled())
direction_ = Direction::UP;
else
direction_ = Direction::DOWN;
}
2 changes: 2 additions & 0 deletions src/Tank.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class Tank : public Drawable

bool destroy();

void resetDirection();

static const int BASIC_ATTACK{1};
static const int BASIC_HEALTH{1};
static const int BASIC_SPEED{2};
Expand Down

0 comments on commit 45dac21

Please sign in to comment.