Skip to content

Commit

Permalink
Some fields renaming to match convention.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Sep 12, 2024
1 parent a895619 commit be5e275
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 75 deletions.
4 changes: 2 additions & 2 deletions src/Bullet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

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.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Config

static unsigned int getRandomSeed();

std::chrono::seconds getFireDelay() const { return fireDelay; }
std::chrono::seconds getFireDelay() const { return fireDelay_; }

enum class FPS : char
{
Expand All @@ -53,5 +53,5 @@ class Config
unsigned int boardHeight_{};
unsigned int statusWidth_{};
float speedFactor_{};
const std::chrono::seconds fireDelay{2};
const std::chrono::seconds fireDelay_{2};
};
4 changes: 2 additions & 2 deletions src/Drawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Drawable::Drawable(Point point) : point_(point) {}

Drawable::~Drawable() = default;

void Drawable::setX(unsigned int x) { point_.x = x; }
void Drawable::setX(unsigned int x) { point_.x_ = x; }

void Drawable::setY(unsigned int y) { point_.y = y; }
void Drawable::setY(unsigned int y) { point_.y_ = y; }

void Drawable::setLocation(Point point) { point_ = point; }

Expand Down
4 changes: 2 additions & 2 deletions src/Drawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class Drawable
void setX(unsigned int x);
void setY(unsigned int y);

unsigned int getX() const { return point_.x; }
unsigned int getY() const { return point_.y; }
unsigned int getX() const { return point_.x_; }
unsigned int getY() const { return point_.y_; }

void setLocation(Point point);
Point getLocation() const;
Expand Down
40 changes: 20 additions & 20 deletions src/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,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 @@ -187,51 +187,51 @@ void Map::tagAreaAsChanged(Point leftUpper, Point rightLower)
const unsigned int tileSize{Config::getInstance().getTileSize()};
Point point{screenPointToTile(leftUpper)};
if (PointUtils::isValidPoint(leftUpper))
changedTiles_[point.x][point.y] = true;
changedTiles_[point.x_][point.y_] = true;

point = screenPointToTile({leftUpper.x, leftUpper.y + tileSize});
if (PointUtils::isValidPoint({leftUpper.x, leftUpper.y + tileSize}))
changedTiles_[point.x][point.y] = true;
point = screenPointToTile({leftUpper.x_, leftUpper.y_ + tileSize});
if (PointUtils::isValidPoint({leftUpper.x_, leftUpper.y_ + tileSize}))
changedTiles_[point.x_][point.y_] = true;

point = screenPointToTile(rightLower);
if (PointUtils::isValidPoint(rightLower))
changedTiles_[point.x][point.y] = true;
changedTiles_[point.x_][point.y_] = true;

point = screenPointToTile({rightLower.x, rightLower.y - tileSize});
if (PointUtils::isValidPoint({rightLower.x, rightLower.y - tileSize}))
changedTiles_[point.x][point.y] = true;
point = screenPointToTile({rightLower.x_, rightLower.y_ - tileSize});
if (PointUtils::isValidPoint({rightLower.x_, rightLower.y_ - tileSize}))
changedTiles_[point.x_][point.y_] = true;
}

Point Map::screenPointToTile(Point location)
{
return {location.x / Config::getInstance().getTileSize(),
location.y / Config::getInstance().getTileSize()};
return {location.x_ / Config::getInstance().getTileSize(),
location.y_ / Config::getInstance().getTileSize()};
}

Point Map::tileToScreenPoint(Point point)
{
return {point.x * Config::getInstance().getTileSize(),
point.y * Config::getInstance().getTileSize()};
return {point.x_ * Config::getInstance().getTileSize(),
point.y_ * Config::getInstance().getTileSize()};
}

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)
{
point.x = (point.x / tileSize) * tileSize;
point.x_ = (point.x_ / tileSize) * tileSize;
}

void Map::shiftUp(Point& point, unsigned int tileSize)
{
point.y = (point.y / tileSize) * tileSize;
point.y_ = (point.y_ / tileSize) * tileSize;
}

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

void Map::drawBackground(const Screen& screen)
Expand Down
4 changes: 2 additions & 2 deletions src/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class Map
private:
const std::unique_ptr<Tile>& getTile(Point point) const
{
return board_[point.y][point.x];
return board_[point.y_][point.x_];
}

std::unique_ptr<Tile>& getTile(Point point)
{
return board_[point.y][point.x];
return board_[point.y_][point.x_];
}

static Point screenPointToTile(Point location);
Expand Down
24 changes: 12 additions & 12 deletions src/MapUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ std::vector<Point> getMovePoints(Point leftUpperCorner, Direction direction,
case Direction::UP:
{
return {
{leftUpperCorner.x + oneThirdOfTank, leftUpperCorner.y},
{leftUpperCorner.x + 2 * oneThirdOfTank, leftUpperCorner.y}};
{leftUpperCorner.x_ + oneThirdOfTank, leftUpperCorner.y_},
{leftUpperCorner.x_ + 2 * oneThirdOfTank, leftUpperCorner.y_}};
}
case Direction::DOWN:
{
return {{leftUpperCorner.x + oneThirdOfTank,
leftUpperCorner.y + tileSize - 1},
{leftUpperCorner.x + 2 * oneThirdOfTank,
leftUpperCorner.y + tileSize - 1}};
return {{leftUpperCorner.x_ + oneThirdOfTank,
leftUpperCorner.y_ + tileSize - 1},
{leftUpperCorner.x_ + 2 * oneThirdOfTank,
leftUpperCorner.y_ + tileSize - 1}};
}
case Direction::LEFT:
{
return {
{leftUpperCorner.x, leftUpperCorner.y + oneThirdOfTank},
{leftUpperCorner.x, leftUpperCorner.y + 2 * oneThirdOfTank}};
{leftUpperCorner.x_, leftUpperCorner.y_ + oneThirdOfTank},
{leftUpperCorner.x_, leftUpperCorner.y_ + 2 * oneThirdOfTank}};
}
case Direction::RIGHT:
{
return {{leftUpperCorner.x + tileSize - 1,
leftUpperCorner.y + oneThirdOfTank},
{leftUpperCorner.x + tileSize - 1,
leftUpperCorner.y + 2 * oneThirdOfTank}};
return {{leftUpperCorner.x_ + tileSize - 1,
leftUpperCorner.y_ + oneThirdOfTank},
{leftUpperCorner.x_ + tileSize - 1,
leftUpperCorner.y_ + 2 * oneThirdOfTank}};
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Point.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

struct Point
{
unsigned int x;
unsigned int y;
unsigned int x_;
unsigned int y_;
};

inline bool operator==(const Point& lhs, const Point& rhs)
{
return lhs.x == rhs.x && lhs.y == rhs.y;
return lhs.x_ == rhs.x_ && lhs.y_ == rhs.y_;
}
2 changes: 1 addition & 1 deletion src/PointUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bool isValidPoint(int x, int y, unsigned int objectSize)
bool isValidPoint(Point point)
{
const unsigned int maxCoordinate{Config::getInstance().getBoardWidth()};
return point.x < maxCoordinate && point.y < maxCoordinate;
return point.x_ < maxCoordinate && point.y_ < maxCoordinate;
}

}; // namespace PointUtils
8 changes: 4 additions & 4 deletions src/Status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ void Status::update(TankStats newStats, const Screen& screen)
void Status::draw(const Screen& screen) const
{
const unsigned int spacer{getHeight() / 5};
screen.drawTextWithBackground(getCenter().x, spacer * 1,
screen.drawTextWithBackground(getCenter().x_, spacer * 1,
"Lives: " + std::to_string(stats_.lives));
screen.drawTextWithBackground(getCenter().x, spacer * 2,
screen.drawTextWithBackground(getCenter().x_, spacer * 2,
"Shield: " + std::to_string(stats_.shield));
screen.drawTextWithBackground(getCenter().x, spacer * 3,
screen.drawTextWithBackground(getCenter().x_, spacer * 3,
"Speed: " + std::to_string(stats_.speed));
screen.drawTextWithBackground(
getCenter().x, spacer * 4,
getCenter().x_, spacer * 4,
"Attack: " + std::to_string(stats_.attackPower));
}

Expand Down
10 changes: 5 additions & 5 deletions src/Tank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "TankType.h"

Tank::Tank(TankType tankType, Point point)
: Drawable(point), initialX_(point.x), initialY_(point.y)
: Drawable(point), initialX_(point.x_), initialY_(point.y_)
{
setType(tankType);
direction_ = (isPlayerControlled() ? Direction::UP : Direction::DOWN);
Expand Down Expand Up @@ -161,14 +161,14 @@ void Tank::applyPowerUp(ResourceType powerUpType)
bool Tank::isWithin(Point point) const
{
const unsigned int tileSize{Config::getInstance().getTileSize()};
return point.x >= getX() && point.x < getX() + tileSize &&
point.y >= getY() && point.y < getY() + tileSize;
return point.x_ >= getX() && point.x_ < getX() + tileSize &&
point.y_ >= getY() && point.y_ < getY() + tileSize;
}

void Tank::move(Point point)
{
setX(point.x);
setY(point.y);
setX(point.x_);
setY(point.y_);
}

void Tank::respawn()
Expand Down
36 changes: 18 additions & 18 deletions test/BulletTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,28 @@ TEST_CASE("Bullet coordinates", "[bullet]")
SECTION("location is correct")
{
const Point currentPoint{bullet.getLocation()};
REQUIRE(currentPoint.x ==
point.x - Config::getInstance().getBulletSize() / 2);
REQUIRE(currentPoint.y ==
point.y - Config::getInstance().getBulletSize() / 2);
REQUIRE(currentPoint.x_ ==
point.x_ - Config::getInstance().getBulletSize() / 2);
REQUIRE(currentPoint.y_ ==
point.y_ - Config::getInstance().getBulletSize() / 2);
}
SECTION("center is correct")
{
const Point currentPoint{bullet.getCenter()};
REQUIRE(currentPoint.x == point.x);
REQUIRE(currentPoint.y == point.y);
REQUIRE(currentPoint.x_ == point.x_);
REQUIRE(currentPoint.y_ == point.y_);
}
SECTION("getX is working")
{
const Point currentPoint{bullet.getLocation()};
const unsigned int currentX{bullet.getX()};
REQUIRE(currentX == currentPoint.x);
REQUIRE(currentX == currentPoint.x_);
}
SECTION("getY is working")
{
const Point currentPoint{bullet.getLocation()};
const unsigned int currentY{bullet.getY()};
REQUIRE(currentY == currentPoint.y);
REQUIRE(currentY == currentPoint.y_);
}

SECTION("setX is working")
Expand Down Expand Up @@ -101,8 +101,8 @@ TEST_CASE("Bullet moving", "[bullet]")
bullet.move();

const Point centerAfterMove{bullet.getCenter()};
REQUIRE(centerBeforeMove.x == centerAfterMove.x);
REQUIRE(centerBeforeMove.y == centerAfterMove.y);
REQUIRE(centerBeforeMove.x_ == centerAfterMove.x_);
REQUIRE(centerBeforeMove.y_ == centerAfterMove.y_);
}
SECTION("bullet moving inside valid area")
{
Expand All @@ -120,8 +120,8 @@ TEST_CASE("Bullet moving", "[bullet]")

bullet.move();

REQUIRE(bullet.getCenter().x == expectedPoint.x);
REQUIRE(bullet.getCenter().y == expectedPoint.y);
REQUIRE(bullet.getCenter().x_ == expectedPoint.x_);
REQUIRE(bullet.getCenter().y_ == expectedPoint.y_);
}
SECTION("location and center not changed after invalid move")
{
Expand All @@ -132,11 +132,11 @@ TEST_CASE("Bullet moving", "[bullet]")
REQUIRE(bullet.move() == false);

const Point centerAfterMove{bullet.getCenter()};
REQUIRE(centerBeforeMove.x == centerAfterMove.x);
REQUIRE(centerBeforeMove.y == centerAfterMove.y);
REQUIRE(centerBeforeMove.x_ == centerAfterMove.x_);
REQUIRE(centerBeforeMove.y_ == centerAfterMove.y_);
const Point locationAfterMove{bullet.getLocation()};
REQUIRE(locationBeforeMove.x == locationAfterMove.x);
REQUIRE(locationBeforeMove.y == locationAfterMove.y);
REQUIRE(locationBeforeMove.x_ == locationAfterMove.x_);
REQUIRE(locationBeforeMove.y_ == locationAfterMove.y_);
}
}

Expand All @@ -147,8 +147,8 @@ TEST_CASE("Bullet moving to invalid area", "[bullet]")
bulletSpeed / 2};
auto [direction, pointGenerated] =
GENERATE_REF(TestData{Direction::UP, point},
TestData{Direction::DOWN, Point{point.x, nearEndOfMap}},
TestData{Direction::RIGHT, Point{nearEndOfMap, point.y}},
TestData{Direction::DOWN, Point{point.x_, nearEndOfMap}},
TestData{Direction::RIGHT, Point{nearEndOfMap, point.y_}},
TestData{Direction::LEFT, point});

Bullet bullet{pointGenerated, bulletSpeed, enemyOrigin, bulletPower,
Expand Down
4 changes: 2 additions & 2 deletions test/TankTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ TEST_CASE("firing", "[tank]")
const unsigned int tileSize{Config::getInstance().getTileSize()};
Tank tank(TankType::PLAYER_TIER_1, point);
const Bullet bullet = tank.fire(TimePoint::max());
const Point expectedBulletCenter{point.x + tileSize / 2,
point.y + tileSize / 2};
const Point expectedBulletCenter{point.x_ + tileSize / 2,
point.y_ + tileSize / 2};
REQUIRE(bullet.getCenter() == expectedBulletCenter);
}

Expand Down

0 comments on commit be5e275

Please sign in to comment.